com.maxifier.mxcache.impl.caches.batch.ListValueStrategy Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
*/
package com.maxifier.mxcache.impl.caches.batch;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
/**
* @author Alexander Kochurov ([email protected])
*/
final class ListValueStrategy implements ValueStrategy, V, BitSet> {
private ListValueStrategy() {}
private static final ListValueStrategy INSTANCE = new ListValueStrategy();
public static ListValueStrategy getInstance() {
//noinspection unchecked
return INSTANCE;
}
@Override
public List compose(List knownValue, List calculated, BitSet composition) {
for (int i = composition.nextSetBit(0), p = 0; i >= 0; i = composition.nextSetBit(i+1), p++) {
knownValue.set(i, calculated.get(p));
}
return knownValue;
}
@Override
public List createValue(Class> valueType, int n) {
return new ArrayList(n);
}
@Override
public BitSet createComposer(int n) {
return new BitSet(n);
}
@Override
public void addUnknown(List knownValues, BitSet composer, int i, K k) {
composer.set(i);
//noinspection unchecked
knownValues.add(null);
}
@Override
public void addKnown(List knownValues, BitSet composer, int i, K k, V v) {
knownValues.add(v);
}
@Override
public V get(List value, int index, K key) {
return value.get(index);
}
@Override
public boolean requiresOrder() {
return true;
}
}