Example usage for java.util IdentityHashMap values

List of usage examples for java.util IdentityHashMap values

Introduction

In this page you can find the example usage for java.util IdentityHashMap values.

Prototype

public Collection<V> values() 

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:Main.java

public static void main(String args[]) {

    IdentityHashMap<Integer, String> ihmap = new IdentityHashMap<Integer, String>();

    ihmap.put(1, "from");
    ihmap.put(2, "java2s.com");
    ihmap.put(3, "tutorial");

    System.out.println("Map values: " + ihmap);
    System.out.println("Collection view of the map: " + ihmap.values());
}

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

/**
 * Check the state of a newly constructed, empty IdentityHashMap.
 *
 * @param hashMap//from   w w  w . j a  v a2s  . co m
 */
private static void checkEmptyHashMapAssumptions(IdentityHashMap hashMap) {
    assertNotNull(hashMap);
    assertTrue(hashMap.isEmpty());

    assertNotNull(hashMap.values());
    assertTrue(hashMap.values().isEmpty());
    assertTrue(hashMap.values().size() == 0);

    assertNotNull(hashMap.keySet());
    assertTrue(hashMap.keySet().isEmpty());
    assertTrue(hashMap.keySet().size() == 0);

    assertNotNull(hashMap.entrySet());
    assertTrue(hashMap.entrySet().isEmpty());
    assertTrue(hashMap.entrySet().size() == 0);

    assertNotNull(hashMap.entrySet().iterator());
    assertFalse(hashMap.entrySet().iterator().hasNext());
}

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

/**
 * Test method for 'java.util.AbstractMap.values()'.
 *///ww  w  .  ja  v  a  2 s .  co m
public void testValues() {
    IdentityHashMap hashMap = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap);

    assertNotNull(hashMap.values());

    hashMap.put(KEY_KEY, VALUE_VAL);

    Collection valColl = hashMap.values();
    assertNotNull(valColl);
    assertEquals(valColl.size(), SIZE_ONE);

    Iterator itVal = valColl.iterator();
    String val = (String) itVal.next();
    assertEquals(val, VALUE_VAL);
}

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

public void testHashMapMap() {
    IdentityHashMap srcMap = new IdentityHashMap();
    assertNotNull(srcMap);/*from   w ww.  j  a v a 2 s.com*/
    checkEmptyHashMapAssumptions(srcMap);

    srcMap.put(INTEGER_1, INTEGER_11);
    srcMap.put(INTEGER_2, INTEGER_22);
    srcMap.put(INTEGER_3, INTEGER_33);

    IdentityHashMap hashMap = new IdentityHashMap(srcMap);
    assertFalse(hashMap.isEmpty());
    assertTrue(hashMap.size() == SIZE_THREE);

    Collection valColl = hashMap.values();
    assertTrue(valColl.contains(INTEGER_11));
    assertTrue(valColl.contains(INTEGER_22));
    assertTrue(valColl.contains(INTEGER_33));

    Collection keyColl = hashMap.keySet();
    assertTrue(keyColl.contains(INTEGER_1));
    assertTrue(keyColl.contains(INTEGER_2));
    assertTrue(keyColl.contains(INTEGER_3));
}

From source file:de.codesourcery.eve.skills.ui.model.impl.MarketGroupTreeModelBuilder.java

private FilteringTreeModel createTreeModel(boolean populateAllNodes) {
    long time = -System.currentTimeMillis();

    final IdentityHashMap<MarketGroup, ITreeNode> nodes = new IdentityHashMap<MarketGroup, ITreeNode>();

    // construct tree
    final List<MarketGroup> marketGroups = dataModel.getLeafMarketGroups();
    System.out.println("createTreeModel( populateAll = " + populateAllNodes + "): Filtering "
            + marketGroups.size() + " leaf market groups");

    //      int debugCount=0;
    for (MarketGroup marketGroup : marketGroups) {
        //         System.out.print(".");
        //         if ( (debugCount++ % 60 ) == 0 ) {
        //            System.out.println();
        //         }

        final ITreeNode node = getOrCreateTreeNode(marketGroup, nodes);
        if (populateAllNodes) {
            final List<InventoryType> members = getMembers(marketGroup);

            if (!members.isEmpty()) {
                for (InventoryType type : members) {
                    node.addChild(new DefaultTreeNode(type));
                }//ww  w .  j  a v a  2  s .  c o  m
            } else {
                nodes.remove(marketGroup);
                continue;
            }
        }

        if (marketGroup.getParent() != null) {
            MarketGroup current = marketGroup;
            while (current != null) {
                final ITreeNode toAdd = getOrCreateTreeNode(current, nodes);
                if (current.getParent() != null) {
                    ITreeNode parent = getOrCreateTreeNode(current.getParent(), nodes);
                    boolean add = true;
                    for (ITreeNode child : parent.getChildren()) {
                        if (ObjectUtils.equals(child.getValue(), current)) {
                            add = false;
                            break;
                        }
                    }
                    if (add) {
                        parent.addChild(toAdd);
                    }
                }
                current = current.getParent();
            }
        }
    }

    System.out.println("createTreeModel( populateAll = " + populateAllNodes + "): Initial tree creation took "
            + (time + System.currentTimeMillis()) + " ms");

    final ITreeNode root = new DefaultTreeNode();
    // convert all nodes without children to LazyTreeNode instances 
    for (ITreeNode node : nodes.values()) {
        final MarketGroup g = (MarketGroup) node.getValue();
        if (g.getParent() == null) { // top-level market group, add to root node
            root.addChild(wrapIfLeafNode(node));
        } else {
            wrapIfLeafNode(node);
        }
    }

    final FilteringTreeModel model = new FilteringTreeModel(new DefaultTreeModel(root));

    // sort tree nodes alphabetically
    final Comparator<ITreeNode> COMPARATOR = new Comparator<ITreeNode>() {
        @Override
        public int compare(ITreeNode o1, ITreeNode o2) {
            if (o1.getValue() instanceof MarketGroup && o2.getValue() instanceof MarketGroup) {
                final MarketGroup g1 = (MarketGroup) o1.getValue();
                final MarketGroup g2 = (MarketGroup) o2.getValue();
                return g1.getName().compareTo(g2.getName());
            } else if (o1.getValue() instanceof InventoryType && o2.getValue() instanceof InventoryType) {
                final InventoryType g1 = (InventoryType) o1.getValue();
                final InventoryType g2 = (InventoryType) o2.getValue();
                return g1.getName().compareTo(g2.getName());
            }
            throw new RuntimeException(
                    "Internal error,unhandled node values: " + o1.getValue() + " / " + o2.getValue());
        }
    };
    model.sortChildren(root, COMPARATOR, true);

    time += System.currentTimeMillis();
    System.out.println("createTreeModel( populateAll = " + populateAllNodes + ") took " + time + " ms");
    return model;
}

From source file:org.jamocha.rating.fraj.RatingProvider.java

private double rateBetaWithoutExistentials(final StatisticsProvider statisticsProvider,
        final PathNodeFilterSet toRate,
        final Map<Set<PathFilterList>, List<Pair<List<Set<PathFilterList>>, List<PathFilter>>>> componentToJoinOrder,
        final Map<Path, Set<PathFilterList>> pathToPreNetworkComponents) {
    final IdentityHashMap<Set<PathFilterList>, Data> preNetworkComponentToData = new IdentityHashMap<>();
    for (final Set<PathFilterList> comp : componentToJoinOrder.keySet()) {
        preNetworkComponentToData.put(comp, statisticsProvider.getData(comp));
    }/*w  w  w.j  a  v a 2 s .c o  m*/
    final double tupleSize = preNetworkComponentToData.values().stream().mapToDouble(Data::getTupleSize).sum();
    final double tuplesPerPage = statisticsProvider.getPageSize() / tupleSize;
    final double rowCount = calcBetaUnfilteredSize(statisticsProvider, componentToJoinOrder,
            pathToPreNetworkComponents, componentToJoinOrder.keySet());
    // joinsize is needed twice per component, thus pre-calculate it
    final Map<Set<PathFilterList>, Double> preNetworkComponentToJoinSize = preNetworkComponentToData.keySet()
            .stream()
            .collect(toMap(Function.identity(),
                    component -> joinSize(statisticsProvider, component, componentToJoinOrder.get(component),
                            componentToJoinOrder.keySet(), pathToPreNetworkComponents)));
    final double finsert = preNetworkComponentToData.entrySet().stream()
            .mapToDouble(
                    entry -> entry.getValue().getFinsert() * preNetworkComponentToJoinSize.get(entry.getKey()))
            .sum();
    final double fdelete = preNetworkComponentToData.values().stream().mapToDouble(Data::getFdelete).sum();
    // publish information to statistics provider
    {
        final Set<PathFilterList> filters = new HashSet<>();
        componentToJoinOrder.keySet().forEach(filters::addAll);
        filters.add(toRate);
        statisticsProvider.setData(filters, new Data(finsert, fdelete, rowCount, tupleSize));
    }
    final double mxBeta = m(rowCount, tuplesPerPage);
    final double runtimeCost = preNetworkComponentToData.entrySet().stream().mapToDouble(entry -> {
        final Set<PathFilterList> component = entry.getKey();
        final Data data = entry.getValue();
        return data.getFinsert()
                * costPosInsVarI(statisticsProvider, component, componentToJoinOrder.get(component),
                        componentToJoinOrder.keySet(), pathToPreNetworkComponents)
                + data.getFdelete() * (mxBeta + cardenas(mxBeta, preNetworkComponentToJoinSize.get(component)));
    }).sum();
    final double memoryCost = rowCount * tupleSize;
    return cpuAndMemCostCombiner.applyAsDouble(runtimeCost, memoryCost);
}