@Test public void testAddNary() { TripleStore store = new TripleStore(200, 0.6f ); Individual ind = new Individual(); assertFalse( store.put( t1 ) ); assertTrue(store.put(t2)); store.add(t3); store.add( t4 ); store.add(t5); store.add( t6 ); coll = store.getAll(tKey); assertTrue( coll.containsAll( Arrays.asList( new TripleImpl(ind, "hasName", "oscar"), new TripleImpl(ind, "hasName", "mark"), new TripleImpl(ind, "hasName", "daniel") ) ) ); assertFalse( store.contains( new TripleImpl(ind, "hasName", "marc") ) ); assertTrue( store.contains( new TripleImpl(ind, "hasName", "mark") ) ); assertTrue( store.contains( new TripleImpl(ind, "hasName", "daniel") ) ); assertTrue( store.contains( new TripleImpl(ind, "hasCar", "mini") ) ); assertTrue( store.contains( new TripleImpl(ind, "hasName", "oscar") ) ); assertTrue( store.contains( new TripleImpl(ind, "hasCar", "ferrari") ) ); assertTrue( store.contains( new TripleImpl(ind, "hasName", "oscar") ) );
@Test public void testPutAndGetandRemove() { // We know it needs to hold a lot of triples, so instantiate it with huge capacity. // A lower capacity ensures a larger capacity per number of triples, i.e. less collision - default is 0.75f TripleStore store = new TripleStore(10*100*1000, 0.6f ); Individual ind = new Individual(); Triple t = new TripleImpl(ind, "hasName", "mark"); assertFalse( store.put( t ) ); Triple tKey = new TripleImpl(ind, "hasName", V ); t = store.get( tKey ); assertEquals("mark", t.getValue() ); t = new TripleImpl(ind, "hasName", V ); assertEquals( 1, store.removeAll( t ) ); assertFalse( store.remove( t ) ); // try again and make sure it's false. tKey = new TripleImpl(ind, "hasName", V ); assertNull( store.get( tKey ) ); }
public TripleBasedTypes( Object obj, TripleStore store, TripleFactory factory ) { super(); this.store = store; this.storeId = store.getId(); this.object = obj; this.tripleFactory = factory; }
public StudentProxyWrapper3( Imp2 object, TripleStore store ) { this.object = object; this.store = store; if ( ! this.store.contains( propertyKey("age") ) ) { this.store.put( property( "age", 0) ); } this.store.put( property( "xcsvf" , 0.0 ) ); this.store.put( property( "name" , null ) ); this.store.put( property( "csdfsd", 0L ) ); this.store.put( property( "school" , null ) ); }
@Test public void testPutAndGet() { // We know it needs to hold a lot of triples, so instantiate it with huge capacity. // A lower capacity ensures a larger capacity per number of triples, i.e. less collision - default is 0.75f TripleStore store = new TripleStore(10*100*1000, 0.6f ); Individual ind = new Individual(); Triple t = new TripleImpl(ind, "hasName", "mark"); assertFalse( store.put( t ) ); Triple tKey = new TripleImpl(ind, "hasName", V ); t = store.get( tKey ); assertEquals("mark", t.getValue() ); }
@Test public void testQueryVariable() { TripleStore store = new TripleStore(10*100*1000, 0.6f ); Individual ind = new Individual(); assertFalse( store.put( t1 ) ); assertFalse( store.put( t2 ) ); assertFalse( store.put( t3 ) ); assertFalse( store.put( t4 ) ); assertFalse( store.put( t5 ) ); assertFalse( store.put( t6 ) ); t = store.get( tKey ); assertEquals("mark", t.getValue() ); t = store.get( tKey ); assertEquals("bologna", t.getValue() ); t = store.get( tKey ); assertNull(t); t = store.get( tKey ); assertEquals("lancia", t.getValue()); coll = store.getAll(tKey);
@Test public void testMassAddRemove() { TripleStore store = new TripleStore( ); int instanceLength = 1 * 1000 * 30; int tripleLength = 70; Triple t = null; List<Individual> inds = new ArrayList<Individual>(instanceLength); for ( int i = 0; i < instanceLength; i++) { Individual ind = new Individual(); inds.add( ind ); for (int j = 0; j < tripleLength; j++) { t = new TripleImpl(ind, getPropertyName(j), i*j); assertFalse( store.put( t ) ); } } assertEquals( instanceLength * tripleLength, store.size() ); for ( int i = 0; i < instanceLength; i++) { for (int j = 0; j < tripleLength; j++) { t = new TripleImpl(inds.get( i ),getPropertyName(j), V ); store.removeAll( t ); } } assertEquals( 0, store.size() ); }
public Integer getAgeI() { Triple t = map.get( propertyKey( "age" ) ); if ( t == null || t.getValue() == null ) { return null; } return (Integer) t.getValue(); }
public void setAge(int age) { map.put( property( "age", Integer.valueOf( age ) ) ); }
public boolean containsKey(Object key) { return store.contains( property( TripleStore.TYPE, key ) ); }
private Collection<Triple> getSchemaTriplesForSubject( Object subj ) { return store.getAll( tripleFactory.newTriple( subj, TripleStore.TYPE, Variable.v ) ); }
public void setDefaultTripleStore() { tripleStore = new TripleStore(); }
public boolean put(final Triple triple, final boolean checkExists) { final int hashCode = this.comparator.hashCodeOf( triple ); final int index = indexOf( hashCode, this.table.length ); // scan the linked entries to see if it exists if ( checkExists ) { Object val = triple.getValue(); ((TripleImpl) triple).setValue( Variable.v ); TripleImpl current = (TripleImpl) this.table[index]; while ( current != null ) { if ( hashCode == this.comparator.hashCodeOf( current ) && this.comparator.equal( triple, current ) ) { current.setValue( val ); return true; } current = (TripleImpl) current.getNext(); } ((TripleImpl) triple).setValue( val ); } // We aren't checking the key exists, or it didn't find the key TripleImpl timpl = ( TripleImpl ) triple; timpl.setNext( this.table[index] ); this.table[index] = timpl; if ( this.size++ >= this.threshold ) { resize( 2 * this.table.length ); } return false; }
@Override public Entry getBucket(Object object) { final int hashCode = this.comparator.hashCodeOf( object ); final int index = indexOf( hashCode, this.table.length ); return this.table[index]; }
@Test public void testPutAndGetWithExisting() { // We know it needs to hold a lot of triples, so instantiate it with huge capacity. // A lower capacity ensures a larger capacity per number of triples, i.e. less collision - default is 0.75f TripleStore store = new TripleStore(10*100*1000, 0.6f ); Individual ind = new Individual(); Triple t = new TripleImpl(ind, "hasName", "mark"); assertFalse( store.put( t ) ); Triple tKey = new TripleImpl(ind, "hasName", V ); t = store.get( tKey ); assertEquals("mark", t.getValue() ); t = new TripleImpl(ind, "hasName", "davide"); assertTrue( store.put( t ) ); tKey = new TripleImpl(ind, "hasName", V ); t = store.get( tKey ); assertEquals("davide", t.getValue() ); }