Skip to content

Commit 41ac4af

Browse files
committed
Make RefPropertyMap able to create values
1 parent 7f40fc3 commit 41ac4af

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

src/main/java/org/mastodon/properties/RefPropertyMap.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
package org.mastodon.properties;
3030

31+
import java.util.function.Function;
32+
3133
import org.mastodon.RefPool;
3234
import org.mastodon.collection.RefCollection;
3335
import org.mastodon.collection.RefMaps;
@@ -43,16 +45,18 @@ public class RefPropertyMap< O, T > extends AbstractPropertyMap< O, T >
4345
{
4446
private final RefRefMap< O, T > map;
4547

46-
public RefPropertyMap( final RefCollection< O > keyPool, final RefCollection< T > valuePool )
47-
{
48-
map = RefMaps.createRefRefMap( keyPool, valuePool );
49-
tryRegisterPropertyMap( keyPool );
50-
}
48+
private final Function< T, T > createValue;
5149

52-
public RefPropertyMap( final RefPool< O > keyPool, final RefPool< T > valuePool )
50+
public RefPropertyMap( final RefPool< O > keyPool,
51+
final RefPool< T > valuePool,
52+
final Function< T, T > createValue )
5353
{
54+
// TODO: For performance we might want to implement a
55+
// RefRefArrayMap (similar to IntRefArrayMap),
56+
// instead of the RefRefHashMap used currently.
5457
map = new RefRefHashMap<>( keyPool, valuePool );
5558
tryRegisterPropertyMap( keyPool );
59+
this.createValue = createValue;
5660
}
5761

5862
@Override
@@ -101,6 +105,26 @@ public RefRefMap< O, T > getMap()
101105
return map;
102106
}
103107

108+
public T createValueRef()
109+
{
110+
return map.createValueRef();
111+
}
112+
113+
public void releaseValueRef( T ref )
114+
{
115+
map.releaseValueRef( ref );
116+
}
117+
118+
public T createValue( T ref )
119+
{
120+
return createValue.apply( ref );
121+
}
122+
123+
public T createValue()
124+
{
125+
return createValue( createValueRef() );
126+
}
127+
104128
public void release()
105129
{
106130
map.clear();

0 commit comments

Comments
 (0)