List of usage examples for java.util Set equals
boolean equals(Object o);
From source file:hr.fer.zemris.vhdllab.dao.impl.PredefinedFileDaoImplTest.java
@Test public void getPredefinedFiles() { Set<File> files = dao.getPredefinedFiles(); assertNotNull(files);/*from w w w. j a v a 2 s . c om*/ assertEquals(2, files.size()); File file = (File) CollectionUtils.get(files, 0); assertNull(file.getId()); assertNull(file.getVersion()); assertNull(file.getProject()); assertEquals(FileType.PREDEFINED, file.getType()); assertTrue(file.getName().startsWith("PREDEFINED_FILE")); assertNotNull(file.getData()); // Files are defensively copied before return! file.setName("new predefined name"); assertFalse(files.equals(dao.getPredefinedFiles())); }
From source file:de.hybris.platform.test.CaseInsensitiveStringMapTest.java
@Test public void testKeySet() { final Set<String> keys = new HashSet<String>(// Arrays.asList("AAA", "BBB", "CCC", "ddd", "x", "y", "\u00df", "\u00dc", "")); final Set<String> wrongKeys = new HashSet<String>(// Arrays.asList("aaa", "bbb", "ccc", "ddd", "x", "y", "\u00df", "\u00dc", "")); final Map<String, String> testMap = new CaseInsensitiveStringMap<String>(); for (final String key : keys) { testMap.put(key, key);// www .ja v a 2 s . com } final Set<String> keySet = testMap.keySet(); Assert.assertEquals(keys, keySet); Assert.assertFalse(wrongKeys.equals(keySet)); for (final String key : keys) { Assert.assertTrue(keySet.contains(key)); Assert.assertTrue("didn't match '" + key.toLowerCase() + "' within " + keySet, keySet.contains(key.toLowerCase())); if (!"\u00df".equals(key)) // upper case ZS becomes SS which isn't working any way { Assert.assertTrue("didn't match '" + key.toUpperCase() + "' within " + keySet, keySet.contains(key.toUpperCase())); } } }
From source file:dk.netarkivet.harvester.indexserver.distribute.IndexRequestServer.java
/** * Method that handles the processing of an indexRequestMessage. Returns the requested index immediately, if already * available, otherwise proceeds with the index generation of the requested index. Must be run in its own thread, * because it blocks while the index is generated. * * @param irMsg A message requesting an index * @see #visit(IndexRequestMessage)// ww w . java2 s. c o m */ private void doProcessIndexRequestMessage(final IndexRequestMessage irMsg) { final boolean mustReturnIndex = irMsg.mustReturnIndex(); try { checkMessage(irMsg); RequestType type = irMsg.getRequestType(); Set<Long> jobIDs = irMsg.getRequestedJobs(); if (log.isInfoEnabled()) { log.info("Request received for an index of type '{}' for the {} jobs [{}]", type, jobIDs.size(), StringUtils.conjoin(",", jobIDs)); } FileBasedCache<Set<Long>> handler = handlers.get(type); // Here we need to make sure that we don't accidentally process more than // one message at the time before the whole process is over List<Long> sortedList = new ArrayList<Long>(jobIDs); String allIDsString = StringUtils.conjoin("-", sortedList); String checksum = ChecksumCalculator.calculateMd5(allIDsString.getBytes()); log.debug( "Waiting to enter the synchronization zone for the indexing job of size {} with checksum '{}'", jobIDs.size(), checksum); // Begin synchronization synchronized (checksum.intern()) { log.debug("The indexing job of size {} with checksum '{}' is now in the synchronization zone", jobIDs.size(), checksum); Set<Long> foundIDs = handler.cache(jobIDs); irMsg.setFoundJobs(foundIDs); if (foundIDs.equals(jobIDs)) { if (log.isInfoEnabled()) { log.info("Retrieved successfully index of type '{}' for the {} jobs [{}]", type, jobIDs.size(), StringUtils.conjoin(",", jobIDs)); } File cacheFile = handler.getCacheFile(jobIDs); if (mustReturnIndex) { // return index now! packageResultFiles(irMsg, cacheFile); } } else if (satisfactoryTresholdReached(foundIDs, jobIDs)) { log.info( "Data for full index w/ {} jobs not available. Only found data for {} jobs - " + "but satisfactoryTreshold reached, so assuming presence of all data", jobIDs.size(), foundIDs.size()); // Make sure that the index of the data available is generated Set<Long> theFoundIDs = handler.cache(foundIDs); // TheFoundIDS should be identical to foundIDs // Lets make sure of that Set<Long> diffSet = new HashSet<Long>(foundIDs); diffSet.removeAll(theFoundIDs); // Make a copy of the index available, and give it the name of // the index cache file wanted. File cacheFileWanted = handler.getCacheFile(jobIDs); File cacheFileCreated = handler.getCacheFile(foundIDs); log.info("Satisfactory threshold reached - copying index {} '{}' to full index: {}", (cacheFileCreated.isDirectory() ? "dir" : "file"), cacheFileCreated.getAbsolutePath(), cacheFileWanted.getAbsolutePath()); if (cacheFileCreated.isDirectory()) { // create destination cacheFileWanted, and // copy all files in cacheFileCreated to cacheFileWanted. cacheFileWanted.mkdirs(); FileUtils.copyDirectory(cacheFileCreated, cacheFileWanted); } else { FileUtils.copyFile(cacheFileCreated, cacheFileWanted); } // TODO This delete-operation commented out, because it is deemed too dangerous, // as the cachedir represented by cacheFileCreated may still be used // log.info("Deleting the temporary index " // + cacheFileCreated.getAbsolutePath()); // FileUtils.removeRecursively(cacheFileCreated); log.info("We keep the index '{}', as we don't know if anybody is using it", cacheFileCreated.getAbsolutePath()); // Information needed by recipient to store index in local cache irMsg.setFoundJobs(jobIDs); if (mustReturnIndex) { // return index now. packageResultFiles(irMsg, cacheFileWanted); } } else { Set<Long> missingJobIds = new HashSet<Long>(jobIDs); missingJobIds.removeAll(foundIDs); log.warn("Failed generating index of type '{}' for the jobs [{}]. Missing data for jobs [{}].", type, StringUtils.conjoin(",", jobIDs), StringUtils.conjoin(",", missingJobIds)); } } // End of synchronization block } catch (Throwable t) { log.warn("Unable to generate index for jobs [" + StringUtils.conjoin(",", irMsg.getRequestedJobs()) + "]", t); irMsg.setNotOk(t); } finally { // Remove job from currentJobs Set synchronized (currentJobs) { currentJobs.remove(irMsg.getID()); } // delete stored message deleteStoredMessage(irMsg); String state = "failed"; if (irMsg.isOk()) { state = "successful"; } if (mustReturnIndex) { log.info("Sending {} reply for IndexRequestMessage back to sender '{}'.", state, irMsg.getReplyTo()); JMSConnectionFactory.getInstance().reply(irMsg); } else { log.info("Sending {} IndexReadyMessage to Scheduler for harvest {}", state, irMsg.getHarvestId()); boolean isindexready = true; if (state.equalsIgnoreCase("failed")) { isindexready = false; } IndexReadyMessage irm = new IndexReadyMessage(irMsg.getHarvestId(), isindexready, irMsg.getReplyTo(), Channels.getTheIndexServer()); JMSConnectionFactory.getInstance().send(irm); } } }
From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobConfigurationService.java
/** * Interface method implementation. After setting an XML File, also saves the previous file. * @see org.trpr.platform.batch.spi.spring.admin.JobConfigurationService#setJobconfig(String, byte[]) */// www .java 2s .co m @Override public void setJobConfig(List<String> jobNames, Resource jobConfigFile) throws PlatformException { if (this.jobXMLFile.isEmpty()) this.scanXMLFiles(); String destPath = null; //Check if jobName has been changed try { //Using sets to comapare whether the two list of jobNames are equal Set<String> jobNamesUserSet = new HashSet<String>(); Set<String> jobNamesFileSet = new HashSet<String>(); jobNamesUserSet.addAll(jobNames); jobNamesFileSet.addAll(ConfigFileUtils.getJobName(jobConfigFile)); if (!jobNamesUserSet.equals(jobNamesFileSet)) { throw new PlatformException("The Job Name cannot be changed. Expecting: " + jobNamesUserSet.toString() + " Got: " + jobNamesFileSet.toString()); } //Take first jobName to check whether it is a new Job String jobName = jobNames.get(0); //Code for overwriting file to location if (this.getJobConfigURI(jobName) == null) { //NEW JOB destPath = this.getJobStoreURI(jobName).getPath() + SimpleJobConfigurationService.SPRING_BATCH_FILE; } else { //Already deployed job. Store the previous file destPath = this.getJobConfigURI(jobName).getPath(); this.createPrevConfigFile(jobName); } this.upload(ConfigFileUtils.getContents(jobConfigFile).getBytes(), destPath); for (String allJobName : jobNames) { this.jobXMLFile.put(allJobName, new File(destPath).toURI()); } LOGGER.info("Uploaded job config to " + destPath); } catch (IOException ioe) { LOGGER.error("Error creating job configuration file for : " + jobNames.toString() + " in location : " + destPath); throw new PlatformException("Error creating job configuration file for : " + jobNames.toString() + " in location : " + destPath, ioe); } }
From source file:fr.mby.portal.coreimpl.acl.MemoryAclDaoTest.java
@Test public void testGrantRoles() throws Exception { final Principal testPrincipal = new PortalUserPrincipal("test"); this.memoryAclDao.registerPrincipal(testPrincipal); final IRole role1 = this.basicRoleFactory.initializeRole(MemoryAclDaoTest.TEST_ROLE_NAME_1, null, null); this.memoryAclDao.createRole(role1); final Set<IRole> refreshedRoles = this.memoryAclDao.grantRoles(testPrincipal, AclHelper.buileRoleSet(role1)); final Set<IRole> roles = this.memoryAclDao.findPrincipalRoles(testPrincipal); Assert.assertNotNull("Roles set should not be null after registration !", roles); Assert.assertTrue("Roles set size should be 1 after granting the role !", roles.size() == 1); Assert.assertEquals("Role found should be the one we granted !", role1, roles.iterator().next()); Assert.assertTrue("Roles sets found and return by grant method shoud be equals !", roles.equals(refreshedRoles)); }
From source file:org.opentestsystem.delivery.testreg.service.impl.TestRegUserDetailsServiceImpl.java
private Set<String> findAllChildrenMongoIds(final String parentMongoId, final Map<String, Set<String>> uberMap) { Set<String> childrenAlreadyLookedUp = new HashSet<>(); Set<String> allChildrenMongoIds = new HashSet<>(); allChildrenMongoIds.add(parentMongoId); while (!childrenAlreadyLookedUp.equals(allChildrenMongoIds)) { Set<String> newChildrenMongoIds = new HashSet<>(); for (String child : allChildrenMongoIds) { if (!childrenAlreadyLookedUp.contains(child)) { childrenAlreadyLookedUp.add(child); newChildrenMongoIds.addAll(findChildren(child, uberMap)); }/*ww w. jav a2 s . c om*/ } allChildrenMongoIds.addAll(newChildrenMongoIds); } return allChildrenMongoIds; }
From source file:org.ow2.proactive.scheduler.common.job.factories.JobComparator.java
/** * Compares the element in the 2 lists in the exact order they appear in the * lists/*w ww . j ava2 s . c om*/ */ private boolean isEqualInputFiles(List<InputSelector> l1, List<InputSelector> l2) { if ((l1 == null) && (l2 == null)) return true; if ((l1 == null) ^ (l2 == null)) { stack.push("One of 2 values is null"); return false; } if (l1.size() != l2.size()) { stack.push("sizes don't match"); return false; } for (InputSelector is1 : l1) { boolean found = false; for (int i = 0; i < l2.size(); i++) { InputSelector is2 = l2.get(i); if (!is1.getMode().equals(is2.getMode())) { continue; } Set<String> i1 = is1.getInputFiles().getIncludes(); Set<String> i2 = is2.getInputFiles().getIncludes(); if (!i1.equals(i2)) { continue; } Set<String> e1 = is1.getInputFiles().getExcludes(); Set<String> e2 = is2.getInputFiles().getExcludes(); if (!e1.equals(e2)) { continue; } found = true; break; } if (!found) { return false; } } return true; }
From source file:org.ow2.proactive.scheduler.common.job.factories.JobComparator.java
/** * Compares the element in the 2 lists in the exact order they appear in the * lists FIXME: bad object design in the data space layer provides us to * unify the similar code in this method and isEqualInputFiles *//*from w w w . j a va 2s .com*/ private boolean isEqualOutputFiles(List<OutputSelector> l1, List<OutputSelector> l2) { if ((l1 == null) && (l2 == null)) return true; if ((l1 == null) ^ (l2 == null)) { stack.push("One of 2 values is null"); return false; } if (l1.size() != l2.size()) return false; for (OutputSelector os1 : l1) { boolean found = false; for (int i = 0; i < l2.size(); i++) { OutputSelector os2 = l2.get(i); if (!os1.getMode().equals(os2.getMode())) { continue; } Set<String> i1 = os1.getOutputFiles().getIncludes(); Set<String> i2 = os2.getOutputFiles().getIncludes(); if (!i1.equals(i2)) { continue; } Set<String> e1 = os1.getOutputFiles().getExcludes(); Set<String> e2 = os2.getOutputFiles().getExcludes(); if (!e1.equals(e2)) { continue; } found = true; break; } if (!found) { return false; } } return true; }
From source file:org.geoserver.gwc.layer.CatalogLayerEventListener.java
/** * Handles changes of interest to GWC on a {@link LayerInfo}. * <ul>/*from w w w.j a v a 2s .c o m*/ * <li>If the name of the default style changed, then the layer's cache for the default style is * truncated. This method doesn't check if the contents of the styles are equal. That is handled * by {@link CatalogStyleChangeListener} whenever a style is modified. * <li>If the tile layer is {@link GeoServerTileLayerInfo#isAutoCacheStyles() auto caching * styles} and the layerinfo's "styles" list changed, the tile layer's STYLE parameter filter is * updated to match the actual list of layer styles and any removed style is truncated. * </ul> * * @param changedProperties * @param oldValues * @param newValues * @param li * @param tileLayerInfo */ private void handleLayerInfoChange(final List<String> changedProperties, final List<Object> oldValues, final List<Object> newValues, final LayerInfo li, final GeoServerTileLayerInfo tileLayerInfo) { checkNotNull(tileLayerInfo); final String layerName = tileLayerName(li); boolean save = false; boolean defaultStyleChanged = false; final String defaultStyle; /* * If default style name changed */ if (changedProperties.contains("defaultStyle")) { final int propIndex = changedProperties.indexOf("defaultStyle"); final StyleInfo oldStyle = (StyleInfo) oldValues.get(propIndex); final StyleInfo newStyle = (StyleInfo) newValues.get(propIndex); final String oldStyleName = oldStyle.getName(); defaultStyle = newStyle.getName(); if (!Objects.equal(oldStyleName, defaultStyle)) { save = true; defaultStyleChanged = true; log.info("Truncating default style for layer " + layerName + ", as it changed from " + oldStyleName + " to " + defaultStyle); mediator.truncateByLayerAndStyle(layerName, oldStyleName); } } else { StyleInfo styleInfo = li.getDefaultStyle(); defaultStyle = styleInfo == null ? null : styleInfo.getName(); } if (tileLayerInfo.isAutoCacheStyles()) { Set<String> styles = new HashSet<String>(); for (StyleInfo s : li.getStyles()) { styles.add(s.getName()); } ImmutableSet<String> cachedStyles = tileLayerInfo.cachedStyles(); if (!styles.equals(cachedStyles)) { // truncate no longer existing cached styles Set<String> notCachedAnyMore = Sets.difference(cachedStyles, styles); for (String oldCachedStyle : notCachedAnyMore) { log.info("Truncating cached style " + oldCachedStyle + " of layer " + layerName + " as it's no longer one of the layer's styles"); mediator.truncateByLayerAndStyle(layerName, oldCachedStyle); } // reset STYLES parameter filter final boolean createParamIfNotExists = true; TileLayerInfoUtil.updateStringParameterFilter(tileLayerInfo, "STYLES", createParamIfNotExists, defaultStyle, styles); save = true; } } // check the caching settings, have they changed? boolean cachingInfoChanged = false; int metadataIdx = changedProperties.indexOf("metadata"); if (metadataIdx >= 0) { MetadataMap oldMetadata = (MetadataMap) oldValues.get(metadataIdx); MetadataMap newMetadata = (MetadataMap) newValues.get(metadataIdx); boolean cachingEnabledChanged = LangUtils.equals( oldMetadata.get(ResourceInfo.CACHING_ENABLED, Boolean.class), newMetadata.get(ResourceInfo.CACHING_ENABLED, Boolean.class)); boolean cachingMaxAgeChanged = LangUtils.equals( oldMetadata.get(ResourceInfo.CACHE_AGE_MAX, Boolean.class), newMetadata.get(ResourceInfo.CACHE_AGE_MAX, Boolean.class)); // we do we don't need to truncate the layer, but we need to update // its LayerInfo so that the resulting caching headers get updated if (cachingEnabledChanged || cachingMaxAgeChanged) { cachingInfoChanged = true; save = true; } } if (save) { GridSetBroker gridSetBroker = mediator.getGridSetBroker(); GeoServerTileLayer tileLayer = new GeoServerTileLayer(li, gridSetBroker, tileLayerInfo); mediator.save(tileLayer); } // caching info and default style changes affect also the layer groups containing the layer if (cachingInfoChanged || defaultStyleChanged) { List<LayerGroupInfo> groups = catalog.getLayerGroups(); for (LayerGroupInfo lg : groups) { GeoServerTileLayer tileLayer = mediator.getTileLayer(lg); if (tileLayer != null) { LayerGroupHelper helper = new LayerGroupHelper(lg); int idx = helper.allLayers().indexOf(li); if (idx >= 0) { // we need to save in case something changed in one of the layer GridSetBroker gridSetBroker = mediator.getGridSetBroker(); GeoServerTileLayerInfo groupTileLayerInfo = tileLayer.getInfo(); GeoServerTileLayer newTileLayer = new GeoServerTileLayer(lg, gridSetBroker, groupTileLayerInfo); mediator.save(newTileLayer); // we also need to truncate the group if the layer default style changed, // and the layer group was using if (defaultStyleChanged && lg.getStyles().get(idx) == null) { mediator.truncate(groupTileLayerInfo.getName()); } } } } } }
From source file:org.artifactory.model.xstream.fs.PropertiesImpl.java
@Override public MatchResult matchQuery(Properties queryProperties) { if (queryProperties == null) { return MatchResult.NO_MATCH; }// w w w. ja v a 2 s. c om for (String qPropKey : queryProperties.keySet()) { //Hack - need to model query properties together with their control flags boolean mandatory = false; String propKey = qPropKey; if (qPropKey != null && qPropKey.endsWith(MANDATORY_SUFFIX)) { mandatory = true; propKey = qPropKey.substring(0, qPropKey.length() - MANDATORY_SUFFIX.length()); } //If the key given from the query must exist if (mandatory) { //If the current properties contain the given key if (containsKey(propKey)) { Set<String> queryPropertyValues = clearBlankAndReturnPropertyValues( queryProperties.get(qPropKey)); //Only check the current property values if the request property was given with values if (!queryPropertyValues.isEmpty()) { //The given query properties have a value, so we should try to match Set<String> currentPropertyValue = clearBlankAndReturnPropertyValues(get(propKey)); if (!queryPropertyValues.equals(currentPropertyValue)) { //The properties don't match return MatchResult.CONFLICT; } } } else { //Conflict since the key given from the properties is mandatory and doesn't exist in the current properties return MatchResult.CONFLICT; } } else { Set<String> queryPropertyValues = clearBlankAndReturnPropertyValues(queryProperties.get(qPropKey)); if (!queryPropertyValues.isEmpty()) { //If the current properties contain the given query property key if (containsKey(propKey)) { //The given query properties have a value, so we should try to match Set<String> currentPropertyValue = clearBlankAndReturnPropertyValues(get(propKey)); if (!queryPropertyValues.equals(currentPropertyValue)) { //The properties conflict return MatchResult.CONFLICT; } } else { //The current property doesn't have the given query property, so it does not conflict either return MatchResult.NO_MATCH; } } } } return MatchResult.MATCH; }