com.carrotsearch.hppcrt.AbstractFloatCollection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hppcrt Show documentation
Show all versions of hppcrt Show documentation
High Performance Primitive Collections Realtime
(fork of HPPC from Carrotsearch)
Fundamental data structures (maps, sets, lists, queues, heaps, sorts) generated for
combinations of object and primitive types to conserve JVM memory and speed
up execution. The Realtime fork intends to extend the existing collections, by tweaking to remove any dynamic allocations at runtime,
and to obtain low variance execution times whatever the input nature.
package com.carrotsearch.hppcrt;
import java.util.Arrays;
import com.carrotsearch.hppcrt.cursors.FloatCursor;
import com.carrotsearch.hppcrt.predicates.FloatPredicate;
/**
* Common superclass for collections.
*/
@javax.annotation.Generated(date = "2014-10-25T20:54:13+0200", value = "HPPC-RT generated from: AbstractFloatCollection.java")
public abstract class AbstractFloatCollection implements FloatCollection
{
protected FloatContainer testContainer;
protected FloatPredicate testPredicate;
protected float defaultValue = (0f);
protected FloatPredicate containsTestPredicate = new FloatPredicate() {
@Override
public final boolean apply(final float k)
{
return AbstractFloatCollection.this.testContainer.contains(k);
}
};
protected FloatPredicate containsNegateTestPredicate = new FloatPredicate() {
@Override
public final boolean apply(final float k)
{
return !AbstractFloatCollection.this.testContainer.contains(k);
}
};
protected FloatPredicate negatePredicate = new FloatPredicate() {
@Override
public final boolean apply(final float k)
{
return !AbstractFloatCollection.this.testPredicate.apply(k);
}
};
/**
* Default implementation uses a predicate for removal.
*/
/* */
@Override
public int removeAll(final FloatLookupContainer c)
{
// We know c holds sub-types of float and we're not modifying c, so go unchecked.
this.testContainer = (FloatContainer) c;
return this.removeAll(this.containsTestPredicate);
}
/**
* {@inheritDoc}
*/
/* */
@Override
public int retainAll(final FloatLookupContainer c)
{
// We know c holds sub-types of float and we're not modifying c, so go unchecked.
this.testContainer = (FloatContainer) c;
return this.removeAll(this.containsNegateTestPredicate);
}
/**
* {@inheritDoc}
*/
@Override
public int retainAll(final FloatPredicate predicate)
{
this.testPredicate = predicate;
return this.removeAll(this.negatePredicate);
}
/**
* Default implementation for:
* {@inheritDoc}
*/
@Override
public float[] toArray(final float[] target)
{
assert target.length >= size() : "Target array must be >= " + size();
int i = 0;
//use default iterator capability
for (final FloatCursor c : this)
{
target[i++] = c.value;
}
return target;
}
/**
* {@inheritDoc}
*/
@Override
public float [] toArray()
{
return toArray(new float [size()]);
}
/**
* Convert the contents of this container to a human-friendly string.
*/
@Override
public String toString()
{
return Arrays.toString(this.toArray());
}
@Override
public boolean isEmpty()
{
return size() == 0;
}
/**
* Returns the "default value" value used
* in containers methods returning "default value"
* @return
*/
public float getDefaultValue()
{
return this.defaultValue;
}
/**
* Set the "default value" value to be used
* in containers methods returning "default value"
* @return
*/
public void setDefaultValue(final float defaultValue)
{
this.defaultValue = defaultValue;
}
}