List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:net.sourceforge.safr.sample.permission.service.PermissionServiceImpl.java
/** * Returns sample user permissions.//from w ww .j a v a2s.c o m * * @return sample user permissions. */ public Map<UserPrincipal, Set<InstancePermission>> getUserPermissions() { HashMap<UserPrincipal, Set<InstancePermission>> result = new HashMap<UserPrincipal, Set<InstancePermission>>(); // define permissions for root HashSet<InstancePermission> permissions = new HashSet<InstancePermission>(); permissions.add(new InstancePermission(new Target(), Action.AUTH)); result.put(new UserPrincipal("root"), permissions); // define permissions for user1 permissions = new HashSet<InstancePermission>(); permissions.add(new InstancePermission(new Target("user1", NOTEBOOK, WILDCARD), Action.AUTH)); result.put(new UserPrincipal("user1"), permissions); // define permissions for user2 permissions = new HashSet<InstancePermission>(); permissions.add(new InstancePermission(new Target("user2", NOTEBOOK, WILDCARD), Action.AUTH)); result.put(new UserPrincipal("user2"), permissions); // define permissions for user3 permissions = new HashSet<InstancePermission>(); permissions.add(new InstancePermission(new Target("user3", NOTEBOOK, WILDCARD), Action.AUTH)); result.put(new UserPrincipal("user3"), permissions); return result; }
From source file:au.org.ala.bhl.WordLists.java
private static HashSet<String> loadWordList(String resourcePath) { HashSet<String> set = new HashSet<String>(); InputStream is = TaxonGrab.class.getResourceAsStream(resourcePath); try {//from ww w . j av a 2 s . c o m @SuppressWarnings("unchecked") List<String> lines = IOUtils.readLines(is); for (String line : lines) { StringBuilder word = new StringBuilder(); StringBuilder wordAlt = new StringBuilder(); for (int i = 0; i < line.length(); ++i) { char ch = line.charAt(i); char chAlt = substitute(ch); if (Character.isLetter(chAlt)) { wordAlt.append(chAlt); if (chAlt > 127) { System.err.println(String.format("Non ascii letter: %s", ch)); } } if (Character.isLetter(ch)) { word.append(ch); } } set.add(word.toString().toLowerCase()); if (!wordAlt.toString().equals(word.toString())) { set.add(wordAlt.toString()); } } } catch (IOException e) { e.printStackTrace(); } return set; }
From source file:com.datatorrent.lib.io.fs.AbstractFileInputOperatorFailureHandlingTest.java
@Test public void testFailureHandling() throws Exception { FileContext.getLocalFSFileContext().delete(new Path(new File(testMeta.getDir()).getAbsolutePath()), true); HashSet<String> allLines = Sets.newHashSet(); // Create files with 100 records. for (int file = 0; file < 10; file++) { HashSet<String> lines = Sets.newHashSet(); for (int line = 0; line < 10; line++) { lines.add("f" + file + "l" + line); }/* w w w. j av a 2 s .c o m*/ allLines.addAll(lines); FileUtils.write(new File(testMeta.getDir(), "file" + file), StringUtils.join(lines, '\n')); } Thread.sleep(10); TestFileInputOperator oper = new TestFileInputOperator(); CollectorTestSink<String> queryResults = new CollectorTestSink<String>(); @SuppressWarnings({ "unchecked", "rawtypes" }) CollectorTestSink<Object> sink = (CollectorTestSink) queryResults; oper.output.setSink(sink); oper.setDirectory(testMeta.getDir()); oper.getScanner().setFilePatternRegexp(".*file[\\d]"); oper.setup(new OperatorContextTestHelper.TestIdOperatorContext(1, new Attribute.AttributeMap.DefaultAttributeMap())); for (long wid = 0; wid < 1000; wid++) { oper.beginWindow(wid); oper.emitTuples(); oper.endWindow(); } oper.teardown(); Assert.assertEquals("number tuples", 100, queryResults.collectedTuples.size()); Assert.assertEquals("lines", allLines, new HashSet<String>(queryResults.collectedTuples)); TestUtils.deleteTargetTestClassFolder(testMeta.desc); }
From source file:fi.jumi.actors.maven.GenerateEventStubsMojo.java
private void compileClass(String classToCompile, File targetDir) throws MojoExecutionException { HashSet<String> includes = new HashSet<String>(); includes.add(classToCompile.replace('.', '/') + ".java"); CompilerConfiguration config = new CompilerConfiguration(); if (sourceDirectory.isDirectory()) { config.addSourceLocation(sourceDirectory.getAbsolutePath()); }// www . j ava 2s. c o m config.setIncludes(includes); config.setOutputLocation(targetDir.getAbsolutePath()); config.setSourceEncoding(encoding); config.setSourceVersion(source); config.setTargetVersion(target); config.setClasspathEntries(Arrays.asList(projectClasspath)); try { JavacCompiler javac = new JavacCompiler(); getLog().debug("Compiling event interface using: " + Arrays.toString(javac.createCommandLine(config))); List<CompilerError> messages = javac.compile(config); checkForCompilerErrors(messages, classToCompile); } catch (CompilerException e) { throw new MojoExecutionException("Cannot compile event interface: " + classToCompile, e); } }
From source file:com.thoughtworks.go.plugin.access.configrepo.contract.CRParameter.java
public String validateNameUniqueness(HashSet<String> keys) { if (keys.contains(this.getName())) return String.format("Param name '%s' is not unique.", this.getName()); else/*from w w w . jav a 2 s . c o m*/ keys.add(this.getName()); return null; }
From source file:edu.umn.msi.tropix.proteomics.conversion.impl.MzXMLToDTAConverterStreamingImplTest.java
private void testStructure(final MzXMLToDTAOptions options) throws Exception { final MzXMLToDTAConverterStreamingImpl converter = new MzXMLToDTAConverterStreamingImpl(); DTAList dtaList;//from www . j ava 2 s.com InputStream mzxmlStream; mzxmlStream = ProteomicsTests.getResourceAsStream("validMzXML.mzxml"); try { dtaList = converter.mzxmlToDTA(mzxmlStream, options); VerifyUtils.verifyDTAList(dtaList); } finally { IO_UTILS.closeQuietly(mzxmlStream); } mzxmlStream = ProteomicsTests.getResourceAsStream("validMzXML.mzxml"); try { dtaList = converter.mzxmlToDTA(mzxmlStream, options); final HashSet<String> originalNames = new HashSet<String>(); originalNames.addAll(Arrays.asList(new String[] { "mrr.103.106.1.dta", "mrr.1105.1106.2.dta", "mrr.1105.1106.3.dta", "mrr.2025.2026.2.dta", "mrr.2025.2026.3.dta", "mrr.3009.3011.1.dta" })); final HashSet<String> mzxmlNames = new HashSet<String>(); for (final DTAList.Entry entry : dtaList) { mzxmlNames.add(entry.getName()); } assert mzxmlNames.equals(originalNames); } finally { IO_UTILS.closeQuietly(mzxmlStream); } }
From source file:de.kaiserpfalzEdv.office.contacts.location.CityBuilder.java
protected HashSet<PostCodeDO> convertPostCodesToPostCodeDTOs() { HashSet<PostCodeDO> result = new HashSet<>(postCodes.size()); postCodes.parallelStream().forEach(c -> result.add(new PostCodeDO(c))); return result; }
From source file:de.kaiserpfalzEdv.office.contacts.location.CityBuilder.java
protected HashSet<AreaCodeDO> convertAreaCodesToAreaCodeDTOs() { HashSet<AreaCodeDO> result = new HashSet<>(areaCodes.size()); areaCodes.parallelStream().forEach(c -> result.add(new AreaCodeDO(c))); return result; }
From source file:com.github.maven_nar.NarUtil.java
static Set findInstallNameToolCandidates(final File[] files, final Log log) throws MojoExecutionException, MojoFailureException { final HashSet candidates = new HashSet(); for (final File file2 : files) { final File file = file2; if (!file.exists()) { continue; }//w ww. ja v a 2 s.c o m if (file.isDirectory()) { candidates.addAll(findInstallNameToolCandidates(file.listFiles(), log)); } final String fileName = file.getName(); if (file.isFile() && file.canWrite() && (fileName.endsWith(".so") || fileName.endsWith(".dylib") || fileName.endsWith(".jnilib"))) { candidates.add(file); } } return candidates; }
From source file:com.tk.httpClientErp.inspectorfinalck.InspectorfinalckList.java
/** * json/* w w w . jav a 2 s . com*/ * * @return */ private List<HashMap<String, Object>> classification(List<HashMap<String, Object>> jsontoList) { boolean initCompare = true; // true HashMap<String, Object> compareContainer = null; // List<HashMap<String, Object>> fenzuList = new ArrayList<HashMap<String, Object>>(); // if (jsontoList.size() == 0) return fenzuList; // HashSet<String> gd_no = new HashSet<String>(); for (HashMap<String, Object> bean : jsontoList) { gd_no.add(bean.get("gd_no").toString()); } // in_time for (String gdstr : gd_no) { compareContainer = new HashMap<String, Object>(); for (HashMap<String, Object> bean : jsontoList) { if (gdstr.equals(bean.get("gd_no").toString()) && initCompare) { compareContainer = bean; initCompare = false; } else if (gdstr.equals(bean.get("gd_no").toString())) { compareContainer = bean; } } fenzuList.add(compareContainer); initCompare = true; } return fenzuList; }