All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.maxifier.mxcache.impl.caches.batch.ArrayValueStrategy Maven / Gradle / Ivy

Go to download

Constains all classes necessary for launching a MxCache-instrumentated application

There is a newer version: 2.6.9
Show newest version
/*
 * Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
 */
package com.maxifier.mxcache.impl.caches.batch;

import java.lang.reflect.Array;
import java.util.BitSet;

/**
 * @author Alexander Kochurov ([email protected])
 */
final class ArrayValueStrategy implements ValueStrategy {
    private ArrayValueStrategy() {}

    private static final ArrayValueStrategy INSTANCE = new ArrayValueStrategy();

    public static  ArrayValueStrategy getInstance() {
        //noinspection unchecked
        return INSTANCE;
    }

    @SuppressWarnings("MismatchedReadAndWriteOfArray")
    @Override
    public V[] compose(V[] knownValue, V[] calculated, BitSet composition) {
        for (int i = composition.nextSetBit(0), p = 0; i >= 0; i = composition.nextSetBit(i+1), p++) {
            knownValue[i] = calculated[p];
        }
        return knownValue;
    }

    @Override
    public V[] createValue(Class valueType, int n) {
        //noinspection unchecked
        return (V[]) Array.newInstance(valueType.getComponentType(), n);
    }

    @Override
    public BitSet createComposer(int n) {
        return new BitSet(n);
    }

    @Override
    public void addUnknown(V[] knownValues, BitSet composer, int i, K k) {
        composer.set(i);
    }

    @Override
    public void addKnown(V[] knownValues, BitSet composer, int i, K k, V v) {
        knownValues[i] = v;
    }

    @Override
    public V get(V[] value, int index, K key) {
        return value[index];
    }

    @Override
    public boolean requiresOrder() {
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy