make IdentityExtractionFn singleton

This commit is contained in:
Himanshu Gupta 2016-01-06 22:29:07 -06:00
parent dd262f0451
commit 217079d0c7
5 changed files with 18 additions and 9 deletions

View File

@ -24,6 +24,14 @@ import com.google.common.base.Strings;
public class IdentityExtractionFn implements ExtractionFn
{
private static final byte CACHE_TYPE_ID = 0x6;
private static final IdentityExtractionFn instance = new IdentityExtractionFn();
private IdentityExtractionFn()
{
}
@Override
public byte[] getCacheKey()
{
@ -71,4 +79,9 @@ public class IdentityExtractionFn implements ExtractionFn
{
return o != null && o instanceof IdentityExtractionFn;
}
public static final IdentityExtractionFn getInstance()
{
return instance;
}
}

View File

@ -48,11 +48,7 @@ public class DimensionSelectorHavingSpec implements HavingSpec
{
dimension = Preconditions.checkNotNull(dimName, "Must have attribute 'dimension'");
this.value = value;
if (extractionFn != null) {
this.extractionFn = extractionFn;
} else {
this.extractionFn = new IdentityExtractionFn();
}
this.extractionFn = extractionFn != null ? extractionFn : IdentityExtractionFn.getInstance();
}
@JsonProperty("value")

View File

@ -121,7 +121,7 @@ public class SearchQueryRunner implements QueryRunner<Result<SearchResultValue>>
final BitmapIndex bitmapIndex = column.getBitmapIndex();
ExtractionFn extractionFn = dimension.getExtractionFn();
if (extractionFn == null) {
extractionFn = new IdentityExtractionFn();
extractionFn = IdentityExtractionFn.getInstance();
}
if (bitmapIndex != null) {
for (int i = 0; i < bitmapIndex.getCardinality(); ++i) {

View File

@ -35,13 +35,13 @@ public class ExtractionDimFilterTest
ExtractionDimFilter extractionDimFilter = new ExtractionDimFilter(
"abc",
"d",
new IdentityExtractionFn(),
IdentityExtractionFn.getInstance(),
null
);
ExtractionDimFilter extractionDimFilter2 = new ExtractionDimFilter(
"ab",
"cd",
new IdentityExtractionFn(),
IdentityExtractionFn.getInstance(),
null
);

View File

@ -162,7 +162,7 @@ public class DimensionSelectorHavingSpecTest
@Test
public void testGetCacheKey()
{
ExtractionFn extractionFn = new IdentityExtractionFn();
ExtractionFn extractionFn = IdentityExtractionFn.getInstance();
byte[] dimBytes = "dimension".getBytes(Charsets.UTF_8);
byte[] valBytes = "v".getBytes(Charsets.UTF_8);
byte[] extFunKey = extractionFn.getCacheKey();