Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.mapdb;
  
  import org.junit.Test;
  import java.util.*;
  import static org.mapdb.Fun.*;
  import static org.junit.Assert.*;
  
  public class BindTest {
  
     BTreeMap<Integer,Stringm = DBMaker.newMemoryDB().make().getTreeMap("test");
 
     String[] split(String s){
         if(s==nullreturn null;
         String[] ret = new String[s.length()];
         for(int i=0;i<ret.length;i++)
             ret[i] = ""+s.charAt(i);
         return ret;
     }
 
     @Test public void secondary_values(){
         .put(1,"jedna");
         .put(2,"dve");
 
         Set<Tuple2<Integer,String>> sec = new TreeSet<Tuple2<IntegerString>>();
 
         Bind.secondaryValues(,sec,new Function2<String[], IntegerString>() {
             @Override
             public String[] run(Integer integerString s) {
                 return split(s);
             }
         });
 
         //filled if empty
         assertEquals(5+3,sec.size());
         assert(sec.contains(t2(2,"d")));
         assert(sec.contains(t2(2,"v")));
         assert(sec.contains(t2(2,"e")));
 
         //old values preserved
         .put(2,"dvea");
         assertEquals(5+4,sec.size());
         assert(sec.contains(t2(2,"d")));
         assert(sec.contains(t2(2,"v")));
         assert(sec.contains(t2(2,"e")));
         assert(sec.contains(t2(2,"a")));
 
         //old values deleted
         .put(2,"dva");
         assertEquals(5+3,sec.size());
         assert(sec.contains(t2(2,"d")));
         assert(sec.contains(t2(2,"v")));
         assert(sec.contains(t2(2,"a")));
 
         //all removed on delete
         .remove(2);
         assertEquals(5,sec.size());
 
         //all added on put
         .put(2,"dva");
         assertEquals(5+3,sec.size());
         assert(sec.contains(t2(2,"d")));
         assert(sec.contains(t2(2,"v")));
         assert(sec.contains(t2(2,"a")));
 
     }
 
     @Test public void secondary_keys(){
         .put(1,"jedna");
         .put(2,"dve");
 
         Set<Tuple2<String,Integer>> sec = new TreeSet<Tuple2<String,Integer>>();
 
         Bind.secondaryKeys(,sec,new Function2<String[], IntegerString>() {
             @Override
             public String[] run(Integer integerString s) {
                 return split(s);
             }
         });
 
         //filled if empty
         assertEquals(5+3,sec.size());
         assert(sec.contains(t2("d",2)));
         assert(sec.contains(t2("v",2)));
         assert(sec.contains(t2("e",2)));
 
         //old values preserved
         .put(2,"dvea");
         assertEquals(5+4,sec.size());
         assert(sec.contains(t2("d",2)));
         assert(sec.contains(t2("v",2)));
         assert(sec.contains(t2("e",2)));
         assert(sec.contains(t2("a",2)));
 
         //old values deleted
         .put(2,"dva");
         assertEquals(5+3,sec.size());
         assert(sec.contains(t2("d",2)));
         assert(sec.contains(t2("v",2)));
         assert(sec.contains(t2("a",2)));
        //all removed on delete
        .remove(2);
        assertEquals(5,sec.size());
        //all added on put
        .put(2,"dva");
        assertEquals(5+3,sec.size());
        assert(sec.contains(t2("d",2)));
        assert(sec.contains(t2("v",2)));
        assert(sec.contains(t2("a",2)));
    }
New to GrepCode? Check out our FAQ X