Package java.util

Examples of java.util.SortedMap


    public Map makeEmptyMap() {
        return FixedSizeSortedMap.decorate(new TreeMap());
    }

    public Map makeFullMap() {
        SortedMap map = new TreeMap();
        addSampleMappings(map);
        return FixedSizeSortedMap.decorate(map);
    }
View Full Code Here


     * @param text the text.
     * @return a <code>TermPositionVector</code> for the given text.
     */
    private TermPositionVector createTermPositionVector(String text) {
        // term -> TermVectorOffsetInfo[]
        final SortedMap termMap = new TreeMap();
        Reader r = new StringReader(text);
        TokenStream ts = index.getTextAnalyzer().tokenStream("", r);
        Token t = new Token();
        try {
            while ((t = ts.next(t)) != null) {
                String termText = t.term();
                TermVectorOffsetInfo[] info =
                        (TermVectorOffsetInfo[]) termMap.get(termText);
                if (info == null) {
                    info = new TermVectorOffsetInfo[1];
                } else {
                    TermVectorOffsetInfo[] tmp = info;
                    info = new TermVectorOffsetInfo[tmp.length + 1];
                    System.arraycopy(tmp, 0, info, 0, tmp.length);
                }
                info[info.length - 1] = new TermVectorOffsetInfo(
                        t.startOffset(), t.endOffset());
                termMap.put(termText, info);
            }
        } catch (IOException e) {
            // should never happen, we are reading from a string
        }

        return new TermPositionVector() {

            private String[] terms =
                    (String[]) termMap.keySet().toArray(new String[termMap.size()]);

            public int[] getTermPositions(int index) {
                return null;
            }

            public TermVectorOffsetInfo[] getOffsets(int index) {
                TermVectorOffsetInfo[] info = TermVectorOffsetInfo.EMPTY_OFFSET_INFO;
                if (index >= 0 && index < terms.length) {
                    info = (TermVectorOffsetInfo[]) termMap.get(terms[index]);
                }
                return info;
            }

            public String getField() {
                return "";
            }

            public int size() {
                return terms.length;
            }

            public String[] getTerms() {
                return terms;
            }

            public int[] getTermFrequencies() {
                int[] freqs = new int[terms.length];
                for (int i = 0; i < terms.length; i++) {
                    freqs[i] = ((TermVectorOffsetInfo[]) termMap.get(terms[i])).length;
                }
                return freqs;
            }

            public int indexOf(String term) {
View Full Code Here

    }

    // from TestPredicatedMap
    //-----------------------------------------------------------------------
    public void testEntrySet() {
        SortedMap map = makeTestSortedMap();
        assertTrue("returned entryset should not be null",
            map.entrySet() != null);
        map = decorateMap(new TreeMap(), null, null);
        map.put("oneKey", "oneValue");
        assertTrue("returned entryset should contain one entry",
            map.entrySet().size() == 1);
        map = decorateMap(map, null, null);
    }
View Full Code Here

       
    }

    //-----------------------------------------------------------------------
    public void testSortOrder() {
        SortedMap map = makeTestSortedMap();
        map.put("A""a");
        map.put("B", "b");
        try {
            map.put(null, "c");
            fail("Null key should raise IllegalArgument");
        } catch (IllegalArgumentException e) {
            // expected
        }
        map.put("C", "c");
        try {
            map.put("D", null);
            fail("Null value should raise IllegalArgument");
        } catch (IllegalArgumentException e) {
            // expected
        }
        assertEquals("First key should be A", map.firstKey(), "A");
        assertEquals("Last key should be C", map.lastKey(), "C");
        assertEquals("First key in tail map should be B",
            map.tailMap("B").firstKey(), "B");
        assertEquals("Last key in head map should be B",
            map.headMap("C").lastKey(), "B");
        assertEquals("Last key in submap should be B",
           map.subMap("A","C").lastKey(), "B");
       
        Comparator c = map.comparator();
        assertTrue("natural order, so comparator should be null",
            c == null);
    }
View Full Code Here

        static final int SUBSIZE = 6;
        final Object toKey;
       
        public TestHeadMap(AbstractTestMap main) {
            super("SortedMap.HeadMap", main);
            SortedMap sm = (SortedMap) main.makeFullMap();
            for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
                Map.Entry entry = (Map.Entry) it.next();
                this.subSortedKeys.add(entry.getKey());
                this.subSortedValues.add(entry.getValue());
            }
            this.toKey = this.subSortedKeys.get(SUBSIZE);
View Full Code Here

        final Object fromKey;
        final Object invalidKey;
       
        public TestTailMap(AbstractTestMap main) {
            super("SortedMap.TailMap", main);
            SortedMap sm = (SortedMap) main.makeFullMap();
            for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
                Map.Entry entry = (Map.Entry) it.next();
                this.subSortedKeys.add(entry.getKey());
                this.subSortedValues.add(entry.getValue());
            }
            this.fromKey = this.subSortedKeys.get(this.subSortedKeys.size() - SUBSIZE);
View Full Code Here

        final Object fromKey;
        final Object toKey;
       
        public TestSubMap(AbstractTestMap main) {
            super("SortedMap.SubMap", main);
            SortedMap sm = (SortedMap) main.makeFullMap();
            for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
                Map.Entry entry = (Map.Entry) it.next();
                this.subSortedKeys.add(entry.getKey());
                this.subSortedValues.add(entry.getValue());
            }
            this.fromKey = this.subSortedKeys.get(SUBSIZE);
View Full Code Here

        return new TreeMap();
    }

    //-----------------------------------------------------------------------
    public void testComparator() {
        SortedMap sm = (SortedMap) makeFullMap();
        // no tests I can think of
    }
View Full Code Here

        SortedMap sm = (SortedMap) makeFullMap();
        // no tests I can think of
    }
   
    public void testFirstKey() {
        SortedMap sm = (SortedMap) makeFullMap();
        assertSame(sm.keySet().iterator().next(), sm.firstKey());
    }
View Full Code Here

        SortedMap sm = (SortedMap) makeFullMap();
        assertSame(sm.keySet().iterator().next(), sm.firstKey());
    }
   
    public void testLastKey() {
        SortedMap sm = (SortedMap) makeFullMap();
        Object obj = null;
        for (Iterator it = sm.keySet().iterator(); it.hasNext();) {
            obj = (Object) it.next();
        }
        assertSame(obj, sm.lastKey());
    }
View Full Code Here

TOP

Related Classes of java.util.SortedMap

Copyright © 2018 www.massapicom. 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.