List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:com.datatorrent.lib.io.fs.FileSplitterInputTest.java
static Set<String> createData(String dataDirectory) throws IOException { Set<String> filePaths = Sets.newHashSet(); FileContext.getLocalFSFileContext().delete(new Path(new File(dataDirectory).getAbsolutePath()), true); HashSet<String> allLines = Sets.newHashSet(); for (int file = 0; file < 12; file++) { HashSet<String> lines = Sets.newHashSet(); for (int line = 0; line < 2; line++) { //padding 0 to file number so every file has 6 blocks. lines.add("f" + String.format("%02d", file) + "l" + line); }//from ww w. ja v a 2 s . co m allLines.addAll(lines); File created = new File(dataDirectory, "file" + file + ".txt"); filePaths.add(created.getAbsolutePath()); FileUtils.write(created, StringUtils.join(lines, '\n')); } return filePaths; }
From source file:lv.semti.Thesaurus.struct.ThesaurusEntry.java
/** * Constructing a list of lemmas to ignore - basically meant to ease * development and testing./*from w ww . jav a 2 s. c o m*/ */ private static HashSet<String> initBlacklist() { HashSet<String> blist = new HashSet<String>(); BufferedReader ieeja; try { // Blacklist file format - one word (lemma) per line. ieeja = new BufferedReader(new InputStreamReader(new FileInputStream("blacklist.txt"), "UTF-8")); String rinda; while ((rinda = ieeja.readLine()) != null) { //if (rinda.contains("<s>") || rinda.contains("</s>") || rinda.isEmpty()) // continue; blist.add(rinda.trim()); } ieeja.close(); } catch (Exception e) { System.err.println("Blacklist was not loaded."); } //TODO - any IO issues ignored return blist; }
From source file:com.metamx.milano.proto.MilanoTool.java
/** * Build a MilanoTool from a DescriptorProto, FileDescriptorProto, and a FileDescriptorSet representing * the dependencies./*www . ja va2 s . com*/ * * @param descriptorProto The Descriptor for the message. * @param fileDescriptorProto The FileDescriptorProto containing descriptorProto. * @param dependencies A possible empty FileDescriptorSet containing the dependencies for fileDescriptorProto. * * @return A MilanoTool of the message. */ public static MilanoTool with(final DescriptorProtos.DescriptorProto descriptorProto, final DescriptorProtos.FileDescriptorProto fileDescriptorProto, final DescriptorProtos.FileDescriptorSet dependencies) { HashSet<String> fileSet = new HashSet<String>(); DescriptorProtos.FileDescriptorSet.Builder storedFileSetBuilder = DescriptorProtos.FileDescriptorSet .newBuilder(); if (dependencies != null) { for (DescriptorProtos.FileDescriptorProto fileProto : dependencies.getFileList()) { log.debug(String.format("Found dependency [%s] in package [%s]", fileProto.getName(), fileProto.getPackage())); fileSet.add(fileProto.getName()); if (fileProto.getName().equals("descriptor.proto") && fileProto.getPackage().equals("google.protobuf")) { continue; } storedFileSetBuilder.addFile(fileProto); } } for (String dependency : fileDescriptorProto.getDependencyList()) { log.debug(String.format("Type requires dependency: %s", dependency)); if (!fileSet.contains(dependency) && !dependency.equals("descriptor.proto")) { throw new IllegalStateException( String.format("File requires dependency [%s] that does not exist.", dependency)); } } MilanoTypeMetadata.TypeMetadata.Builder typeMetadataBuilder = MilanoTypeMetadata.TypeMetadata.newBuilder() .setTypeName(descriptorProto.getName()).setTypePackageName(fileDescriptorProto.getPackage()) .setTypeFileDescriptor(fileDescriptorProto); if (storedFileSetBuilder.getFileCount() > 0) { typeMetadataBuilder.setTypeDependencies(storedFileSetBuilder.build()); } return new MilanoTool(typeMetadataBuilder.build()); }
From source file:com.allinfinance.startup.init.MenuInfoUtil.java
/** * ???/*from ww w. j ava2 s. com*/ * * @param degree * @return * 2011-9-16?11:17:18 */ @SuppressWarnings("unchecked") public static HashSet<String> getAuthSet(String degree) { HashSet<String> set = new HashSet<String>(); ICommQueryDAO commQueryDAO = (ICommQueryDAO) ContextUtil.getBean("CommQueryDAO"); String sql = "select VALUE_ID FROM TBL_ROLE_FUNC_MAP ,TBL_ROLE_INF WHERE ROLE_ID = KEY_ID and KEY_ID = " + degree; List<Object> funcMapList = commQueryDAO.findBySQLQuery(sql); Iterator<Object> it = funcMapList.iterator(); while (it.hasNext()) { Object obj = it.next(); if (!StringUtil.isNull(obj)) { set.add(obj.toString()); } } return set; }
From source file:blusunrize.immersiveengineering.client.render.TileRenderAutoWorkbench.java
public static BlueprintLines getBlueprintDrawable(ItemStack stack, World world) { if (stack.isEmpty()) return null; EntityPlayer player = ClientUtils.mc().player; ArrayList<BufferedImage> images = new ArrayList<>(); try {//from w w w . ja v a2s .c o m IBakedModel ibakedmodel = ClientUtils.mc().getRenderItem().getItemModelWithOverrides(stack, world, player); HashSet<String> textures = new HashSet(); Collection<BakedQuad> quads = ibakedmodel.getQuads(null, null, 0); for (BakedQuad quad : quads) if (quad != null && quad.getSprite() != null) textures.add(quad.getSprite().getIconName()); for (String s : textures) { ResourceLocation rl = new ResourceLocation(s); rl = new ResourceLocation(rl.getNamespace(), String.format("%s/%s%s", "textures", rl.getPath(), ".png")); IResource resource = ClientUtils.mc().getResourceManager().getResource(rl); BufferedImage bufferedImage = TextureUtil.readBufferedImage(resource.getInputStream()); if (bufferedImage != null) images.add(bufferedImage); } } catch (Exception e) { } if (images.isEmpty()) return null; ArrayList<Pair<TexturePoint, TexturePoint>> lines = new ArrayList(); HashSet testSet = new HashSet(); HashMultimap<Integer, TexturePoint> area = HashMultimap.create(); int wMax = 0; for (BufferedImage bufferedImage : images) { Set<Pair<TexturePoint, TexturePoint>> temp_lines = new HashSet<>(); int w = bufferedImage.getWidth(); int h = bufferedImage.getHeight(); if (h > w) h = w; if (w > wMax) wMax = w; for (int hh = 0; hh < h; hh++) for (int ww = 0; ww < w; ww++) { int argb = bufferedImage.getRGB(ww, hh); float r = (argb >> 16 & 255) / 255f; float g = (argb >> 8 & 255) / 255f; float b = (argb & 255) / 255f; float intesity = (r + b + g) / 3f; int alpha = (argb >> 24) & 255; if (alpha > 0) { boolean added = false; //Check colour sets for similar colour to shade it later TexturePoint tp = new TexturePoint(ww, hh, w); if (!testSet.contains(tp)) { for (Integer key : area.keySet()) { for (TexturePoint p : area.get(key)) { float mod = w / (float) p.scale; int pColour = bufferedImage.getRGB((int) (p.x * mod), (int) (p.y * mod)); float dR = (r - (pColour >> 16 & 255) / 255f); float dG = (g - (pColour >> 8 & 255) / 255f); float dB = (b - (pColour & 255) / 255f); double delta = Math.sqrt(dR * dR + dG * dG + dB * dB); if (delta < .25) { area.put(key, tp); added = true; break; } } if (added) break; } if (!added) area.put(argb, tp); testSet.add(tp); } //Compare to direct neighbour for (int i = 0; i < 4; i++) { int xx = (i == 0 ? -1 : i == 1 ? 1 : 0); int yy = (i == 2 ? -1 : i == 3 ? 1 : 0); int u = ww + xx; int v = hh + yy; int neighbour = 0; float delta = 1; boolean notTransparent = false; if (u >= 0 && u < w && v >= 0 && v < h) { neighbour = bufferedImage.getRGB(u, v); notTransparent = ((neighbour >> 24) & 255) > 0; if (notTransparent) { float neighbourIntesity = ((neighbour >> 16 & 255) + (neighbour >> 8 & 255) + (neighbour & 255)) / 765f; float intesityDelta = Math.max(0, Math.min(1, Math.abs(intesity - neighbourIntesity))); float rDelta = Math.max(0, Math.min(1, Math.abs(r - (neighbour >> 16 & 255) / 255f))); float gDelta = Math.max(0, Math.min(1, Math.abs(g - (neighbour >> 8 & 255) / 255f))); float bDelta = Math.max(0, Math.min(1, Math.abs(b - (neighbour & 255) / 255f))); delta = Math.max(intesityDelta, Math.max(rDelta, Math.max(gDelta, bDelta))); delta = delta < .25 ? 0 : delta > .4 ? 1 : delta; } } if (delta > 0) { Pair<TexturePoint, TexturePoint> l = Pair.of( new TexturePoint(ww + (i == 0 ? 0 : i == 1 ? 1 : 0), hh + (i == 2 ? 0 : i == 3 ? 1 : 0), w), new TexturePoint(ww + (i == 0 ? 0 : i == 1 ? 1 : 1), hh + (i == 2 ? 0 : i == 3 ? 1 : 1), w)); temp_lines.add(l); } } } } lines.addAll(temp_lines); } ArrayList<Integer> lumiSort = new ArrayList<>(area.keySet()); Collections.sort(lumiSort, (rgb1, rgb2) -> Double.compare(getLuminance(rgb1), getLuminance(rgb2))); HashMultimap<ShadeStyle, Point> complete_areaMap = HashMultimap.create(); int lineNumber = 2; int lineStyle = 0; for (Integer i : lumiSort) { complete_areaMap.putAll(new ShadeStyle(lineNumber, lineStyle), area.get(i)); ++lineStyle; lineStyle %= 3; if (lineStyle == 0) lineNumber += 1; } Set<Pair<Point, Point>> complete_lines = new HashSet<>(); for (Pair<TexturePoint, TexturePoint> line : lines) { TexturePoint p1 = line.getKey(); TexturePoint p2 = line.getValue(); complete_lines.add(Pair.of( new Point((int) (p1.x / (float) p1.scale * wMax), (int) (p1.y / (float) p1.scale * wMax)), new Point((int) (p2.x / (float) p2.scale * wMax), (int) (p2.y / (float) p2.scale * wMax)))); } return new BlueprintLines(wMax, complete_lines, complete_areaMap); }
From source file:net.firstpartners.nounit.utility.XmlUtil.java
/** * gets all elements in the XML Document Being Passed in <BR> * @param inXmlDocument to generated the hashmap from * @return nodeList containing nodes/*w ww.j av a2 s .com*/ */ public static HashSet getAllNodes(Document inXmlDocument) { //Internal Variables int stackPointer = 0; int index = 1; String locationId = null; Element currentElement = null; Element parentElement = null; Element thisElement = null; Attribute tmpAttribute = null; List elementList = null; ListIterator deepestList = null; HashMap mappings = new HashMap(); HashSet nodeList = new HashSet(); List stack = new Vector(); //Implements list interface //Get the list information for the entire document - kick start loop stack.add(inXmlDocument.getContent().listIterator()); //Loop though the elements on list while (!stack.isEmpty()) { //Get the last list on the stack deepestList = (ListIterator) stack.get(stack.size() - 1); //Does this list have more elements? if (deepestList.hasNext()) { //if so Get Next element from this list thisElement = (Element) deepestList.next(); // add this element to the list nodeList.add(thisElement); //does this list have children ? if (thisElement.hasChildren()) { //if so add to the stack stackPointer++; stack.add(thisElement.getChildren().listIterator()); } } else { //if not , remove this list from the stack stack.remove(stackPointer); stackPointer--; } // end if stack has more elements } return nodeList; }
From source file:com.krawler.esp.handlers.basecampHandler.java
public static boolean cheForProject(String projName, String[] projNames) { boolean res = false; java.util.List l = java.util.Arrays.asList(projNames); java.util.HashSet<String> hs = new java.util.HashSet<String>(); hs.addAll(l);/* www .jav a 2 s . c o m*/ res = hs.add(projName); return res; }
From source file:amie.keys.CombinationsExplorationNew.java
private static HashSet<Node> createChildren(GraphNew newGraph, HashSet<Node> parents, Rule conditionRule) { HashSet<Node> allChildren = new HashSet<>(); for (Node parent1 : parents) { for (Node parent2 : parents) { if (parent1 != parent2) { HashSet<Integer> newSet = new HashSet<>(); newSet.addAll(parent1.set); newSet.addAll(parent2.set); HashSet<Integer> newSet2 = new HashSet<>(); newSet2.addAll(newSet);/*from ww w . j a v a2s . c o m*/ newSet2.addAll(newSet); if ((newSet.size() == parent1.set.size() + 1) && (getSupport(newSet2, conditionRule, support))) { Node child = new Node(newSet); HashSet<Node> children1 = newGraph.graph.get(parent1); children1.add(child); newGraph.nodes.put(child, child); newGraph.graph.put(parent1, children1); HashSet<Node> children2 = newGraph.graph.get(parent2); children2.add(child); newGraph.graph.put(parent2, children2); allChildren.add(child); //System.out.println("child:"+child); } } } } // System.out.println("allChildren:" + allChildren); return allChildren; }
From source file:gov.jgi.meta.MetaUtils.java
/** * find all files from a given root./*from ww w .j ava2s. c om*/ * @param p is the root on which to search * @return a set of file paths * @throws IOException if filesystem can't find file or has other io problems */ public static Set<Path> findAllPaths(Path p) throws IOException { Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); HashSet<Path> s = new HashSet<Path>(); if (fs.getFileStatus(p).isDir()) { for (FileStatus f : fs.listStatus(p)) { if (!f.isDir()) { s.add(f.getPath()); } } } else { s.add(p); } return (s); }
From source file:amie.keys.CombinationsExplorationNew.java
public static HashSet<HashSet<Integer>> powerSet(HashSet<Integer> originalSet) { HashSet<HashSet<Integer>> sets = new HashSet<HashSet<Integer>>(); if (originalSet.isEmpty()) { sets.add(new HashSet<Integer>()); return sets; }//w w w . ja v a 2s . com List<Integer> list = new ArrayList<Integer>(originalSet); int head = list.get(0); HashSet<Integer> rest = new HashSet<Integer>(list.subList(1, list.size())); for (HashSet<Integer> set : powerSet(rest)) { HashSet<Integer> newSet = new HashSet<Integer>(); newSet.add(head); newSet.addAll(set); sets.add(newSet); sets.add(set); } return sets; }