Example usage for java.util HashMap equals

List of usage examples for java.util HashMap equals

Introduction

In this page you can find the example usage for java.util HashMap equals.

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this map for equality.

Usage

From source file:io.fabric8.kubernetes.client.utils.ResourceCompare.java

public static <T> boolean equals(T left, T right) {
    HashMap<String, Object> leftMap = trim((Map<String, Object>) JSON_MAPPER.convertValue(left, TYPE_REF));
    HashMap<String, Object> rightMap = trim((Map<String, Object>) JSON_MAPPER.convertValue(right, TYPE_REF));
    return leftMap.equals(rightMap);
}

From source file:com.google.gwt.emultest.java.util.HashMapTest.java

public void testEquals() {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(hashMap);

    hashMap.put(KEY_KEY, VALUE_VAL);/*from   w  ww .ja  va 2s .  c  o m*/

    HashMap<String, String> copyMap = cloneMap(hashMap);

    assertTrue(hashMap.equals(copyMap));
    hashMap.put(VALUE_VAL, KEY_KEY);
    assertFalse(hashMap.equals(copyMap));
}

From source file:net.bluehornreader.service.FeedManagerService.java

/**
 * Assigns the feeds to crawlers. <p/>
 *
 * Should work but there are many ways to improve it:
 *
 * <ul> It's probably a good idea to shuffle the feeds every once in a while (like 1 hour) </ul>
 *
 * <ul> When there's any change, everything is computed from scratch and marked as new, causing various things to restart at once </ul>
 *
 * <ul> In a big deployment it may take too long to assign the feeds (note: 100000 feeds is not much) </ul>
 */// w  w w .  ja v a  2 s .  c om
private void distributeFeeds() throws Exception {
    long begin = System.currentTimeMillis();

    ArrayList<Crawler> crawlers = crawlerDb.getAll(); // ttt1 reads all fields but doesn't need them
    ArrayList<Crawler> liveCrawlers = new ArrayList<>();
    ArrayList<Crawler> deadCrawlers = new ArrayList<>();
    for (Crawler crawler : crawlers) {
        if (checkAndStoreAlive(crawler)) {
            liveCrawlers.add(crawler);
        } else {
            deadCrawlers.add(crawler);
        }
    }

    HashMap<String, ArrayList<String>> newFeedMap = new HashMap<>();
    if (liveCrawlers.isEmpty()) {
        LOG.warn("No live crawlers found");
    } else {
        Collections.sort(liveCrawlers, new Comparator<Crawler>() {
            @Override
            public int compare(Crawler o1, Crawler o2) {
                return o1.crawlerId.compareTo(o2.crawlerId);
            }
        });
        for (Crawler crawler : liveCrawlers) {
            newFeedMap.put(crawler.crawlerId, new ArrayList<String>());
        }
        int k = 0;
        for (Feed feed : feeds) {
            newFeedMap.get(liveCrawlers.get(k).crawlerId).add(feed.feedId);
            ++k;
            if (k >= liveCrawlers.size()) {
                k = 0;
            }
        }
    }

    if (!newFeedMap.equals(feedMap)) {
        LOG.info("new feed map");
        feedMap = newFeedMap;
        for (Crawler crawler : liveCrawlers) {
            crawlerDb.updateFeedList(crawler.crawlerId, feedMap.get(crawler.crawlerId), crawler.feedIdsSeq + 1);
        }
    }

    crawlerDb.delete(deadCrawlers);

    long end = System.currentTimeMillis();
    if (end - begin > Config.getConfig().feedManagerTickInterval / 4) {
        LOG.error("FeedManagerTickInterval is too low"); // ttt1 maybe throw
        // ttt1 perhaps have worker threads or something, if using more than 10000 feeds
    }
}

From source file:com.intuit.wasabi.api.ExperimentsResourceTest.java

@Test
public void createExclusions() throws Exception {

    ExperimentsResource experimentsResource = new ExperimentsResource(experiments, eventsExport, assignments,
            authorization, buckets, mutex, pages, priorities, "US/New York", "YYYY-mm-DD",
            new HttpHeader("jaba-???"));

    when(authorization.getUser(AUTHHEADER)).thenReturn(USER);
    when(authorization.getUserInfo(USER)).thenReturn(USERINFO);
    when(experiments.getExperiment(experiment.getID())).thenReturn(null);
    Experiment experiment2 = Experiment.withID(Experiment.ID.newInstance()).withApplicationName(TESTAPP)
            .withStartTime(new Date()).withEndTime(new Date()).withState(Experiment.State.DRAFT).build();
    List<Experiment.ID> experimentIDs = new ArrayList<>();
    experimentIDs.add(experiment2.getID());
    ExperimentIDList experimentIDList = ExperimentIDList.newInstance().withExperimentIDs(experimentIDs).build();
    try {// ww  w . ja  v a2s  .c  om
        experimentsResource.createExclusions(experiment.getID(), experimentIDList, AUTHHEADER);
    } catch (ExperimentNotFoundException ignored) {
    }

    when(experiments.getExperiment(experiment.getID())).thenReturn(experiment);
    HashMap<Experiment.ID, Experiment.ID> hashMap = new HashMap<>();
    hashMap.put(experiment.getID(), experiment2.getID());
    List<Map> exclusionsList = new ArrayList<>();
    exclusionsList.add(hashMap);
    when(mutex.createExclusions(experiment.getID(), experimentIDList, USERINFO)).thenReturn(exclusionsList);
    HashMap<String, Object> result = new HashMap<>();
    result.put("exclusions", exclusionsList);
    Response response = experimentsResource.createExclusions(experiment.getID(), experimentIDList, AUTHHEADER);
    assert (result.equals(response.getEntity()));

    doThrow(AuthenticationException.class).when(authorization).checkUserPermissions(USER,
            experiment.getApplicationName(), Permission.CREATE);
    try {
        experimentsResource.createExclusions(experiment.getID(), experimentIDList, AUTHHEADER);
        fail();
    } catch (AuthenticationException ignored) {
    }
}

From source file:org.apache.geode.internal.cache.wan.WANTestBase.java

public static void checkQueueOnSecondary(final Map primaryUpdatesMap) {
    final HashMap secondaryUpdatesMap = new HashMap();
    secondaryUpdatesMap.put("Create", listener1.createList);
    secondaryUpdatesMap.put("Update", listener1.updateList);
    secondaryUpdatesMap.put("Destroy", listener1.destroyList);

    Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> {
        secondaryUpdatesMap.put("Create", listener1.createList);
        secondaryUpdatesMap.put("Update", listener1.updateList);
        secondaryUpdatesMap.put("Destroy", listener1.destroyList);
        assertEquals("Expected secondary map to be " + primaryUpdatesMap + " but it is " + secondaryUpdatesMap,
                true, secondaryUpdatesMap.equals(primaryUpdatesMap));
    });/*from www  .  j  av  a 2  s . co m*/
}

From source file:org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.EqualToExpr.java

@SuppressWarnings("unchecked")
private Result doComparison(Result left, Result right) throws ExecException {
    if (left.returnStatus != POStatus.STATUS_OK) {
        return left;
    }//ww w  . ja v a2 s .co  m
    if (right.returnStatus != POStatus.STATUS_OK) {
        return right;
    }
    // if either operand is null, the result should be
    // null
    if (left.result == null || right.result == null) {
        left.result = null;
        left.returnStatus = POStatus.STATUS_OK;
        return left;
    }

    if (left.result instanceof Comparable && right.result instanceof Comparable) {
        if (((Comparable) left.result).compareTo(right.result) == 0) {
            left.result = Boolean.TRUE;
        } else {
            left.result = Boolean.FALSE;
        }
    } else if (left.result instanceof HashMap && right.result instanceof HashMap) {
        HashMap leftMap = (HashMap) left.result;
        HashMap rightMap = (HashMap) right.result;
        if (leftMap.equals(rightMap)) {
            left.result = Boolean.TRUE;
        } else {
            left.result = Boolean.FALSE;
        }
    } else {
        throw new ExecException("The left side and right side has the different types");
    }
    illustratorMarkup(null, left.result, (Boolean) left.result ? 0 : 1);
    return left;
}

From source file:org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.NotEqualToExpr.java

@SuppressWarnings("unchecked")
private Result doComparison(Result left, Result right) throws ExecException {
    if (left.returnStatus != POStatus.STATUS_OK) {
        return left;
    }/*from   w  w w  .j av  a  2 s  .  c  o m*/
    if (right.returnStatus != POStatus.STATUS_OK) {
        return right;
    }
    // if either operand is null, the result should be
    // null
    if (left.result == null || right.result == null) {
        left.result = null;
        left.returnStatus = POStatus.STATUS_OK;
        return left;
    }

    if (left.result instanceof Comparable && right.result instanceof Comparable) {
        if (((Comparable) left.result).compareTo(right.result) != 0) {
            left.result = Boolean.TRUE;
        } else {
            left.result = Boolean.FALSE;
        }
    } else if (left.result instanceof HashMap && right.result instanceof HashMap) {
        HashMap leftMap = (HashMap) left.result;
        HashMap rightMap = (HashMap) right.result;
        if (leftMap.equals(rightMap)) {
            left.result = Boolean.FALSE;
        } else {
            left.result = Boolean.TRUE;
        }
    } else {
        throw new ExecException("The left side and right side has the different types");
    }
    illustratorMarkup(null, left.result, (Boolean) left.result ? 0 : 1);
    return left;
}

From source file:org.apache.ranger.hadoop.client.config.HadoopConfigHolder.java

public static HadoopConfigHolder getInstance(String aDatasourceName,
        HashMap<String, String> connectionProperties) {
    HadoopConfigHolder ret = dataSource2HadoopConfigHolder.get(aDatasourceName);
    if (ret == null) {
        synchronized (HadoopConfigHolder.class) {
            HadoopConfigHolder temp = ret;
            if (temp == null) {
                ret = new HadoopConfigHolder(aDatasourceName, connectionProperties);
                dataSource2HadoopConfigHolder.put(aDatasourceName, ret);
            }//from w  w  w . j  av a 2  s .  c  o m
        }
    } else {
        if (connectionProperties != null && !connectionProperties.equals(ret.connectionProperties)) {
            ret = new HadoopConfigHolder(aDatasourceName, connectionProperties);
            dataSource2HadoopConfigHolder.remove(aDatasourceName);
            dataSource2HadoopConfigHolder.put(aDatasourceName, ret);
        }
    }
    return ret;
}

From source file:org.apache.storm.testing.Testing.java

@ClojureClass(className = "backtype.storm.testing#ms=")
public static boolean multiSetEquals(List<Object>... args) {
    int len = args.length;
    HashMap<Object, Integer> first = CoreUtil.multiSet(args[0]);
    for (int i = 1; i < len; i++) {
        HashMap<Object, Integer> other = CoreUtil.multiSet(args[i]);
        if (!first.equals(other)) {
            return false;
        }/* ww  w . j  a  va  2  s  .  c  o  m*/
    }
    return true;
}