ObjectHashMap extends AbstractHashTable implements Externalizable { public Object get(final Object key) { final int hashCode = this.comparator.hashCodeOf( key ); final int index = indexOf( hashCode, this.table.length ); ObjectEntry current = (ObjectEntry) this.table[index]; while ( current != null ) { if ( hashCode == current.cachedHashCode && this.comparator.areEqual(key, current.key ) ) { return current.value; } current = (ObjectEntry) current.getNext(); } return null; } ObjectHashMap();  ObjectHashMap(final int capacity,
                         final float loadFactor);  ObjectHashMap(final Entry[] table);  ObjectHashMap(final float loadFactor,
                         final Entry[] table); Object put(final Object key,
                      final Object value); Object put(final Object key,
                      final Object value,
                      final boolean checkExists); Object get(final Object key); Object remove(final Object key); Entry getBucket(final Object object); @Override int getResizeHashcode(Entry entry);  }
@Test public void testEqualityWithResize() { KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption( EqualityBehaviorOption.EQUALITY ); KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf); KieSession ksession = kbase.newKieSession(); int length = 1 * 300 * 1000 ; List<FactHandle> handles = new ArrayList<FactHandle>(1000); List<String> objects = new ArrayList<String>(1000); for ( int i = 0; i < length; i++) { String s = getPropertyName(i); FactHandle handle = ksession.insert( s ); objects.add( s ); handles.add( handle ); } for ( int i = 0; i < length; i++) { String s = objects.get(i); FactHandle handle = handles.get( i ); assertEquals( s, ksession.getObject( handle ) ); assertSame( handle, ksession.getFactHandle( s ) ); handle = DefaultFactHandle.createFromExternalFormat(((DefaultFactHandle)handle).toExternalForm()); assertEquals( s, ksession.getObject( handle ) ); } for ( int i = 0; i < length; i++) { FactHandle handle = handles.get( i ); handle = DefaultFactHandle.createFromExternalFormat(((DefaultFactHandle)handle).toExternalForm()); ksession.retract( handle ); assertEquals( length - i -1, ksession.getObjects().size() ); assertEquals( length - i -1, ksession.getFactHandles().size() ); } assertEquals( 0, ksession.getObjects().size() ); assertEquals( 0, ksession.getFactHandles().size() ); }
@Test public void testIdentityWithResize() { KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption( EqualityBehaviorOption.IDENTITY ); KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf); KieSession ksession = kbase.newKieSession(); int length = 1 * 300 * 1000 ; List<FactHandle> handles = new ArrayList<FactHandle>(1000); List<String> objects = new ArrayList<String>(1000); for ( int i = 0; i < length; i++) { String s = getPropertyName(i); FactHandle handle = ksession.insert( s ); objects.add( s ); handles.add( handle ); } for ( int i = 0; i < length; i++) { String s = objects.get(i); FactHandle handle = handles.get( i ); assertEquals( s, ksession.getObject( handle ) ); assertSame( handle, ksession.getFactHandle( s ) ); handle = DefaultFactHandle.createFromExternalFormat(((DefaultFactHandle)handle).toExternalForm()); assertEquals( s, ksession.getObject( handle ) ); } for ( int i = 0; i < length; i++) { FactHandle handle = handles.get( i ); handle = DefaultFactHandle.createFromExternalFormat(((DefaultFactHandle)handle).toExternalForm()); ksession.retract( handle ); assertEquals( length - i -1, ksession.getObjects().size() ); assertEquals( length - i -1, ksession.getFactHandles().size() ); } assertEquals( 0, ksession.getObjects().size() ); assertEquals( 0, ksession.getFactHandles().size() ); }