@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() ); }
@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() ); }
public Set<Entry<String, Object>> entrySet() { Set<Entry<String, Object>> set = new HashSet<Entry<String, Object>>(); for ( Triple t : getSchemaTriplesForSubject( getObject() ) ) { // Triple proxy = store.get( tripleFactory.newTriple( t.getValue(), TripleStore.PROXY, Variable.v ) ); // set.add( TraitProxy.buildEntry( (String) t.getValue(), proxy.getValue() ) ); Triple x = getProxyTripleByTraitType( t.getValue() ); if ( x != null ) { set.add( TraitProxy.buildEntry( (String) t.getValue(), x.getValue() ) ); } } return set; }
public Collection<Object> values() { List<Object> values = new ArrayList<Object>(); for ( Triple t : getSchemaTriplesForSubject( getObject() ) ) { Triple x = getProxyTripleByTraitType( t.getValue() ); if ( x != null ) { // values.add( store.get( tripleFactory.newTriple( t.getValue(), TripleStore.PROXY, null ) ).getValue() ); values.add( x.getValue() ); } } return values; }
public Collection<Object> values() { List<Object> values = new ArrayList<Object>(); for ( Triple t : getTriplesForSubject( getObject() ) ) { values.add( t.getValue() ); } return values; }
public Set<String> keySet() { Set<String> set = new HashSet<String>(); for ( Triple t : getSchemaTriplesForSubject( getObject() ) ) { if ( t.getProperty().equals( TripleStore.TYPE ) ) { set.add( t.getValue().toString() ); } } return set; }
public Object get(Object key) { Triple t = store.get( propertyKey( key ) ); return t == null ? null : t.getValue(); }
public Set<Entry<String, Object>> entrySet() { Set<Entry<String, Object>> set = new HashSet<Entry<String, Object>>(); for ( Triple t : getTriplesForSubject( getObject() ) ) { set.add( TraitProxy.buildEntry( (String) t.getProperty(), t.getValue() ) ); } return set; }
@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 Triple getProxyTripleByTraitType( Object key ) { Collection<Triple> candidates = store.getAll( tripleFactory.newTriple( key, TripleStore.PROXY, Variable.v ) ); for ( Triple t : candidates ) { if ( ((TraitProxy) t.getValue() ).getObject() == object ) { return t; } } return null; } }
public boolean containsValue( Object value ) { for ( Triple t : getSchemaTriplesForSubject(getObject()) ) { if (t.getProperty().equals( TripleStore.TYPE ) ) { return store.contains( tripleFactory.newTriple( t.getValue(), TripleStore.PROXY, value ) ); } } return false; }
public Object remove( Object key ) { Triple t = getProxyTripleByTraitType( key ); if ( t == null ) { return false; } store.remove( t ); store.remove( property( TripleStore.TYPE, key ) ); return t.getValue(); }
public Object get( Object key ) { Triple t = store.get( tripleFactory.newTriple( key, TripleStore.PROXY, Variable.v ) ); while ( t != null ) { Object o = t.getValue(); if ( o instanceof TraitProxy && (( TraitProxy ) o ).getObject() == this.object ) { return o; } else { t = (Triple) t.getNext(); } } return null; }
public boolean remove(final Triple triple) { final int hashCode = this.comparator.hashCodeOf( triple ); final int index = indexOf( hashCode, this.table.length ); TripleImpl previous = (TripleImpl) this.table[index]; TripleImpl current = previous; Triple key = new TripleImpl( triple.getInstance(), triple.getProperty(), Variable.v ); while ( current != null ) { final TripleImpl next = (TripleImpl) current.getNext(); if ( hashCode == this.comparator.hashCodeOf( current ) && this.comparator.equal( key, current ) ) { if ( ( current.getValue() == null && triple.getValue() == null ) || ( current.getValue() != null && current.getValue().equals( triple.getValue() ) ) ) { if ( previous == current ) { this.table[index] = next; } else { previous.setNext( next ); } current.setNext( null ); this.size--; return true; } } previous = current; current = next; } return false; }
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; }