List of usage examples for com.google.common.collect LinkedListMultimap create
public static <K, V> LinkedListMultimap<K, V> create()
From source file:mods.railcraft.common.util.crafting.DyeHelper.java
public static Multimap<EnumColor, ItemStack> getDyes() { if (dyes == null) { dyes = LinkedListMultimap.create(); for (EnumColor color : EnumColor.VALUES) { dyes.putAll(color, OreDictionary.getOres(EnumColor.DYES[color.ordinal()])); }/*from w ww .ja va 2 s. com*/ } return dyes; }
From source file:org.calrissian.mango.uri.support.UriUtils.java
public static Multimap<String, String> splitQuery(String query) throws UnsupportedEncodingException { Multimap<String, String> query_pairs = LinkedListMultimap.create(); String[] pairs = query.split("&"); for (String pair : pairs) { int idx = pair.indexOf("="); query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); }//from www. j a va 2 s . c o m return query_pairs; }
From source file:eu.tomylobo.routes.util.Ini.java
public static Multimap<String, Multimap<String, String>> load(String fileName) { final LinkedListMultimap<String, Multimap<String, String>> sections = LinkedListMultimap.create(); try {/*from w w w. ja va2 s .com*/ final BufferedReader stream = new BufferedReader(new FileReader(fileName)); String line; while ((line = stream.readLine()) != null) { if (line.trim().isEmpty()) continue; final Matcher matcher = sectionStartPattern.matcher(line); if (!matcher.matches()) { System.err.println("Malformed line in " + fileName + "."); continue; } final String sectionName = matcher.group(1); final Multimap<String, String> section = loadSection(stream); sections.put(sectionName, section); } stream.close(); } catch (IOException e) { //e.printStackTrace(); return null; } return sections; }
From source file:com.github.jasonruckman.sidney.ext.guava.MultimapSerializer.java
public static void registerMaps(AbstractSid sid) { sid.addSerializer(Multimap.class, MultimapSerializer.class); sid.addInstanceFactory(ArrayListMultimap.class, new InstanceFactory<ArrayListMultimap>() { @Override/*from w w w . jav a 2 s . c om*/ public ArrayListMultimap newInstance() { return ArrayListMultimap.create(); } }); sid.addInstanceFactory(LinkedListMultimap.class, new InstanceFactory<LinkedListMultimap>() { @Override public LinkedListMultimap newInstance() { return LinkedListMultimap.create(); } }); sid.addInstanceFactory(LinkedHashMultimap.class, new InstanceFactory<LinkedHashMultimap>() { @Override public LinkedHashMultimap newInstance() { return LinkedHashMultimap.create(); } }); sid.addInstanceFactory(TreeMultimap.class, new InstanceFactory<TreeMultimap>() { @Override public TreeMultimap newInstance() { return TreeMultimap.create(); } }); sid.addInstanceFactory(HashMultimap.class, new InstanceFactory<HashMultimap>() { @Override public HashMultimap newInstance() { return HashMultimap.create(); } }); }
From source file:org.opentripplanner.internals.AnalysisUtils.java
/** * Get polygons covering the components of the graph. The largest component (in terms of number * of nodes) will not overlap any other components (it will have holes); the others may overlap * each other./*w ww. ja va2 s .c o m*/ * * @param dateTime */ public static List<Geometry> getComponentPolygons(Graph graph, RoutingRequest options, long time) { DisjointSet<Vertex> components = getConnectedComponents(graph); LinkedListMultimap<Integer, Coordinate> componentCoordinates = LinkedListMultimap.create(); options.setDummyRoutingContext(graph); for (Vertex v : graph.getVertices()) { for (Edge e : v.getOutgoing()) { State s0 = new State(v, time, options); State s1 = e.traverse(s0); if (s1 != null) { Integer component = components.find(e.getFromVertex()); Geometry geometry = s1.getBackEdge().getGeometry(); if (geometry != null) { List<Coordinate> coordinates = new ArrayList<Coordinate>( Arrays.asList(geometry.getCoordinates())); for (int i = 0; i < coordinates.size(); ++i) { Coordinate coordinate = new Coordinate(coordinates.get(i)); coordinate.x = Math.round(coordinate.x * PRECISION) / PRECISION; coordinate.y = Math.round(coordinate.y * PRECISION) / PRECISION; coordinates.set(i, coordinate); } componentCoordinates.putAll(component, coordinates); } } } } // generate convex hull of each component List<Geometry> geoms = new ArrayList<Geometry>(); int mainComponentSize = 0; int mainComponentIndex = -1; int component = 0; for (Integer key : componentCoordinates.keySet()) { List<Coordinate> coords = componentCoordinates.get(key); Coordinate[] coordArray = new Coordinate[coords.size()]; ConvexHull hull = new ConvexHull(coords.toArray(coordArray), GeometryUtils.getGeometryFactory()); Geometry geom = hull.getConvexHull(); // buffer components which are mere lines so that they do not disappear. if (geom instanceof LineString) { geom = geom.buffer(0.01); // ~10 meters } else if (geom instanceof Point) { geom = geom.buffer(0.05); // ~50 meters, so that it shows up } geoms.add(geom); if (mainComponentSize < coordArray.length) { mainComponentIndex = component; mainComponentSize = coordArray.length; } ++component; } // subtract small components out of main component // (small components are permitted to overlap each other) Geometry mainComponent = geoms.get(mainComponentIndex); for (int i = 0; i < geoms.size(); ++i) { Geometry geom = geoms.get(i); if (i == mainComponentIndex) { continue; } mainComponent = mainComponent.difference(geom); } geoms.set(mainComponentIndex, mainComponent); return geoms; }
From source file:com.giaybac.traprange.MAIN.java
private static void extractTables(String[] args) { try {/*from www . ja va2s. c om*/ List<Integer> pages = getPages(args); List<Integer> exceptPages = getExceptPages(args); List<Integer[]> exceptLines = getExceptLines(args); String in = getIn(args); String out = getOut(args); PDFTableExtractor extractor = (new PDFTableExtractor()).setSource(in); //page for (Integer page : pages) { extractor.addPage(page); } //except page for (Integer exceptPage : exceptPages) { extractor.exceptPage(exceptPage); } //except lines List<Integer> exceptLineIdxs = new ArrayList<>(); Multimap<Integer, Integer> exceptLineInPages = LinkedListMultimap.create(); for (Integer[] exceptLine : exceptLines) { if (exceptLine.length == 1) { exceptLineIdxs.add(exceptLine[0]); } else if (exceptLine.length == 2) { int lineIdx = exceptLine[0]; int pageIdx = exceptLine[1]; exceptLineInPages.put(pageIdx, lineIdx); } } if (!exceptLineIdxs.isEmpty()) { extractor.exceptLine(Ints.toArray(exceptLineIdxs)); } if (!exceptLineInPages.isEmpty()) { for (int pageIdx : exceptLineInPages.keySet()) { extractor.exceptLine(pageIdx, Ints.toArray(exceptLineInPages.get(pageIdx))); } } //begin parsing pdf file List<Table> tables = extractor.extract(); Writer writer = new OutputStreamWriter(new FileOutputStream(out), "UTF-8"); try { for (Table table : tables) { writer.write("Page: " + (table.getPageIdx() + 1) + "\n"); writer.write(table.toHtml()); } } finally { try { writer.close(); } catch (Exception e) { } } } catch (Exception e) { logger.error(null, e); } }
From source file:org.apache.eagle.common.module.ModuleRegistryImpl.java
public ModuleRegistryImpl() { moduleRepo = LinkedListMultimap.create(); }
From source file:uapi.service.ServiceInterfaceMeta.java
public ServiceInterfaceMeta(final String interfaceId, final Class<?> interfaceType, final List<ServiceMeta> svcMetas) { ArgumentChecker.required(interfaceId, "interfaceId"); ArgumentChecker.required(interfaceType, "interfaceType"); ArgumentChecker.required(svcMetas, "svcMetas"); this._intfId = interfaceId; this._intfType = interfaceType; this._svcMetas = LinkedListMultimap.create(); Observable.from(svcMetas).subscribe(svcMeta -> this._svcMetas.put(svcMeta.getName(), svcMeta)); }
From source file:de.iteratec.visualizationmodel.layout.Bounds.java
/** * Helper method for partitioning a list of planar map symbols into lists of symbols of a given size * /*from ww w .jav a2s . c o m*/ * @param symbols the planar map symbols to partition * * @return a map from possible sizes to lists of symbols of that size */ public static final ListMultimap<Bounds, ASymbol> deriveSymmetryBrokenProblem(Collection<ASymbol> symbols) { ListMultimap<Bounds, ASymbol> result = LinkedListMultimap.create(); for (ASymbol symbol : symbols) { result.put(new Bounds(symbol), symbol); } return result; }
From source file:org.jclouds.chef.predicates.CookbookVersionPredicates.java
/** * Note that the default recipe of a cookbook is its name. Otherwise, you * prefix the recipe with the name of the cookbook. ex. {@code apache2} will * be the default recipe where {@code apache2::mod_proxy} is a specific one * in the cookbook./*from w w w . ja va2s. co m*/ * * @param recipes * names of the recipes. * @return true if the cookbook version contains a recipe in the list. */ public static Predicate<CookbookVersion> containsRecipes(String... recipes) { checkNotNull(recipes, "recipes must be defined"); final Multimap<String, String> search = LinkedListMultimap.create(); for (String recipe : recipes) { if (recipe.indexOf("::") != -1) { Iterable<String> nameRecipe = Splitter.on("::").split(recipe); search.put(get(nameRecipe, 0), get(nameRecipe, 1) + ".rb"); } else { search.put(recipe, "default.rb"); } } return new Predicate<CookbookVersion>() { @Override public boolean apply(final CookbookVersion cookbookVersion) { return search.containsKey(cookbookVersion.getCookbookName()) && any(search.get(cookbookVersion.getCookbookName()), new Predicate<String>() { @Override public boolean apply(final String recipeName) { return any(cookbookVersion.getRecipes(), new Predicate<Resource>() { @Override public boolean apply(Resource resource) { return resource.getName().equals(recipeName); } }); } }); } @Override public String toString() { return "containsRecipes(" + search + ")"; } }; }