Java Code Examples for java.util.Map.equals()

The following are Jave code examples for showing how to use equals() of the java.util.Map class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: rapidminer   File: PlotConfiguration.java   View Source Code Vote up 6 votes
/**
 * @param colorScheme
 *            the colorScheme to set
 */
public void setColorSchemes(Map<String, ColorScheme> colorSchemes, String activeColorSchemeName) {
	boolean changed = false;

	ColorScheme oldActiveScheme = getActiveColorScheme();
	if (!colorSchemes.equals(this.colorSchemes)) {
		this.colorSchemes = colorSchemes;
		changed = true;
	}

	if (!oldActiveScheme.equals(colorSchemes.get(activeColorSchemeName))) {
		setActiveScheme(activeColorSchemeName);
		changed = true;
	}
	if (changed) {
		firePlotConfigurationChanged(new PlotConfigurationChangeEvent(this, getActiveColorScheme()));
	}
}
 
Example 2
Project: apollo-custom   File: ReleaseService.java   View Source Code Vote up 6 votes
private void mergeFromMasterAndPublishBranch(Namespace parentNamespace, Namespace childNamespace,
                                             Map<String, String> parentNamespaceItems,
                                             String releaseName, String releaseComment,
                                             String operator, Release masterPreviousRelease,
                                             Release parentRelease, boolean isEmergencyPublish) {
  //create release for child namespace
  Map<String, String> childReleaseConfiguration = getNamespaceReleaseConfiguration(childNamespace);
  Map<String, String> parentNamespaceOldConfiguration = masterPreviousRelease == null ?
                                                        null : gson.fromJson(masterPreviousRelease.getConfigurations(),
                                                                      GsonType.CONFIG);

  Map<String, String> childNamespaceToPublishConfigs =
      calculateChildNamespaceToPublishConfiguration(parentNamespaceOldConfiguration,
                                                    parentNamespaceItems,
                                                    childNamespace);
  //compare
  if (!childNamespaceToPublishConfigs.equals(childReleaseConfiguration)) {
    branchRelease(parentNamespace, childNamespace, releaseName, releaseComment,
                  childNamespaceToPublishConfigs, parentRelease.getId(), operator,
                  ReleaseOperation.MASTER_NORMAL_RELEASE_MERGE_TO_GRAY, isEmergencyPublish);
  }

}
 
Example 3
Project: openjdk-jdk10   File: EqualsTest.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    boolean test;

    /* synchronizedList test */
    List list = Collections.synchronizedList(new ArrayList());
    list.add(list);
    test = list.equals(list);
    assertTrue(test);
    list.remove(list);

    /* synchronizedSet test */
    Set s = Collections.synchronizedSet(new HashSet());
    s.add(s);
    test = s.equals(s);
    assertTrue(test);

    /* synchronizedMap test */
    Map m =  Collections.synchronizedMap(new HashMap());
    test = m.equals(m);
    assertTrue(test);

}
 
Example 4
Project: drift   File: TestThriftMethodMetadata.java   View Source Code Vote up 6 votes
@SafeVarargs
private static void assertExceptions(String methodName, Class<? extends Exception>... expectedExceptions)
{
    ThriftMethodMetadata metadata = new ThriftMethodMetadata(getMethod(methodName), new ThriftCatalog());
    Map<Short, Type> actualIdMap = new TreeMap<>();
    Map<Short, Type> expectedIdMap = new TreeMap<>();

    for (Map.Entry<Short, ThriftType> entry : metadata.getExceptions().entrySet()) {
        actualIdMap.put(entry.getKey(), entry.getValue().getJavaType());
    }

    short expectedId = 1;
    for (Class<? extends Exception> expectedException : expectedExceptions) {
        expectedIdMap.put(expectedId, expectedException);
        expectedId++;
    }

    // string comparison produces more useful failure message (and is safe, given the types)
    if (!actualIdMap.equals(expectedIdMap)) {
        assertEquals(actualIdMap.toString(), expectedIdMap.toString());
    }
}
 
Example 5
Project: Leanplum-Android-SDK   File: Leanplum.java   View Source Code Vote up 6 votes
/**
 * Applies the variables, messages, or update rules in a start or getVars response.
 *
 * @param response The response containing content.
 * @param alwaysApply Always apply the content regardless of whether the content changed.
 */
private static void applyContentInResponse(JSONObject response, boolean alwaysApply) {
  Map<String, Object> values = JsonConverter.mapFromJsonOrDefault(
      response.optJSONObject(Constants.Keys.VARS));
  Map<String, Object> messages = JsonConverter.mapFromJsonOrDefault(
      response.optJSONObject(Constants.Keys.MESSAGES));
  List<Map<String, Object>> updateRules = JsonConverter.listFromJsonOrDefault(
      response.optJSONArray(Constants.Keys.UPDATE_RULES));
  List<Map<String, Object>> eventRules = JsonConverter.listFromJsonOrDefault(
      response.optJSONArray(Constants.Keys.EVENT_RULES));
  Map<String, Object> regions = JsonConverter.mapFromJsonOrDefault(
      response.optJSONObject(Constants.Keys.REGIONS));
  List<Map<String, Object>> variants = JsonConverter.listFromJsonOrDefault(
      response.optJSONArray(Constants.Keys.VARIANTS));

  if (alwaysApply
      || !values.equals(VarCache.getDiffs())
      || !messages.equals(VarCache.getMessageDiffs())
      || !updateRules.equals(VarCache.getUpdateRuleDiffs())
      || !eventRules.equals(VarCache.getEventRuleDiffs())
      || !regions.equals(VarCache.regions())) {
    VarCache.applyVariableDiffs(values, messages, updateRules,
        eventRules, regions, variants);
  }
}
 
Example 6
Project: WordnetLoom   File: ConfigurationManager.java   View Source Code Vote up 6 votes
public void saveConfiguration() {
    // próba odczytania configu
    Map<String, String> old = loadConfigFromFile(configFileName);
    // jeżeli się nie zmienił to nie robimy zmian
    if (old != null && !old.isEmpty() && old.equals(this.config)) {
        return;
    }

    try (FileOutputStream fo = new FileOutputStream(configFileName)) {
        PrintStream out = new PrintStream(fo);
        Set<Map.Entry<String, String>> set = this.config.entrySet();
        set.stream().map((element) -> {
            out.print(element.getKey());
            return element;
        }).forEach((element) -> {
            out.print("=");
            out.println(element.getValue());
        });
    } catch (IOException ex) {
        Logger.getLogger(ConfigurationManager.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 7
Project: swaggy-jenkins   File: PatchRequest.java   View Source Code Vote up 5 votes
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
  Map<String, String> headers = super.getHeaders();
  if (headers == null || headers.equals(Collections.emptyMap())) {
    headers = new HashMap<String, String>();
  }
  if (apiHeaders != null && !apiHeaders.equals(Collections.emptyMap())) {
    headers.putAll(apiHeaders);
  }
  if(contentType != null) {
    headers.put("Content-Type", contentType);
  }

  return headers;
}
 
Example 8
Project: payments-Android-SDK   File: GetRequest.java   View Source Code Vote up 5 votes
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
  Map<String, String> headers = super.getHeaders();
  if (headers == null || headers.equals(Collections.emptyMap())) {
    headers = new HashMap<String, String>();
  }
  if (apiHeaders != null && !apiHeaders.equals(Collections.emptyMap())) {
    headers.putAll(apiHeaders);
  }
  if(contentType != null) {
    headers.put("Content-Type", contentType);
  }

  return headers;
}
 
Example 9
Project: DAFramework   File: MapUtil.java   View Source Code Vote up 5 votes
public static boolean compare(Map<?, ?> map1, Map<?, ?> map2) {
	boolean result = true;
	if (map1 == map2) {
		return true;
	}
	if (map1.equals(map2)) {
		return true;
	}
	if (map1.size() != map2.size()) {
		return false;
	}
	//TODO compare(Map map1, Map map2)
	result = false;
	return result;
}
 
Example 10
Project: hands-on-neo4j-devoxx-fr-2017   File: ResultOperations.java   View Source Code Vote up 5 votes
private static ResultRowDifference rowDifference(Map<String, Object> actualRow,
                                                 Map<String, Object> expectedRow) {

    if (actualRow.equals(expectedRow)) {
        return ResultRowDifference.empty();
    }

    return computeDifference(actualRow, expectedRow);
}
 
Example 11
Project: swaggy-jenkins   File: DeleteRequest.java   View Source Code Vote up 5 votes
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
  Map<String, String> headers = super.getHeaders();
  if (headers == null || headers.equals(Collections.emptyMap())) {
    headers = new HashMap<String, String>();
  }
  if (apiHeaders != null && !apiHeaders.equals(Collections.emptyMap())) {
    headers.putAll(apiHeaders);
  }
  if(contentType != null) {
    headers.put("Content-Type", contentType);
  }

  return headers;
}
 
Example 12
Project: swaggy-jenkins   File: PostRequest.java   View Source Code Vote up 5 votes
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
  Map<String, String> headers = super.getHeaders();
  if (headers == null || headers.equals(Collections.emptyMap())) {
      headers = new HashMap<String, String>();
  }
  if (apiHeaders != null && !apiHeaders.equals(Collections.emptyMap())) {
      headers.putAll(apiHeaders);
  }
  if(contentType != null) {
      headers.put("Content-Type", contentType);
  }

  return headers;
}
 
Example 13
Project: elasticsearch_my   File: GatewayMetaState.java   View Source Code Vote up 5 votes
/**
 * Elasticsearch 2.0 removed several deprecated features and as well as support for Lucene 3.x. This method calls
 * {@link MetaDataIndexUpgradeService} to makes sure that indices are compatible with the current version. The
 * MetaDataIndexUpgradeService might also update obsolete settings if needed.
 * Allows upgrading global custom meta data via {@link MetaDataUpgrader#customMetaDataUpgraders}
 *
 * @return input <code>metaData</code> if no upgrade is needed or an upgraded metaData
 */
static MetaData upgradeMetaData(MetaData metaData,
                                MetaDataIndexUpgradeService metaDataIndexUpgradeService,
                                MetaDataUpgrader metaDataUpgrader) throws Exception {
    // upgrade index meta data
    boolean changed = false;
    final MetaData.Builder upgradedMetaData = MetaData.builder(metaData);
    for (IndexMetaData indexMetaData : metaData) {
        IndexMetaData newMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData,
            Version.CURRENT.minimumIndexCompatibilityVersion());
        changed |= indexMetaData != newMetaData;
        upgradedMetaData.put(newMetaData, false);
    }
    // collect current customs
    Map<String, MetaData.Custom> existingCustoms = new HashMap<>();
    for (ObjectObjectCursor<String, MetaData.Custom> customCursor : metaData.customs()) {
        existingCustoms.put(customCursor.key, customCursor.value);
    }
    // upgrade global custom meta data
    Map<String, MetaData.Custom> upgradedCustoms = metaDataUpgrader.customMetaDataUpgraders.apply(existingCustoms);
    if (upgradedCustoms.equals(existingCustoms) == false) {
        existingCustoms.keySet().forEach(upgradedMetaData::removeCustom);
        for (Map.Entry<String, MetaData.Custom> upgradedCustomEntry : upgradedCustoms.entrySet()) {
            upgradedMetaData.putCustom(upgradedCustomEntry.getKey(), upgradedCustomEntry.getValue());
        }
        changed = true;
    }
    return changed ? upgradedMetaData.build() : metaData;
}
 
Example 14
Project: securelogin-java   File: SecureLogin.java   View Source Code Vote up 5 votes
private static void verifyScope(Options options, Map<String, List<String>> scope)
        throws SecureLoginVerificationException {
    if (options.isPasswordChange()) {
        boolean properScope = scope.get("mode").contains("change") && scope.containsKey("to") && scope.size() == 2;
        if (!properScope) {
            throw new SecureLoginVerificationException(SecureLoginVerificationFailure.NOT_CHANGE_TOKEN_MODE);
        }
    } else if (!scope.isEmpty() && !scope.equals(options.getScope())){
        throw new SecureLoginVerificationException(SecureLoginVerificationFailure.INVALID_SCOPE);
    }
}
 
Example 15
Project: athena   File: OspfNbrImpl.java   View Source Code Vote up 4 votes
/**
 * Builds the LsUpdate for flooding.
 *
 * @param txList list contains LSAs
 * @return list of LsUpdate instances
 */
private List buildLsUpdate(Map<String, OspfLsa> txList) {
    List<LsUpdate> lsUpdateList = new ArrayList<>();
    ListIterator itr = new ArrayList(txList.keySet()).listIterator();
    while (itr.hasNext()) {
        LsUpdate lsupdate = new LsUpdate();
        // seting OSPF Header
        lsupdate.setOspfVer(OspfUtil.OSPF_VERSION);
        lsupdate.setOspftype(OspfPacketType.LSUPDATE.value());
        lsupdate.setRouterId(ospfArea.routerId());
        lsupdate.setAreaId(ospfArea.areaId());
        lsupdate.setAuthType(OspfUtil.NOT_ASSIGNED);
        lsupdate.setAuthentication(OspfUtil.NOT_ASSIGNED);
        lsupdate.setOspfPacLength(OspfUtil.NOT_ASSIGNED); // to calculate packet length
        lsupdate.setChecksum(OspfUtil.NOT_ASSIGNED);

        //limit to mtu
        int currentLength = OspfUtil.OSPF_HEADER_LENGTH + OspfUtil.FOUR_BYTES;
        int maxSize = ospfInterface.mtu() -
                OspfUtil.LSA_HEADER_LENGTH; // subtract a normal IP header.

        int noLsa = 0;
        while (itr.hasNext()) {

            String key = (String) itr.next();
            OspfLsa lsa = txList.get(key);
            if ((lsa.age() + OspfParameters.INFTRA_NS_DELAY) >= OspfParameters.MAXAGE) {
                ((LsaHeader) lsa.lsaHeader()).setAge(OspfParameters.MAXAGE);
            } else {
                ((LsaHeader) lsa.lsaHeader()).setAge(lsa.age() + OspfParameters.INFTRA_NS_DELAY);
            }

            if ((currentLength + ((LsaHeader) lsa.lsaHeader()).lsPacketLen()) >= maxSize) {
                itr.previous();
                break;
            }
            log.debug("FloodingTimer::LSA Type::{}, Header: {}, LSA: {}", lsa.getOspfLsaType(),
                      lsa.lsaHeader(), lsa);

            if (lsa != null) {
                lsupdate.addLsa(lsa);
                noLsa++;
                currentLength = currentLength + ((LsaHeader) lsa.lsaHeader()).lsPacketLen();
            }
            log.debug("FloodingTimer::Removing key {}", key);
            if (txList.equals(reTxList)) {
                reTxList.remove(key);
                pendingReTxList.put(key, lsa);
            }
        }
        //set number of lsa's
        lsupdate.setNumberOfLsa(noLsa);
        lsUpdateList.add(lsupdate);
    }
    return lsUpdateList;
}
 
Example 16
Project: aries-jpa   File: AriesEntityManagerFactoryBuilder.java   View Source Code Vote up 4 votes
@Override
public EntityManagerFactory createEntityManagerFactory(Map<String, Object> props) {
	
	synchronized (this) {
		if (closed) {
			throw new IllegalStateException("The EntityManagerFactoryBuilder for " + 
					getPUName() + " is no longer valid");
		}
	}
	
	if (bundle.getState() == Bundle.UNINSTALLED || bundle.getState() == Bundle.INSTALLED
			|| bundle.getState() == Bundle.STOPPING) {
		// Not sure why but during the TCK tests updated sometimes was
		// called for uninstalled bundles
		throw new IllegalStateException("The EntityManagerFactoryBuilder for " + 
				getPUName() + " is no longer valid");
	}
	
	Map<String, Object> processedProperties = processProperties(props);
	
	synchronized (this) {
		if(processedProperties.equals(activeProps) && emf != null) {
			return emf;
		}
	}
	
	closeEMF();
	
	final EntityManagerFactory toUse = createAndPublishEMF(processedProperties);
	
	return (EntityManagerFactory) Proxy.newProxyInstance(getClass().getClassLoader(), 
			new Class<?>[] {EntityManagerFactory.class}, new InvocationHandler() {
				
				@Override
				public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
					if("close".equals(method.getName())) {
						// Close the registration as per the spec
						closeEMF();
						// Do not delegate as the closeEMF call already closes
						return null;
					}
					return method.invoke(toUse, args);
				}
			});
}
 
Example 17
Project: centraldogma   File: GitRepositoryMigrationTest.java   View Source Code Vote up 4 votes
/**
 * Makes sure a legacy {@link GitRepository} is migrated to the modern format.
 */
@Test
public void singleRepositoryMigration() {
    final File repoDir0 = new File(tempDir.getRoot(), "legacy");
    final File repoDir1 = new File(tempDir.getRoot(), "modern");
    final GitRepository repo0 = new GitRepository(proj, repoDir0, V0, commonPool(), 0, Author.SYSTEM);
    try {
        assertThat(repo0.format()).isSameAs(V0);

        // Put some commits into the legacy repo.
        for (int i = 1; i < 128; i++) {
            repo0.commit(new Revision(i), i * 1000, new Author("user" + rnd() + "@example.com"),
                         "Summary " + rnd(), "Detail " + rnd(), Markup.PLAINTEXT,
                         Change.ofTextUpsert("/file_" + rnd() + ".txt", "content " + i)).join();
        }

        // Build a clone in modern format.
        repo0.cloneTo(repoDir1);

        final GitRepository repo1 = new GitRepository(proj, repoDir1, commonPool());
        try {
            assertThat(repo1.format()).isSameAs(V1);

            // Make sure all commits are identical.
            final List<Commit> commits0 = repo0.history(
                    Revision.INIT, Revision.HEAD, Repository.ALL_PATH, Integer.MAX_VALUE).join();
            final List<Commit> commits1 = repo1.history(
                    Revision.INIT, Revision.HEAD, Repository.ALL_PATH, Integer.MAX_VALUE).join();

            assertThat(commits1).isEqualTo(commits0);

            // Make sure all commits are ordered correctly.
            for (int i = 0; i < commits0.size(); i++) {
                assertThat(commits0.get(i).revision().major()).isEqualTo(i + 1);
            }

            // Make sure the changes of all commits are identical.
            for (Commit c : commits0) {
                if (c.revision().major() == 1) {
                    continue;
                }

                final Map<String, Change<?>> changes0 = repo0.diff(
                        c.revision().backward(1), c.revision(), Repository.ALL_PATH).join();
                final Map<String, Change<?>> changes1 = repo0.diff(
                        c.revision().backward(1), c.revision(), Repository.ALL_PATH).join();

                if (changes0.equals(changes1)) {
                    logger.debug("{}: {}", c.revision().major(), changes0);
                } else {
                    logger.warn("{}: {} vs. {}", c.revision().major(), changes0, changes1);
                }

                assertThat(changes1)
                        .withFailMessage("mismatching changes for revision %s", c.revision().major())
                        .isEqualTo(changes0);
            }
        } finally {
            repo1.close();
        }
    } finally {
        repo0.close();
    }
}
 
Example 18
Project: spring-credhub   File: CredHubInterpolationServiceDataPostProcessorTests.java   View Source Code Vote up 4 votes
private boolean mapsAreEquivalent(Map<String, ?> actual, Map<String, ?> expected) {
	return expected.equals(actual);
}
 
Example 19
Project: microprofile-opentracing   File: TestSpan.java   View Source Code Vote up 4 votes
/**
 * {@inheritDoc}
 */
@Override
public boolean equals(final Object obj) {
    TestSpan otherSpan = (TestSpan) obj;
    if (otherSpan != null) {
        if (!cachedOperationName.equals(otherSpan.cachedOperationName)) {
            System.err.println("MISMATCH: Operation names don't match: "
                    + cachedOperationName + " ; "
                    + otherSpan.cachedOperationName);
            return false;
        }
        
        if (tags.size() != otherSpan.tags.size()) {
            System.err.println("MISMATCH: Number of tags doesn't match");
            return false;
        }

        if (!tags.equals(otherSpan.tags)) {
            return false;
        }
        
        if (logEntries.size() != otherSpan.logEntries.size()) {
            System.err.println(
                    "MISMATCH: Number of log entries doesn't match ("
                            + logEntries.size() + ", "
                            + otherSpan.logEntries.size() + ")");
            return false;
        }
        
        for (int i = 0; i < logEntries.size(); i++) {
            Map<String, ?> logEntryX = logEntries.get(i);
            Map<String, ?> logEntryY = otherSpan.logEntries.get(i);
            
            if (!logEntryX.equals(logEntryY)) {
                return false;
            }
        }

        return true;
    }
    return super.equals(obj);
}
 
Example 20
Project: Rubus   File: LiveVariable.java   View Source Code Vote up 3 votes
/**
 * Stores the given result for the given block and updates the
 * <code>changed</code> flag as appropriate.
 *
 * @param block  Block.
 * @param map    New result.
 */
private void storeResult(Block block, Map<Integer, Type> map) {
  if(!map.equals(live.get(block))) {
    changed = true;
    live.put(block, map);
  }
}