Examples of comparator()


Examples of java.util.TreeMap.comparator()

        TreeMap reversedTreeMap = new TreeMap(comp);
        reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
        reversedTreeMap.put(new Integer(2).toString(), new Integer(2));
        TreeMap anotherTreeMap = new TreeMap(reversedTreeMap);
        assertTrue("New tree map does not answer correct comparator",
                anotherTreeMap.comparator() == comp);
        assertTrue("TreeMap does not use comparator (firstKey was incorrect)",
                anotherTreeMap.firstKey().equals(new Integer(2).toString()));
        assertTrue("TreeMap does not use comparator (lastKey was incorrect)",
                anotherTreeMap.lastKey().equals(new Integer(1).toString()));
View Full Code Here

Examples of java.util.TreeMap.comparator()

     */
    public void test_comparator() {
        // Test for method java.util.Comparator java.util.TreeMap.comparator()\
        Comparator comp = new ReversedComparator();
        TreeMap reversedTreeMap = new TreeMap(comp);
        assertTrue("TreeMap answered incorrect comparator", reversedTreeMap
                .comparator() == comp);
        reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
        reversedTreeMap.put(new Integer(2).toString(), new Integer(2));
        assertTrue("TreeMap does not use comparator (firstKey was incorrect)",
                reversedTreeMap.firstKey().equals(new Integer(2).toString()));
View Full Code Here

Examples of java.util.TreeMap.comparator()

  }

  static public class TreeMapSerializer extends MapSerializer {
    public void write (Kryo kryo, Output output, Map map) {
      TreeMap treeMap = (TreeMap)map;
      kryo.writeClassAndObject(output, treeMap.comparator());
      super.write(kryo, output, map);
    }

    protected Map create (Kryo kryo, Input input, Class<Map> type) {
      return new TreeMap((Comparator)kryo.readClassAndObject(input));
View Full Code Here

Examples of java.util.TreeMap.comparator()

            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
                TreeMap tm = (TreeMap) super.unmarshal(reader,context);
                return new Tree(tm,tm.comparator());
            }

            @Override
            public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
                super.marshal(((Tree)source).core,writer,context);
View Full Code Here

Examples of java.util.TreeMap.comparator()

                "    <string>walnes</string>\n" +
                "  </entry>\n" +
                "</tree-map>";

        TreeMap result = (TreeMap) assertBothWays(map, expected);
        assertEquals(MyComparator.class, result.comparator().getClass());
    }

    public void testTreeMapWithoutComparator() {
        TreeMap map = new TreeMap();
        map.put("benny", "hill");
View Full Code Here

Examples of java.util.TreeMap.comparator()

                "    <string>walnes</string>\n" +
                "  </entry>\n" +
                "</tree-map>";

        TreeMap result = (TreeMap) assertBothWays(map, expected);
        assertNull(result.comparator());
    }

    public void testEmptyTreeMap() {
        TreeMap map = new TreeMap();
View Full Code Here

Examples of java.util.TreeMap.comparator()

    public void testEmptyTreeMap() {
        TreeMap map = new TreeMap();

        String expected = "<tree-map/>";
        TreeMap result = (TreeMap) assertBothWays(map, expected);
        assertNull(result.comparator());
    }

    public void testTreeMapDoesNotUseComparatorAtDeserialization() {
        TreeMap map = new TreeMap(new UnusedComparator());
        map.put("john", "doe");
View Full Code Here

Examples of java.util.TreeMap.comparator()

                "  </entry>\n" +
                "</tree-map>";

        assertEquals(expected, xstream.toXML(map));
        TreeMap result = (TreeMap) xstream.fromXML(expected);
        assertSame(UnusedComparator.THROWING_COMPARATOR, result.comparator());
        assertEquals(new ArrayList(map.entrySet()), new ArrayList(result.entrySet()));
    }

    public void testTreeSetWithComparator() {
        TreeSet set = new TreeSet(new MyComparator());
View Full Code Here

Examples of java.util.TreeMap.comparator()

        Map orig = (Map) _mgr.newMapProxy(HashMap.class, null, null, null, true);
        populate(orig);
        assertMapsEqual(new HashMap(orig), (Map) _mgr.copyMap(orig));

        TreeMap torig = (TreeMap) _mgr.newMapProxy(TreeMap.class, null, null, new CustomComparator(), true);
        assertTrue(torig.comparator() instanceof CustomComparator);
        populate(torig);
        assertSortedMapsEqual(new TreeMap(torig), (SortedMap) _mgr.copyMap(torig));
    }

    public void testCloneProxyMap() {
View Full Code Here

Examples of java.util.TreeMap.comparator()

    public void testCloneProxyMap() {
        // Map does not support clone()

        TreeMap torig = (TreeMap) _mgr.newMapProxy(TreeMap.class, null, null, new CustomComparator(), true);
        assertTrue(torig.comparator() instanceof CustomComparator);
        populate(torig);
        assertSortedMapsEquals(new TreeMap(torig), (SortedMap) torig.clone());
    }

    public void testMapMethodsProxied() throws Exception {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.