Java Code Examples for java.util.HashMap#equals()

The following examples show how to use java.util.HashMap#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InventoryItemSource.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private boolean recomputeItemStackCount() {
    if (!checkItemHandlerValid(false)) {
        return false;
    }
    this.lastStoredItemListUpdateTick = world.getTotalWorldTime();
    HashMap<ItemStackKey, Integer> amountMap = new HashMap<>();
    for (int i = 0; i < itemHandler.getSlots(); i++) {
        ItemStack itemStack = itemHandler.getStackInSlot(i);
        if (itemStack.isEmpty()) continue;
        ItemStackKey stackKey = new ItemStackKey(itemStack);
        amountMap.put(stackKey, amountMap.getOrDefault(stackKey, 0) + itemStack.getCount());
    }
    if (amountMap.equals(itemStackByAmountMap)) {
        return false;
    }
    HashSet<ItemStackKey> removedItems = new HashSet<>(itemStackByAmountMap.keySet());
    removedItems.removeAll(amountMap.keySet());
    this.itemStackByAmountMap = amountMap;
    if (changeCallback != null) {
        changeCallback.onStoredItemsUpdated(amountMap, removedItems);
    }
    return true;
}
 
Example 2
Source File: ComponentHotDeployTask.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
private boolean needReload() {

        if (!componentLocation.exists() || !componentLocation.isDirectory()) {
            log.error("Component location '" + componentLocation.getAbsolutePath()
                      + "' does not exist or is not a directory - skipping it");
            return false;
        }

        boolean result = false;

        File[] jarFiles = componentLocation.listFiles(new JarFilenameFilter());
        if (jarFiles != null) {
            HashMap<String, Long> currentModificationTimes = getLastModificationTimes(jarFiles);
            if (!currentModificationTimes.equals(lastModificationTimes)) {

                lastModificationTimes = currentModificationTimes;
                result = true;
            }
        }

        return result;
    }
 
Example 3
Source File: WANTestBase.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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);
  
  WaitCriterion wc = new WaitCriterion() {
    public boolean done() {
      secondaryUpdatesMap.put("Create", listener1.createList);
      secondaryUpdatesMap.put("Update", listener1.updateList);
      secondaryUpdatesMap.put("Destroy", listener1.destroyList);
      if (secondaryUpdatesMap.equals(primaryUpdatesMap)) {
        return true;
      }
      return false;
    }

    public String description() {
      return "Expected seconadry map to be " + primaryUpdatesMap + " but it is " + secondaryUpdatesMap;
    }
  };
  DistributedTestCase.waitForCriterion(wc, 300000, 500, true); 
}
 
Example 4
Source File: WANTestBase.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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);
  
  WaitCriterion wc = new WaitCriterion() {
    public boolean done() {
      secondaryUpdatesMap.put("Create", listener1.createList);
      secondaryUpdatesMap.put("Update", listener1.updateList);
      secondaryUpdatesMap.put("Destroy", listener1.destroyList);
      if (secondaryUpdatesMap.equals(primaryUpdatesMap)) {
        return true;
      }
      return false;
    }

    public String description() {
      return "Expected seconadry map to be " + primaryUpdatesMap + " but it is " + secondaryUpdatesMap;
    }
  };
  DistributedTestCase.waitForCriterion(wc, 300000, 500, true); 
}
 
Example 5
Source File: Anagram.java    From algorithms101 with MIT License 5 votes vote down vote up
public boolean isAnagram1(String text1, String text2) {

        // Map 1
        HashMap<String, Integer> map1 = map(text1);

        // Map 2
        HashMap<String, Integer> map2 = map(text2);

        // Compare letters and frequency of characters in Maps
        return map1.equals(map2);
    }
 
Example 6
Source File: ResourceCompare.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public static <T>  boolean equals(T left, T right) {
    ObjectMapper jsonMapper = Serialization.jsonMapper();
    Map<String, Object> leftJson = (Map<String, Object>) jsonMapper.convertValue(left, TYPE_REF);
    Map<String, Object> rightJson = (Map<String, Object>) jsonMapper.convertValue(right, TYPE_REF);

    Map<String, Object> leftLabels = fetchLabels(leftJson);
    Map<String, Object> rightLabels = fetchLabels(rightJson);

    HashMap<String, Object> leftMap = trim(leftJson);
    HashMap<String, Object> rightMap = trim(rightJson);

    return leftMap.equals(rightMap) && leftLabels.equals(rightLabels);
}
 
Example 7
Source File: EqualToExpr.java    From spork with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Result doComparison(Result left, Result right) throws ExecException {
    if (left.returnStatus != POStatus.STATUS_OK) {
        return left;
    }
    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;
}
 
Example 8
Source File: NotEqualToExpr.java    From spork with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Result doComparison(Result left, Result right) throws ExecException {
    if (left.returnStatus != POStatus.STATUS_OK) {
        return left;
    }
    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;
}
 
Example 9
Source File: TreedMapper.java    From compiler with Apache License 2.0 4 votes vote down vote up
private void lcs(ArrayList<ASTNode> lM, ArrayList<ASTNode> lN, ArrayList<Integer> lcsM, ArrayList<Integer> lcsN) {
	int lenM = lM.size(), lenN = lN.size();
	int[][] d = new int[2][lenN + 1];
	char[][] p = new char[lenM + 1][lenN + 1];
	for (int j = 0; j <= lenN; j++)
		d[1][j] = 0;
	for (int i = lenM-1; i >= 0; i--) {
		ASTNode nodeM = lM.get(i);
		int hM = treeHeight.get(nodeM);
		HashMap<String, Integer> vM = treeVector.get(nodeM);
		for (int j = 0; j <= lenN; j++)
			d[0][j] = d[1][j];
		for (int j = lenN-1; j >= 0; j--) {
			ASTNode nodeN = lN.get(j);
			int hN = treeHeight.get(nodeN);
			HashMap<String, Integer> vN = treeVector.get(nodeN);
			if (hM == hN && nodeM.getNodeType() == nodeN.getNodeType() && vM.equals(vN) && subtreeMatch(nodeM, nodeN)) {
				d[1][j] = d[0][j + 1] + 1;
				p[i][j] = 'D';
			} else if (d[0][j] >= d[1][j + 1]) {
				d[1][j] = d[0][j];
				p[i][j] = 'U';
			} else {
				d[1][j] = d[1][j + 1];
				p[i][j] = 'R';
			}
		}
	}
	int i = 0, j = 0;
	while (i < lenM && j < lenN) {
		if (p[i][j] == 'D') {
			lcsM.add(i);
			lcsN.add(j);
			i++;
			j++;
		} else if (p[i][j] == 'U')
			i++;
		else
			j++;
	}
}