List of usage examples for java.util Map equals
boolean equals(Object o);
From source file:org.openflexo.generator.Generator.java
private void updateVelocityMacroIfRequired() throws VelocityException, UnexpectedExceptionOccuredException { try {/*from www.java 2 s . c o m*/ // the next lines ensures that the macro library will be added as a template used by this generator List<CGTemplate> macroTemplates = getProjectGenerator().getVelocityMacroTemplates(); macroTemplates.addAll(getVelocityMacroTemplates()); synchronized (RuntimeSingleton.getRuntimeServices()) { Map<String, Long> newMacroLibMap = new HashMap<String, Long>(); for (CGTemplate template : macroTemplates) { newMacroLibMap.put(template.getRelativePath(), template.getLastUpdate().getTime()); notifyTemplateRequired(template); } if (!newMacroLibMap.equals(macroLibMap)) { FlexoVelocity.addToVelocimacro(getTemplateLocator(), macroTemplates.toArray(new CGTemplate[0])); macroLibMap = newMacroLibMap; } } } catch (ResourceNotFoundException e) { e.printStackTrace(); throw new VelocityException(e, getProjectGenerator()); } catch (ParseErrorException e) { e.printStackTrace(); throw new VelocityException(e, getProjectGenerator()); } catch (Exception e) { e.printStackTrace(); throw new UnexpectedExceptionOccuredException(e, getProjectGenerator()); } }
From source file:org.lockss.test.LockssTestCase.java
/** * Asserts that two Maps are equal (contain the same mappings). * If they are not an AssertionFailedError is thrown. * @param message the message to give on failure * @param expected the expected value// w w w .j ava2 s . c om * @param actual the actual value */ static public void assertEquals(String message, Map expected, Map actual) { if (expected == null && actual == null) { return; } if (expected != null && expected.equals(actual)) { return; } failNotEquals(message, expected, actual); }
From source file:org.apache.poi.hpsf.Section.java
/** * Checks whether this section is equal to another object. The result is * {@code false} if one of the the following conditions holds: * * <ul>/* w w w.j a va 2 s .co m*/ * * <li>The other object is not a {@link Section}. * * <li>The format IDs of the two sections are not equal. * * <li>The sections have a different number of properties. However, * properties with ID 1 (codepage) are not counted. * * <li>The other object is not a {@link Section}. * * <li>The properties have different values. The order of the properties * is irrelevant. * * </ul> * * @param o The object to compare this section with * @return {@code true} if the objects are equal, {@code false} if * not */ @Override public boolean equals(final Object o) { if (!(o instanceof Section)) { return false; } final Section s = (Section) o; if (!s.getFormatID().equals(getFormatID())) { return false; } /* Compare all properties except the dictionary (id 0) and * the codepage (id 1 / ignored) as they must be handled specially. */ Set<Long> propIds = new HashSet<Long>(properties.keySet()); propIds.addAll(s.properties.keySet()); propIds.remove(0L); propIds.remove(1L); for (Long id : propIds) { Property p1 = properties.get(id); Property p2 = s.properties.get(id); if (p1 == null || p2 == null || !p1.equals(p2)) { return false; } } /* If the dictionaries are unequal the sections are unequal. */ Map<Long, String> d1 = getDictionary(); Map<Long, String> d2 = s.getDictionary(); return (d1 == null && d2 == null) || (d1 != null && d2 != null && d1.equals(d2)); }
From source file:org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigComponentImpl.java
/** * Validate the caveat config and optionally update the cache. * * @param nodeRef The nodeRef of the config * @param updateCache Set to <code>true</code> to update the cache *//*from www. j a v a 2 s.c o m*/ @SuppressWarnings("unchecked") protected void validateAndReset(NodeRef nodeRef) { ContentReader cr = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); if (cr != null) { // TODO - check who can change caveat config ! // TODO - locking (or checkout/checkin) String caveatConfigData = cr.getContentString(); if (caveatConfigData != null) { NodeRef existing = getCaveatConfigNode(); if ((existing != null && (!existing.equals(nodeRef)))) { throw new AlfrescoRuntimeException("Cannot create more than one caveat config (existing=" + existing + ", new=" + nodeRef + ")"); } try { if (logger.isTraceEnabled()) { logger.trace(caveatConfigData); } Set<QName> models = new HashSet<QName>(1); Set<QName> props = new HashSet<QName>(10); Set<String> expectedPrefixes = new HashSet<String>(10); if (caveatModelQNames.size() > 0) { models.addAll(caveatModelQNames); } else { models.addAll(dictionaryService.getAllModels()); } if (logger.isTraceEnabled()) { logger.trace("validateAndReset: models to check " + models); } for (QName model : models) { props.addAll(dictionaryService.getProperties(model, DATATYPE_TEXT)); expectedPrefixes.addAll(namespaceService.getPrefixes(model.getNamespaceURI())); } if (props.size() == 0) { logger.warn("validateAndReset: no caveat properties found"); } else { if (logger.isTraceEnabled()) { logger.trace("validateAndReset: properties to check " + props); } } Map<String, Object> caveatConfigMap = JSONtoFmModel.convertJSONObjectToMap(caveatConfigData); for (Map.Entry<String, Object> conEntry : caveatConfigMap.entrySet()) { String conStr = conEntry.getKey(); QName conQName = QName.resolveToQName(namespaceService, conStr); // check prefix String conPrefix = QName.splitPrefixedQName(conStr)[0]; boolean prefixFound = false; for (String expectedPrefix : expectedPrefixes) { if (conPrefix.equals(expectedPrefix)) { prefixFound = true; } } if (!prefixFound) { throw new AlfrescoRuntimeException("Unexpected prefix: " + conPrefix + " (" + conStr + ") expected one of " + expectedPrefixes + ")"); } Map<String, List<String>> caveatMap = (Map<String, List<String>>) conEntry.getValue(); List<String> allowedValues = null; @SuppressWarnings("unused") boolean found = false; for (QName propertyName : props) { PropertyDefinition propDef = dictionaryService.getProperty(propertyName); List<ConstraintDefinition> conDefs = propDef.getConstraints(); for (ConstraintDefinition conDef : conDefs) { final Constraint con = conDef.getConstraint(); if (con instanceof RMListOfValuesConstraint) { String conName = ((RMListOfValuesConstraint) con).getShortName(); if (conName.equals(conStr)) { // note: assumes only one caveat/LOV against a given property allowedValues = AuthenticationUtil.runAs(new RunAsWork<List<String>>() { public List<String> doWork() { return ((RMListOfValuesConstraint) con).getAllowedValues(); } }, AuthenticationUtil.getSystemUserName()); found = true; break; } } } } if (allowedValues != null) { if (logger.isInfoEnabled()) { logger.info("Processing constraint: " + conQName); } for (Map.Entry<String, List<String>> caveatEntry : caveatMap.entrySet()) { String authorityName = caveatEntry.getKey(); List<String> caveatList = caveatEntry.getValue(); // validate authority (user or group) - note: groups are configured with fullname (ie. GROUP_xxx) if ((!authorityService.authorityExists(authorityName) && !personService.personExists(authorityName))) { // TODO - review warnings (& I18N) String msg = "User/group does not exist: " + authorityName + " (constraint=" + conStr + ")"; logger.warn(msg); } // validate caveat list for (String value : caveatList) { if (!allowedValues.contains(value)) { // TODO - review warnings (& add I18N) String msg = "Invalid value in list: " + value + " (authority=" + authorityName + ", constraint=" + conStr + ")"; logger.warn(msg); } } } } } try { writeLock.lock(); // we can't just clear the cache, as all puts to the cache afterwards in this transaction will be ignored // first delete all keys that are now not in the config caveatConfig.getKeys().retainAll(caveatConfigMap.keySet()); for (Map.Entry<String, Object> conEntry : caveatConfigMap.entrySet()) { String conStr = conEntry.getKey(); Map<String, List<String>> caveatMap = (Map<String, List<String>>) conEntry.getValue(); Map<String, List<String>> cacheValue = caveatConfig.get(conStr); if (cacheValue == null || !cacheValue.equals(caveatMap)) { // update the cache caveatConfig.put(conStr, caveatMap); } } } finally { writeLock.unlock(); } } catch (JSONException e) { throw new AlfrescoRuntimeException("Invalid caveat config syntax: " + e); } } } }
From source file:org.kuali.kfs.sys.businessobject.AccountingLineBase.java
/** * @see org.kuali.rice.krad.bo.AccountingLine#isLike(org.kuali.rice.krad.bo.AccountingLine) */// ww w . j av a 2s . co m @Override public boolean isLike(AccountingLine other) { boolean isLike = false; if (other != null) { if (other == this) { isLike = true; } else { Map thisValues = this.getValuesMap(); Map otherValues = other.getValuesMap(); isLike = thisValues.equals(otherValues); if (!isLike && LOG.isDebugEnabled()) { StringBuffer inequalities = new StringBuffer(); boolean first = true; for (Iterator i = thisValues.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); Object thisValue = thisValues.get(key); Object otherValue = otherValues.get(key); if (!org.apache.commons.lang.ObjectUtils.equals(thisValue, otherValue)) { inequalities.append(key + "(" + thisValue + " != " + otherValue + ")"); if (first) { first = false; } else { inequalities.append(","); } } } if (LOG.isDebugEnabled()) { LOG.debug("inequalities: " + inequalities); } } } } return isLike; }
From source file:org.apache.oodt.cas.pge.TestPGETaskInstance.java
@Test public void testDumpMetadataIfRequested() throws Exception { PGETaskInstance pgeTask = createTestInstance(); File dumpMetFile = new File(pgeTask.getDumpMetadataPath()); pgeTask.dumpMetadataIfRequested();//from w w w.j ava 2 s.com assertFalse(dumpMetFile.exists()); pgeTask.pgeMetadata.replaceMetadata(DUMP_METADATA, "true"); pgeTask.dumpMetadataIfRequested(); assertTrue(dumpMetFile.exists()); @SuppressWarnings("unchecked") String expectedMetString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<cas:metadata xmlns:cas=\"http://oodt.jpl.nasa.gov/1.0/cas\">" + "<keyval type=\"vector\">" + "<key>PGETask_Name</key>" + "<val>" + pgeTask.pgeMetadata.getMetadata(NAME) + "</val>" + "</keyval>" + "<keyval type=\"vector\">" + "<key>PGETask_DumpMetadata</key>" + "<val>" + pgeTask.pgeMetadata.getMetadata(DUMP_METADATA) + "</val>" + "</keyval>" + "</cas:metadata>"; Document dumpMetDoc = parseXmlFile(dumpMetFile); Document expectedMetDoc = parseXmlString(expectedMetString); Element dumpMetRoot, expectedMetRoot; dumpMetRoot = dumpMetDoc.getDocumentElement(); expectedMetRoot = expectedMetDoc.getDocumentElement(); NodeList dumpKeyList = dumpMetRoot.getElementsByTagName("key"); NodeList expectedKeyList = expectedMetRoot.getElementsByTagName("key"); NodeList dumpValList = dumpMetRoot.getElementsByTagName("val"); NodeList expectedValList = expectedMetRoot.getElementsByTagName("val"); assertEquals(dumpKeyList.getLength(), expectedKeyList.getLength()); assertEquals(dumpValList.getLength(), expectedValList.getLength()); Map<String, String> dumpKeyValMap = new ConcurrentHashMap<String, String>(); Map<String, String> expectedKeyValMap = new ConcurrentHashMap<String, String>(); for (int i = 0; i < dumpKeyList.getLength(); i++) { Node k1 = dumpKeyList.item(i); Node k2 = expectedKeyList.item(i); Node v1 = dumpValList.item(i); Node v2 = expectedValList.item(i); dumpKeyValMap.put(k1.getFirstChild().getNodeValue(), v1.getFirstChild().getNodeValue()); expectedKeyValMap.put(k2.getFirstChild().getNodeValue(), v2.getFirstChild().getNodeValue()); } assertTrue(dumpKeyValMap.equals(expectedKeyValMap)); }
From source file:org.apache.atlas.utils.LruCacheTest.java
@Test public void testMapOperations() { Map<String, String> reference = new HashMap<>(); reference.put("name", "Fred"); reference.put("occupation", "student"); reference.put("height", "5'11"); reference.put("City", "Littleton"); reference.put("State", "MA"); LruCache<String, String> map = new LruCache<>(10, 10); map.putAll(reference);//from w ww . j av a 2 s. c om assertEquals(map.size(), reference.size()); assertEquals(map.keySet().size(), reference.keySet().size()); assertTrue(map.keySet().containsAll(reference.keySet())); assertTrue(reference.keySet().containsAll(map.keySet())); assertEquals(reference.entrySet().size(), map.entrySet().size()); for (Map.Entry<String, String> entry : map.entrySet()) { assertTrue(reference.containsKey(entry.getKey())); assertEquals(entry.getValue(), reference.get(entry.getKey())); assertTrue(map.containsKey(entry.getKey())); assertTrue(map.containsValue(entry.getValue())); assertTrue(map.values().contains(entry.getValue())); } assertTrue(reference.equals(map)); assertTrue(map.equals(reference)); }
From source file:uk.co.markfrimston.tasktree.TaskTree.java
protected boolean nodesEqual(Node a, Node b) { if ((a == null) != (b == null)) { return false; }//from w w w .j a v a2 s .com if (a != null) { if (a.getNodeType() != b.getNodeType()) { return false; } if ((a.getNodeName() == null) != (b.getNodeName() == null)) { return false; } if (a.getNodeName() != null && !a.getNodeName().equals(b.getNodeName())) { return false; } if ((a.getNodeValue() == null) != (b.getNodeValue() == null)) { return false; } if (a.getNodeValue() != null && !a.getNodeValue().equals(b.getNodeValue())) { return false; } NamedNodeMap attrsA = a.getAttributes(); Map<String, String> attrMapA = new HashMap<String, String>(); if (attrsA != null) { for (int i = 0; i < attrsA.getLength(); i++) { Attr att = (Attr) attrsA.item(i); attrMapA.put(att.getName(), att.getValue()); } } NamedNodeMap attrsB = b.getAttributes(); Map<String, String> attrMapB = new HashMap<String, String>(); if (attrsB != null) { for (int i = 0; i < attrsB.getLength(); i++) { Attr att = (Attr) attrsB.item(i); attrMapB.put(att.getName(), att.getValue()); } } if (!attrMapA.equals(attrMapB)) { return false; } Node childA = a.getFirstChild(); Node childB = b.getFirstChild(); while (childA != null) { if (!nodesEqual(childA, childB)) { return false; } childA = childA.getNextSibling(); childB = childB.getNextSibling(); } if (childB != null) { return false; } } return true; }
From source file:com.spotify.helios.servicescommon.coordination.PersistentPathChildrenCache.java
private void update() throws KeeperException, InterruptedException { log.debug("updating: {}", path); final Map<String, T> newSnapshot; final Map<String, T> currentSnapshot = snapshot.get(); if (!synced) { synced = true;//from www. ja v a 2 s .c o m newSnapshot = sync(); } else { newSnapshot = Maps.newHashMap(currentSnapshot); } // Fetch new data and register watchers for updated children final Iterator<String> iterator = changes.iterator(); while (iterator.hasNext()) { final String child = iterator.next(); iterator.remove(); final String node = ZKPaths.makePath(path, child); log.debug("fetching change: {}", node); final T value; try { final byte[] bytes = curator.getData().usingWatcher(dataWatcher).forPath(node); value = Json.read(bytes, valueType); } catch (KeeperException e) { throw e; } catch (Exception e) { throw Throwables.propagate(e); } newSnapshot.put(node, value); } if (!currentSnapshot.equals(newSnapshot)) { snapshot.setUnchecked(newSnapshot); fireNodesChanged(); } }
From source file:org.pentaho.di.ui.trans.steps.annotation.BaseAnnotationStepDialog.java
private boolean groupChanged(final ModelAnnotationGroup g1, final ModelAnnotationGroup g2) { try {/* w w w . j a v a 2 s .c om*/ if (!EqualsBuilder.reflectionEquals(g1, g2)) { return true; } // check model annotations for (int i = 0; i < g1.size(); i++) { // check fields except for annotation field if (!EqualsBuilder.reflectionEquals(g1.get(i), g2.get(i), new String[] { "annotation" })) { return true; } // manually check annotation properties Map<String, Serializable> g1Properties = g1.get(i).describeAnnotation(); Map<String, Serializable> g2Properties = g2.get(i).describeAnnotation(); if (!EqualsBuilder.reflectionEquals(g1Properties, g2Properties)) { return true; // check mainly if one is null and the other isn't } if (g1Properties != null && g2Properties != null) { if (!g1Properties.equals(g2Properties)) { return true; // deep check } } } return false; // no change } catch (Exception e) { return true; } }