Triple t2 = ( Triple ) object2; if ( t1.getInstance() != Variable.v ) { if ( t1.getInstance() == null ) { return false; } else if ( t1.getInstance() instanceof String ) { if ( ! t1.getInstance().equals( t2.getInstance() ) ) { return false; } else if ( t1.getInstance() != t2.getInstance() ) { return false; if ( t1.getProperty() != Variable.v && ! t1.getProperty().equals( t2.getProperty() ) ) { return false; if ( t1.getValue() != Variable.v ) { if ( t1.getValue() == null ) { return t2.getValue() == null; } else { return t1.getValue().equals( t2.getValue() );
public int hashCodeOf(Object object) { Triple t = ( Triple ) object; final int prime = 31; int result = 1; result = prime * result + t.getInstance().hashCode(); result = prime * result + t.getProperty().hashCode(); return result; }
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( 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 Collection<Triple> getAll(final Triple triple) { List<Triple> list = new ArrayList<Triple>(); if ( triple.getInstance() != Variable.v && triple.getProperty() != Variable.v ) { Triple t = get( triple ); if ( t != null ) { list.add( current ); current = (Triple) current.getNext();
protected Collection<Triple> getTriplesForSubject( Object subj ) { Collection<Triple> coll = store.getAll( tripleFactory.newTriple( subj, Variable.v, Variable.v ) ); Iterator<Triple> iter = coll.iterator(); while ( iter.hasNext() ) { if ( (iter.next().getProperty()).equals(TripleStore.TYPE) ) { iter.remove(); } } return coll; }
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; }
public Set<String> keySet() { Set<String> set = new HashSet<String>(); for ( Triple t : getTriplesForSubject( getObject() ) ) { set.add( (String) t.getProperty() ); } return set; }
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 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; }
@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 Object get(Object key) { Triple t = store.get( propertyKey( key ) ); return t == null ? null : t.getValue(); }