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

The following are Jave code examples for showing how to use equals() of the java.util.Map.Entry 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: NucleusFramework-master View Source Vote up 6 votes
@Override
public boolean remove(Object o) {
    Set<Entry<K, Collection<V>>> entrySet = _keyToValue.asMap().entrySet();
    //noinspection SuspiciousMethodCalls
    if (!entrySet.contains(o))
        return false;

    for (Entry<K, Collection<V>> entry : entrySet) {
        if (entry.equals(o)) {
            return !MultiBiMap.this.removeAll(entry.getKey()).isEmpty();
        }
    }

    return false;
}
 
Example 2
Project: CarpoolBackend-master View Source Vote up 6 votes
public static ArrayList<Entry<Long,Integer>> sortMap(HashMap<Long,Integer> map){
	ArrayList<Entry<Long,Integer>> list = new ArrayList<Entry<Long,Integer>>();		
	Entry<Long,Integer> maxEntry = null;
	Entry<Long,Integer> pre = null;
	while(map.size()>0){
		for(Entry<Long,Integer> entry : map.entrySet()) {
			if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
				maxEntry = entry;
			}
		}
		if(!list.contains(maxEntry))list.add(maxEntry);
		map.remove(maxEntry.getKey());
		if(pre!=null && pre.equals(maxEntry)){
			maxEntry=null;
			pre = null;
		}
		else pre = maxEntry;
	}

	return list;

}
 
Example 3
Project: usergrid-master View Source Vote up 6 votes
@Override
public void runTool( CommandLine line ) throws Exception {
    startSpring();

    setVerbose( line );

    // ExportDataCreator dataCreator = new ExportDataCreator(emf,
    // managementService);
    // dataCreator.createTestData();

    applyOrgId( line );
    prepareBaseOutputFileName( line );
    outputDir = createOutputParentDir();
    logger.info( "Export directory: " + outputDir.getAbsolutePath() );

    // Export organizations separately.
    exportOrganizations();

    // Loop through the organizations
    Map<UUID, String> organizations = getOrgs();
    for ( Entry<UUID, String> organization : organizations.entrySet() ) {

        if ( organization.equals( properties.getProperty( "usergrid.test-account.organization" ) ) ) {
            // Skip test data from being exported.
            continue;
        }

        exportApplicationsForOrg( organization );
    }
}
 
Example 4
Project: SchemaCrawler-master View Source Vote up 6 votes
private Set<Index> findRedundantIndexes(final Collection<Index> indexes)
{
  final Set<Index> redundantIndexes = new HashSet<>();

  if (indexes == null || indexes.isEmpty())
  {
    return redundantIndexes;
  }

  final Map<Index, List<String>> indexColumns = new HashMap<>(indexes.size());
  for (final Index index: indexes)
  {
    indexColumns.put(index, MetaDataUtility.columnNames(index));
  }

  for (final Entry<Index, List<String>> indexColumnEntry1: indexColumns
    .entrySet())
  {
    for (final Entry<Index, List<String>> indexColumnEntry2: indexColumns
      .entrySet())
    {
      if (!indexColumnEntry1.equals(indexColumnEntry2))
      {
        if (listStartsWith(indexColumnEntry1.getValue(),
                           indexColumnEntry2.getValue()))
        {
          redundantIndexes.add(indexColumnEntry2.getKey());
        }
      }
    }
  }
  return redundantIndexes;
}
 
Example 5
Project: SpaceDefence-master View Source Vote up 6 votes
public synchronized boolean removeClientSocket(Socket s) {
	for (Entry<Integer, Socket> socket : clients.entrySet()) {
		if (socket.equals(s)) {
			return clients.remove(socket.getKey()) != null;
		}
	}
	return false;
}
 
Example 6
Project: FreeBuilder-master View Source Vote up 6 votes
ContainmentAssertion<K, V> and(Entry<K, V> entry) {
  expected.add(entry);
  if (!entryIterator.hasNext()) {
    fail("contains", expected, "is missing", entry);
    return new FailedContainmentAssertion();
  }
  Entry<K, V> actualEntry = entryIterator.next();
  if (entry.equals(actualEntry)) {
    return this;
  }

  // The subject does not match the order specified by the user, but the entry may still be
  // present. Delegate to an OutOfOrderContainmentAssertion.
  Multimap<K, V> remaining = ArrayListMultimap.create();
  remaining.put(actualEntry.getKey(), actualEntry.getValue());
  while (entryIterator.hasNext()) {
    actualEntry = entryIterator.next();
    remaining.put(actualEntry.getKey(), actualEntry.getValue());
  }
  expected.remove(expected.size() - 1);
  return new OutOfOrderContainmentAssertion(expected, remaining).and(entry);
}
 
Example 7
Project: schemacrawler-master View Source Vote up 6 votes
private Set<Index> findRedundantIndices(final Collection<Index> indices)
{
  final Set<Index> redundantIndices = new HashSet<Index>();
  final Map<Index, List<String>> indexColumns = new HashMap<Index, List<String>>(indices
    .size());
  for (final Index index: indices)
  {
    indexColumns.put(index, columns(index));
  }

  for (final Entry<Index, List<String>> indexColumnEntry1: indexColumns
    .entrySet())
  {
    for (final Entry<Index, List<String>> indexColumnEntry2: indexColumns
      .entrySet())
    {
      if (!indexColumnEntry1.equals(indexColumnEntry2))
      {
        if (listStartsWith(indexColumnEntry1.getValue(),
                           indexColumnEntry2.getValue()))
        {
          redundantIndices.add(indexColumnEntry2.getKey());
        }
      }
    }
  }
  return redundantIndices;
}
 
Example 8
Project: earthsci-master View Source Vote up 5 votes
/**
 * Add a new entry in the colour map that is:
 * <ul>
 * <li>Half way between the selected entry and the previous entry (if one
 * exists); or
 * <li>Half way between the selected entry and the min value (if no previous
 * entry exists and selected != min)
 * <li>Half way between the selected entry and the next entry (if min entry
 * is selected); or
 * <li>Half way between the selected entry and the max value (if min entry
 * is selected and no other entry exists); or
 * <li>Half way between the min value and the max value (if no entries exist
 * in the table)
 * </ul>
 * 
 */
private void addNewEntry()
{
	Double newEntryValue = getMinValue();

	Entry<Double, Color> selectedEntry = getSelectedTableEntry();
	if (selectedEntry == null)
	{
		// If nothing selected, either choose the first entry or the mid point
		if (map.isEmpty())
		{
			newEntryValue = getMinValue() + (getMaxValue() - getMinValue()) / 2;
		}
		else
		{
			selectedEntry = map.getFirstEntry();
		}
	}

	if (selectedEntry != null)
	{
		if (map.getSize() == 1)
		{
			// Map only contains one entry
			if (selectedEntry.getKey() == getMinValue())
			{
				// Selected entry is min value - go higher
				newEntryValue = getMinValue() + (getMaxValue() - getMinValue()) / 2;
			}
			else
			{
				// Otherwise go lower
				newEntryValue = getMinValue() + (selectedEntry.getKey() - getMinValue()) / 2;
			}
		}
		else
		{
			// Map contains more than one entry
			if (selectedEntry.equals(map.getFirstEntry()))
			{
				// Selected entry is first entry 
				if (selectedEntry.getKey() == getMinValue())
				{
					// Go between selected and next
					double nextValue = map.getNextEntry(getMinValue()).getKey();
					newEntryValue = getMinValue() + (nextValue - getMinValue()) / 2;
				}
				else
				{
					// Go between selected and min value
					newEntryValue = getMinValue() + (selectedEntry.getKey() - getMinValue()) / 2;
				}
			}
			else
			{
				// Selected entry is not first - go between previous entry
				double previousValue = map.getPreviousEntry(selectedEntry.getKey()).getKey();
				newEntryValue = previousValue + (selectedEntry.getKey() - previousValue) / 2;
			}
		}
	}

	Color newEntryColor = map.getColor(newEntryValue);
	map.addEntry(newEntryValue, newEntryColor);

}