Example usage for java.util Map equals

List of usage examples for java.util Map equals

Introduction

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

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this map for equality.

Usage

From source file:eu.sonata.nfv.nec.convert.BasicConverterTest.java

@Test
public void convertJsonToYaml() {
    String convertedYamlString = conversionService.convertToYaml(jsonString);
    Map<String, Object> mapOriginal = conversionService.convertToMap(yamlString);
    Map<String, Object> mapConverted = conversionService.convertToMap(convertedYamlString);
    assertTrue("The maps should be equal. ", mapOriginal.equals(mapConverted));
}

From source file:net.nelz.simplesm.test.InvalidateMultiCacheTest.java

@Test
public void test() {
    final TestSvc test = (TestSvc) context.getBean("testSvc");

    // The full list of ids
    final List<Long> allIds = new ArrayList<Long>();

    // The list of ids whose values we do not expect to change.
    final List<Long> noChangeIds = new ArrayList<Long>();

    // The first set of ids whose values we do expect to change
    final List<Long> firstChangeIds = new ArrayList<Long>();

    // The second set of ids whose values we do expect to change
    final List<Long> secondChangeIds = new ArrayList<Long>();

    // Create the overall list, and distribute the keys to the different types
    final Long base = RandomUtils.nextLong();
    for (int ix = 0; ix < 30; ix++) {
        final Long key = base + (ix * 100);
        allIds.add(key);//from  ww  w.  j  av a2  s .  co  m
        if (ix % 3 == 0) {
            noChangeIds.add(key);
        }
        if (ix % 3 == 1) {
            firstChangeIds.add(key);
        }
        if (ix % 3 == 2) {
            secondChangeIds.add(key);
        }
    }

    // Pull the generated results from the svc/dao. This is expected to be NOT cached.
    final Map<Long, String> originalMap = createMap(allIds, test.getRandomStrings(allIds));

    // Make sure successive calls to the svc/dao all generate the same results.
    assertEquals(originalMap, createMap(allIds, test.getRandomStrings(allIds)));
    assertEquals(originalMap, createMap(allIds, test.getRandomStrings(allIds)));

    // Invalidate a set of IDs, so that when the DAO is called for them again,
    // they will be regenerated.
    test.updateRandomStrings(firstChangeIds);

    final Map<Long, String> secondMap = createMap(allIds, test.getRandomStrings(allIds));

    // Firstly, make sure the new data looks differently than the old data.
    assertFalse(secondMap.equals(originalMap));

    // Loop through all the values. Make sure that any value we didn't expect to change
    // didn't, and that values we expect to be the same are.
    for (Map.Entry<Long, String> entry : secondMap.entrySet()) {
        final Long key = entry.getKey();
        if (firstChangeIds.contains(key)) {
            assertFalse(entry.getValue().equals(originalMap.get(key)));
        } else {
            assertEquals(entry.getValue(), originalMap.get(key));
        }
    }

    // Make sure successive calls to the svc/dao all generate the same results.
    assertEquals(secondMap, createMap(allIds, test.getRandomStrings(allIds)));
    assertEquals(secondMap, createMap(allIds, test.getRandomStrings(allIds)));

    // Invalidate yet another subset of the ids.
    test.updateRandomStringsAgain(secondChangeIds);

    final Map<Long, String> thirdMap = createMap(allIds, test.getRandomStrings(allIds));

    // Make sure this set of results is different from the last two sets
    assertFalse(thirdMap.equals(originalMap));
    assertFalse(thirdMap.equals(secondMap));

    // Again, loop through all the individual id/value pairs, making sure they
    // have updated or not according to our expectations.
    for (Map.Entry<Long, String> entry : thirdMap.entrySet()) {
        final Long key = entry.getKey();
        if (noChangeIds.contains(key)) {
            assertEquals(entry.getValue(), originalMap.get(key));
        }
        if (firstChangeIds.contains(key)) {
            assertEquals(entry.getValue(), secondMap.get(key));
        }
        if (secondChangeIds.contains(key)) {
            assertNotSame(entry.getValue(), originalMap.get(key));
        }
    }

    // Make sure succcessive calls to the svc/dao return the same (cached) results.
    assertEquals(thirdMap, createMap(allIds, test.getRandomStrings(allIds)));
    assertEquals(thirdMap, createMap(allIds, test.getRandomStrings(allIds)));
}

From source file:com.google.code.ssm.test.InvalidateMultiCacheTest.java

@Test
public void test() throws InterruptedException {
    //final TestSvc test = (TestSvc) context.getBean("testSvc");

    // The full list of ids
    final List<Long> allIds = new ArrayList<Long>();

    // The list of ids whose values we do not expect to change.
    final List<Long> noChangeIds = new ArrayList<Long>();

    // The first set of ids whose values we do expect to change
    final List<Long> firstChangeIds = new ArrayList<Long>();

    // The second set of ids whose values we do expect to change
    final List<Long> secondChangeIds = new ArrayList<Long>();

    // Create the overall list, and distribute the keys to the different types
    final Long base = RandomUtils.nextLong();
    for (int ix = 0; ix < 30; ix++) {
        final Long key = base + (ix * 100);
        allIds.add(key);// w ww .j  a  v  a2  s  . c  o  m
        if (ix % 3 == 0) {
            noChangeIds.add(key);
        }
        if (ix % 3 == 1) {
            firstChangeIds.add(key);
        }
        if (ix % 3 == 2) {
            secondChangeIds.add(key);
        }
    }

    // Pull the generated results from the svc/dao. This is expected to be NOT cached.
    final Map<Long, String> originalMap = createMap(allIds, test.getRandomStrings(allIds));

    Thread.sleep(1000);
    // Make sure successive calls to the svc/dao all generate the same results.
    assertEquals(originalMap, createMap(allIds, test.getRandomStrings(allIds)));
    assertEquals(originalMap, createMap(allIds, test.getRandomStrings(allIds)));

    // Invalidate a set of IDs, so that when the DAO is called for them again,
    // they will be regenerated.
    test.updateRandomStrings(firstChangeIds);

    final Map<Long, String> secondMap = createMap(allIds, test.getRandomStrings(allIds));

    // Firstly, make sure the new data looks differently than the old data.
    assertFalse(secondMap.equals(originalMap));

    // Loop through all the values. Make sure that any value we didn't expect to change
    // didn't, and that values we expect to be the same are.
    Thread.sleep(1000);
    for (Map.Entry<Long, String> entry : secondMap.entrySet()) {
        final Long key = entry.getKey();
        if (firstChangeIds.contains(key)) {
            assertFalse(entry.getValue().equals(originalMap.get(key)));
        } else {
            assertEquals(entry.getValue(), originalMap.get(key));
        }
    }

    // Make sure successive calls to the svc/dao all generate the same results.
    assertEquals(secondMap, createMap(allIds, test.getRandomStrings(allIds)));
    assertEquals(secondMap, createMap(allIds, test.getRandomStrings(allIds)));

    // Invalidate yet another subset of the ids.
    test.updateRandomStringsAgain(secondChangeIds);

    final Map<Long, String> thirdMap = createMap(allIds, test.getRandomStrings(allIds));

    // Make sure this set of results is different from the last two sets
    assertFalse(thirdMap.equals(originalMap));
    assertFalse(thirdMap.equals(secondMap));

    // Again, loop through all the individual id/value pairs, making sure they
    // have updated or not according to our expectations.
    for (Map.Entry<Long, String> entry : thirdMap.entrySet()) {
        final Long key = entry.getKey();
        if (noChangeIds.contains(key)) {
            assertEquals(entry.getValue(), originalMap.get(key));
        }
        if (firstChangeIds.contains(key)) {
            assertEquals(entry.getValue(), secondMap.get(key));
        }
        if (secondChangeIds.contains(key)) {
            assertNotSame(entry.getValue(), originalMap.get(key));
        }
    }

    // Make sure succcessive calls to the svc/dao return the same (cached) results.
    assertEquals(thirdMap, createMap(allIds, test.getRandomStrings(allIds)));
    assertEquals(thirdMap, createMap(allIds, test.getRandomStrings(allIds)));
}

From source file:org.apache.storm.daemon.worker.stats.StatsData.java

@Override
public boolean equals(Object assignment) {
    if ((assignment instanceof StatsData) == false) {
        return false;
    }/*from www  . j a  va  2 s  .  co m*/

    StatsData otherData = (StatsData) assignment;

    for (Entry<StatsFields, Map<Integer, Object>> entry : commonFieldsMap.entrySet()) {
        StatsFields type = entry.getKey();
        Map<Integer, Object> value = entry.getValue();
        Map<Integer, Object> otherValue = otherData.getCommon(type);

        if (value.equals(otherValue) == false) {
            return false;
        }
    }

    for (Entry<StatsFields, Map<Integer, Object>> entry : spoutFieldsMap.entrySet()) {
        StatsFields type = entry.getKey();
        Map<Integer, Object> value = entry.getValue();
        Map<Integer, Object> otherValue = otherData.getSpout(type);
        if (value.equals(otherValue) == false) {
            return false;
        }
    }

    for (Entry<StatsFields, Map<Integer, Object>> entry : boltFieldsMap.entrySet()) {
        StatsFields type = entry.getKey();
        Map<Integer, Object> value = entry.getValue();
        Map<Integer, Object> otherValue = otherData.getBolt(type);

        if (value.equals(otherValue) == false) {
            return false;
        }
    }

    return true;
}

From source file:com.android.volley.toolbox.GsonRequest.java

@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>();
    }/*  w  w w  .j a v  a  2 s  .c o  m*/

    return headers;
}

From source file:tectonicus.BlockVariantTests.java

@Test
public void createMultipleStatesMap() {
    BlockVariant bv = new BlockVariant("attached=false,facing=north,powered=false,suspended=false", null);
    Map<String, String> states = bv.getStates();

    Map<Object, Object> testStates = new HashMap<>();
    testStates.put("attached", "false");
    testStates.put("facing", "north");
    testStates.put("powered", "false");
    testStates.put("suspended", "false");

    assertTrue(states.equals(testStates));
}

From source file:org.apache.fluo.recipes.core.map.it.CollisionFreeMapIT.java

private void assertWordCountsEqual(FluoClient fc) {
    Map<String, Long> expected = computeWordCounts(fc);
    Map<String, Long> actual = getComputedWordCounts(fc);
    if (!expected.equals(actual)) {
        diff(expected, actual);/*from  w ww . j av a2 s .  com*/
        Assert.fail();
    }
}

From source file:org.zenoss.zep.rest.ConfigResource.java

@POST
@Path("index_details")
@Consumes({ MediaType.APPLICATION_JSON, ProtobufConstants.CONTENT_TYPE_PROTOBUF })
@GZIP/*  w  w w .  j a va2s . c  o m*/
public Response createIndexedDetails(EventDetailItemSet items) throws ZepException {
    if (items.getDetailsCount() == 0) {
        return Response.status(Status.BAD_REQUEST).build();
    }

    Map<String, EventDetailItem> currentItems = this.detailsConfigDao.getEventDetailItemsByName();

    for (EventDetailItem item : items.getDetailsList()) {
        this.detailsConfigDao.create(item);
    }

    Map<String, EventDetailItem> newItems = this.detailsConfigDao.getEventDetailItemsByName();
    if (!currentItems.equals(newItems)) {
        this.applicationEventPublisher.publishEvent(new IndexDetailsUpdatedEvent(this, newItems));
    }

    return Response.status(Status.ACCEPTED).build();
}

From source file:com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot.java

public boolean compareToUserDefineWorker(WorkerAssignment worker, Map<Integer, String> taskToComponent) {
    int cpu = worker.getCpu();
    if (cpu != 0 && this.cpu != cpu)
        return false;
    long mem = worker.getMem();
    if (mem != 0 && this.memSize != mem)
        return false;
    String jvm = worker.getJvm();
    if (jvm != null && !jvm.equals(this.jvm))
        return false;
    String hostName = worker.getHostName();
    if (NetWorkUtils.equals(hostname, hostName) == false)
        return false;
    int port = worker.getPort();
    if (port != 0 && port != this.getPort())
        return false;
    Map<String, Integer> componentToNum = worker.getComponentToNum();
    Map<String, Integer> myComponentToNum = new HashMap<String, Integer>();
    for (Integer task : tasks) {
        String component = taskToComponent.get(task);
        Integer i = myComponentToNum.get(component);
        if (i == null) {
            i = 0;// w  w w .  j a  v a2 s  .c  o m
        }
        myComponentToNum.put(component, ++i);
    }

    return myComponentToNum.equals(componentToNum);
}

From source file:org.redpill.alfresco.module.metadatawriter.aspect.impl.ExportMetadataAspect.java

public void onUpdateProperties(final NodeRef nodeRef, final Map<QName, Serializable> before,
        final Map<QName, Serializable> after) {

    verifyMetadataExportableNode(nodeRef, MetadataWriterModel.ASPECT_METADATA_WRITEABLE, nodeService);

    if (logger.isDebugEnabled()) {
        logger.debug("Properties updated for node " + nodeRef);
    }//from   w  ww  . jav  a 2 s .  c o  m

    // Only update properties if before and after differ
    if (nodeService.exists(nodeRef) && !after.equals(before)) {

        updateProperties(nodeRef, after);
    }
}