Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 Cees De Groot, Alex Boisvert, Jan Kotek Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 package org.mapdb;
 public class LongHashMapTest extends TestCase {
     public void testAll() {
         LongHashMap<Stringt = new LongHashMap<String>(){
             @Override protected long hashSaltValue(){return 0;}
         t.put(1, "aa");
         t.put(2, "bb");
         t.put(2, "bb");
         t.put(4, "cc");
         t.put(9, "FF");
         assertEquals(4, t.size());
         assertEquals(3, t.size());
         assertEquals(t.get(1), null);
         assertEquals(t.get(2), "bb");
         assertEquals(t.get(3), null);
         assertEquals(t.get(4), "cc");
         assertEquals(t.get(5), null);
         assertEquals(t.get(-1), null);
         assertEquals(t.get(9), "FF");
         Iterator<Stringvals = t.valuesIterator();
         assertEquals(, "bb");
         assertEquals(, "cc");
         assertEquals(, "FF");
         assertEquals(0, t.size());
         t.put(2, "bb");
         assertEquals(1, t.size());
         assertEquals(t.get(1), null);
         assertEquals(t.get(3), null);
     public void testRandomCompare() {
         LongHashMap<Stringv1 = new LongHashMap<String>();
         TreeMap<LongStringv2 = new TreeMap<LongString>();
         Random d = new Random();
         for (int i = 0; i < 1000; i++) {
             long key = d.nextInt() % 100;
             double random = d.nextDouble();
             if (random < 0.8) {
 //				System.out.println("put "+key);
                 v1.put(key"" + key);
                 v2.put(key"" + key);
             } else {
 //				System.out.println("remove "+key);
     public void checkEquals(LongMap<Stringv1TreeMap<LongStringv2) {
         assertEquals(v1.size(), v2.size());
         for (long k : v2.keySet()) {
             assertEquals(v1.get(k), v2.get(k));
         int counter = 0;
         Iterator<Stringit = v1.valuesIterator();
         while (it.hasNext()) {
             String v =;
             long key = Long.parseLong(v);
             assertEquals(v1.get(key), v);
             assertEquals("" + keyv);
    public void test2() {
        LongHashMap<Stringv1 = new LongHashMap<String>();
        v1.put(1611, "1611");
        v1.put(15500, "15500");
        v1.put(9446, "9446");
        assertEquals(3, v1.size());
        assertEquals(v1.get(9446), "9446");
    public void testMapIter(){
        LongHashMap<Stringv = new LongHashMap<String>();
        v.put(1L, "one");
        v.put(2L, "two");
        v.put(3L, "three");
        TreeMap<LongStringv2 = new TreeMap<LongString>();
        v2.put(1L, "one");
        v2.put(2L, "two");
        v2.put(3L, "three");
        TreeMap<LongStringv3 = new TreeMap<LongString>();
        LongMap.LongMapIterator<Stringiter = v.longMapIterator();
            v3.put(iter.key(), iter.value());
    public void test_Issue6(){
            LongHashMap<Stringt = new LongHashMap<String>();
            t.put(6447459, "aa");
            t.put(6382177, "bb");
            assertTrue(t.toString().contains("6382177 => bb"));
            assertTrue(t.toString().contains("6447459 => aa"));
New to GrepCode? Check out our FAQ X