List of usage examples for java.util HashSet contains
public boolean contains(Object o)
From source file:com.oneis.javascript.Runtime.java
/** * Initialize the shared JavaScript environment. Loads libraries and removes * methods of escaping the sandbox.//from w ww . java2 s . c om */ public static void initializeSharedEnvironment(String frameworkRoot) throws java.io.IOException { // Don't allow this to be called twice if (sharedScope != null) { return; } long startTime = System.currentTimeMillis(); final Context cx = Runtime.enterContext(); try { final ScriptableObject scope = cx.initStandardObjects(null, false /* don't seal the standard objects yet */); if (!scope.has("JSON", scope)) { throw new RuntimeException( "Expecting built-in JSON support in Rhino, check version is at least 1.7R3"); } if (standardTemplateLoader == null) { throw new RuntimeException("StandardTemplateLoader for Runtime hasn't been set."); } String standardTemplateJSON = standardTemplateLoader.standardTemplateJSON(); scope.put("$STANDARDTEMPLATES", scope, standardTemplateJSON); // Load the library code FileReader bootScriptsFile = new FileReader(frameworkRoot + "/lib/javascript/bootscripts.txt"); LineNumberReader bootScripts = new LineNumberReader(bootScriptsFile); String scriptFilename = null; while ((scriptFilename = bootScripts.readLine()) != null) { FileReader script = new FileReader(frameworkRoot + "/" + scriptFilename); cx.evaluateReader(scope, script, scriptFilename, 1, null /* no security domain */); script.close(); } bootScriptsFile.close(); // Load the list of allowed globals FileReader globalsWhitelistFile = new FileReader( frameworkRoot + "/lib/javascript/globalswhitelist.txt"); HashSet<String> globalsWhitelist = new HashSet<String>(); LineNumberReader whitelist = new LineNumberReader(globalsWhitelistFile); String globalName = null; while ((globalName = whitelist.readLine()) != null) { String g = globalName.trim(); if (g.length() > 0) { globalsWhitelist.add(g); } } globalsWhitelistFile.close(); // Remove all the globals which aren't allowed, using a whitelist for (Object propertyName : scope.getAllIds()) // the form which includes the DONTENUM hidden properties { if (propertyName instanceof String) // ConsString is checked { // Delete any property which isn't in the whitelist if (!(globalsWhitelist.contains(propertyName))) { scope.delete((String) propertyName); // ConsString is checked } } else { // Not expecting any other type of property name in the global namespace throw new RuntimeException( "Not expecting global JavaScript scope to contain a property which isn't a String"); } } // Run through the globals again, just to check nothing escaped for (Object propertyName : scope.getAllIds()) { if (!(globalsWhitelist.contains(propertyName))) { throw new RuntimeException("JavaScript global was not destroyed: " + propertyName.toString()); } } // Run through the whilelist, and make sure that everything in it exists for (String propertyName : globalsWhitelist) { if (!scope.has(propertyName, scope)) { // The whitelist should only contain non-host objects created by the JavaScript source files. throw new RuntimeException( "JavaScript global specified in whitelist does not exist: " + propertyName); } } // And make sure java has gone, to check yet again that everything expected has been removed if (scope.get("java", scope) != Scriptable.NOT_FOUND) { throw new RuntimeException("JavaScript global 'java' escaped destruction"); } // Seal the scope and everything within in, so nothing else can be added and nothing can be changed // Asking initStandardObjects() to seal the standard library doesn't actually work, as it will leave some bits // unsealed so that decodeURI.prototype.pants = 43; works, and can pass information between runtimes. // This recursive object sealer does actually work. It can't seal the main host object class, so that's // added to the scope next, with the (working) seal option set to true. HashSet<Object> sealedObjects = new HashSet<Object>(); recursiveSealObjects(scope, scope, sealedObjects, false /* don't seal the root object yet */); if (sealedObjects.size() == 0) { throw new RuntimeException("Didn't seal any JavaScript globals"); } // Add the host object classes. The sealed option works perfectly, so no need to use a special seal function. defineSealedHostClass(scope, KONEISHost.class); defineSealedHostClass(scope, KObjRef.class); defineSealedHostClass(scope, KScriptable.class); defineSealedHostClass(scope, KLabelList.class); defineSealedHostClass(scope, KLabelChanges.class); defineSealedHostClass(scope, KLabelStatements.class); defineSealedHostClass(scope, KDateTime.class); defineSealedHostClass(scope, KObject.class); defineSealedHostClass(scope, KText.class); defineSealedHostClass(scope, KQueryClause.class); defineSealedHostClass(scope, KQueryResults.class); defineSealedHostClass(scope, KPluginAppGlobalStore.class); defineSealedHostClass(scope, KPluginResponse.class); defineSealedHostClass(scope, KTemplatePartialAutoLoader.class); defineSealedHostClass(scope, KAuditEntry.class); defineSealedHostClass(scope, KAuditEntryQuery.class); defineSealedHostClass(scope, KUser.class); defineSealedHostClass(scope, KUserData.class); defineSealedHostClass(scope, KWorkUnit.class); defineSealedHostClass(scope, KWorkUnitQuery.class); defineSealedHostClass(scope, KEmailTemplate.class); defineSealedHostClass(scope, KBinaryData.class); defineSealedHostClass(scope, KUploadedFile.class); defineSealedHostClass(scope, KStoredFile.class); defineSealedHostClass(scope, KJob.class); defineSealedHostClass(scope, KSessionStore.class); defineSealedHostClass(scope, KSecurityRandom.class); defineSealedHostClass(scope, KSecurityBCrypt.class); defineSealedHostClass(scope, KSecurityDigest.class); defineSealedHostClass(scope, KSecurityHMAC.class); defineSealedHostClass(scope, JdNamespace.class); defineSealedHostClass(scope, JdTable.class); defineSealedHostClass(scope, JdSelectClause.class); defineSealedHostClass(scope, JdSelect.class, true /* map inheritance */); defineSealedHostClass(scope, KGenerateTable.class); defineSealedHostClass(scope, KGenerateXLS.class, true /* map inheritance */); defineSealedHostClass(scope, KRefKeyDictionary.class); defineSealedHostClass(scope, KRefKeyDictionaryHierarchical.class, true /* map inheritance */); defineSealedHostClass(scope, KCheckingLookupObject.class); defineSealedHostClass(scope, KCollaborationService.class); defineSealedHostClass(scope, KCollaborationFolder.class); defineSealedHostClass(scope, KCollaborationItemList.class); defineSealedHostClass(scope, KCollaborationItem.class); defineSealedHostClass(scope, KAuthenticationService.class); // Seal the root now everything has been added scope.sealObject(); // Check JavaScript TimeZone checkJavaScriptTimeZoneIsGMT(); sharedScope = scope; } finally { cx.exit(); } initializeSharedEnvironmentTimeTaken = System.currentTimeMillis() - startTime; }
From source file:www.image.ImageManager.java
public void cleanup(HashSet<String> keepers) { String[] files = mContext.fileList(); HashSet<String> hashedUrls = new HashSet<String>(); for (String imageUrl : keepers) { hashedUrls.add(getMd5(imageUrl)); }//from w w w . ja v a 2s . c om for (String file : files) { if (!hashedUrls.contains(file)) { mContext.deleteFile(file); } } }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.ManageLabelsForIndividualGenerator.java
private List<String> getExistingSortedLanguageNamesList() { HashSet<String> existingLanguages = new HashSet<String>(); for (Literal l : this.existingLabelLiterals) { String language = l.getLanguage(); if (!existingLanguages.contains(language)) { existingLanguages.add(language); }/*from w ww.j av a 2 s . c o m*/ } List<String> sortedNames = new ArrayList<String>(existingLanguages); //sort alphabetically Collections.sort(sortedNames); return sortedNames; }
From source file:com.projity.exchange.ResourceMappingForm.java
public void setMergeField(MergeField mergeField) { this.mergeField = mergeField; Map mergeFieldMap = new HashMap(); HashSet notMergedValues = new HashSet(); Object resource;//from w ww.j a va2 s. co m if (mergeField != NO_MERGE) for (Iterator i = resources.iterator(); i.hasNext();) { resource = i.next(); try { Object value = PropertyUtils.getProperty(resource, mergeField.getProjityName()); if (notMergedValues.contains(value)) continue; if (mergeFieldMap.containsKey(value)) { //not duplicates mergeFieldMap.remove(value); notMergedValues.add(value); } else mergeFieldMap.put(value, resource); } catch (Exception e) { e.printStackTrace(); } } selectedResources.clear(); Object value; for (Iterator i = importedResources.iterator(); i.hasNext();) { resource = i.next(); if (mergeField == NO_MERGE) selectedResources.add(unassignedResource); else { try { value = PropertyUtils.getProperty(resource, mergeField.getImportName()); if (value == null || !mergeFieldMap.containsKey(value)) selectedResources.add(unassignedResource); else selectedResources.add(mergeFieldMap.get(value)); } catch (Exception e) { selectedResources.add(unassignedResource); } } } }
From source file:com.game.ui.views.CharacterEditor.java
/** * This method integrates with GameUtils.cal4d6Roll() to generate all unique values for different * set of modifiers//from w w w . j a va 2s . com * @param set * @return */ public int getUniqueVal(HashSet<Integer> set) { int temp = GameUtils.cal4d6Roll(); while (set.contains(temp)) { temp = GameUtils.cal4d6Roll(); } set.add(temp); return temp; }
From source file:gov.nih.nci.cabig.caaers.web.ae.ReporterTab.java
@Override public Map<String, Object> referenceData(HttpServletRequest request, ExpeditedAdverseEventInputCommand command) { Map<String, Object> refData = super.referenceData(request, command); Set<SiteResearchStaff> researchStaffSet = new HashSet<SiteResearchStaff>(); Set<SiteInvestigator> investigatorSet = new HashSet<SiteInvestigator>(); HashSet<ResearchStaff> temporaryRsSet = new HashSet<ResearchStaff>(); for (SiteResearchStaff srs : command.getAssignment().getStudySite().getOrganization() .getSiteResearchStaffs()) {//from w w w . j a va2 s .c o m ResearchStaff rs = srs.getResearchStaff(); if (!temporaryRsSet.contains(rs)) { if (rs.isUser()) { try { User user = userRepository.getUserByLoginName(rs.getCaaersUser().getLoginName()); if (user.hasRole(UserGroupType.ae_reporter)) researchStaffSet.add(srs); } catch (CaaersSystemException ignore) { //just continue the loop.. } } } temporaryRsSet.add(rs); } for (StudyInvestigator sInvestigator : command.getAssignment().getStudySite() .getActiveStudyInvestigators()) { investigatorSet.add(sInvestigator.getSiteInvestigator()); } List<SiteResearchStaff> researchStaffList = new ArrayList<SiteResearchStaff>(researchStaffSet); List<SiteInvestigator> investigatorList = new ArrayList<SiteInvestigator>(investigatorSet); //Sort the researchStaff and investigators list Collections.sort(researchStaffList); Collections.sort(investigatorList); refData.put("researchStaffList", researchStaffList); refData.put("investigatorList", investigatorList); //set the reporter, as the login person String loginId = SecurityUtils.getUserLoginName(); Person loggedInPerson = null; if (loginId != null) { loggedInPerson = personRepository.getByLoginId(loginId); refData.put("validPersonnel", loggedInPerson != null); refData.put("loggedInPersonId", loggedInPerson != null ? loggedInPerson.getId() : 0); } Person reporter = command.getAeReport().getReporter().getPerson(); Person physician = command.getAeReport().getPhysician().getPerson(); int reporterPersonId = (reporter != null) ? reporter.getId() : (loggedInPerson != null ? loggedInPerson.getId() : 0); refData.put("reporterPersonId", reporterPersonId); refData.put("reporterIsResearchStaff", reporter != null && reporter instanceof ResearchStaff); refData.put("reporterIsInvestigator", reporter != null && reporter instanceof Investigator); int physicianPersonId = (physician != null) ? physician.getId() : 0; refData.put("physicianPersonId", physicianPersonId); refData.put("physicianAPerson", physician != null); refData.put("editFlow", command.getAeReport().getId() != null); return refData; }
From source file:cross.io.misc.WorkflowZipper.java
private void addRelativeZipEntry(final int bufsize, final ZipOutputStream zos, final byte[] input_buffer, final String relativePath, final File file, final HashSet<String> zipEntries) throws IOException { log.debug("Adding zip entry for file {}", file); if (file.exists() && file.isFile()) { // Use the file name for the ZipEntry name. final ZipEntry zip_entry = new ZipEntry(relativePath); if (zipEntries.contains(relativePath)) { log.info("Skipping duplicate zip entry {}", relativePath + "/" + file.getName()); return; } else {//ww w. java2 s . co m zipEntries.add(relativePath); } zos.putNextEntry(zip_entry); // Create a buffered input stream from the file stream. final FileInputStream in = new FileInputStream(file); // Read from source into buffer and write, thereby compressing // on the fly try (BufferedInputStream source = new BufferedInputStream(in, bufsize)) { // Read from source into buffer and write, thereby compressing // on the fly int len = 0; while ((len = source.read(input_buffer, 0, bufsize)) != -1) { zos.write(input_buffer, 0, len); } zos.flush(); } zos.closeEntry(); } else { log.warn("Skipping nonexistant file or directory {}", file); } }
From source file:at.stefanproell.ResultSetVerification.ResultSetVerificationAPI.java
private MessageDigest initCryptoModule(String algorithm) { HashSet<String> algorithms = new HashSet<String>(); algorithms.add("SHA-1"); algorithms.add("MD5"); algorithms.add("SHA-256"); if (algorithms.contains(algorithm)) { this.crypto = null; try {//from ww w . ja v a 2s .c om this.crypto = MessageDigest.getInstance(algorithm); this.crypto.reset(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } return this.crypto; }
From source file:cross.io.misc.WorkflowZipper.java
private void addZipEntry(final int bufsize, final ZipOutputStream zos, final byte[] input_buffer, final File file, final HashSet<String> zipEntries) throws IOException { log.debug("Adding zip entry for file {}", file); if (file.exists() && file.isFile()) { // Use the file name for the ZipEntry name. final ZipEntry zip_entry = new ZipEntry(file.getName()); if (zipEntries.contains(file.getName())) { log.info("Skipping duplicate zip entry {}", file.getName()); return; } else {/* w w w .j av a 2 s . c o m*/ zipEntries.add(file.getName()); } zos.putNextEntry(zip_entry); // Create a buffered input stream from the file stream. final FileInputStream in = new FileInputStream(file); // Read from source into buffer and write, thereby compressing // on the fly try (BufferedInputStream source = new BufferedInputStream(in, bufsize)) { // Read from source into buffer and write, thereby compressing // on the fly int len = 0; while ((len = source.read(input_buffer, 0, bufsize)) != -1) { zos.write(input_buffer, 0, len); } zos.flush(); } zos.closeEntry(); } else { log.warn("Skipping nonexistant file or directory {}", file); } }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.ManageLabelsForIndividualGenerator.java
public List<String> getFullLanguagesNamesSortedList(List<Map<String, Object>> localesList) { HashSet<String> languageNamesSet = new HashSet<String>(); for (Map<String, Object> locale : localesList) { String label = (String) locale.get("label"); if (!languageNamesSet.contains(label)) { languageNamesSet.add(label); }/*ww w . jav a2 s . c o m*/ } List<String> languageNames = new ArrayList<String>(languageNamesSet); Collections.sort(languageNames); return languageNames; }