use of org.apache.commons.lang3.mutable.MutableInt in project sling by apache.
the class PollingTest method testCallableTwice.
@Test
public void testCallableTwice() throws Exception {
final MutableInt callCount = new MutableInt(0);
final MutableBoolean called = new MutableBoolean(false);
Polling p = new Polling(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
callCount.increment();
boolean b = called.booleanValue();
called.setTrue();
return b;
}
});
p.poll(500, 10);
assertEquals(2, callCount.intValue());
}
use of org.apache.commons.lang3.mutable.MutableInt in project sling by apache.
the class PollingTest method testCallableTimeout.
@Test
public void testCallableTimeout() throws Exception {
final MutableInt callCount = new MutableInt(0);
Polling p = new Polling(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
callCount.increment();
return false;
}
});
try {
p.poll(100, 10);
} catch (TimeoutException e) {
assertTrue("Expected to execute call() at least 4 times, got instead only " + callCount.intValue() + " calls", callCount.intValue() > 5);
return;
}
fail("Did not reach timeout");
}
use of org.apache.commons.lang3.mutable.MutableInt in project gatk by broadinstitute.
the class AllelicPanelOfNormalsCreator method create.
/**
* Creates an {@link AllelicPanelOfNormals} given a site-frequency threshold;
* sites appearing in strictly less than this fraction of samples will not be included in the panel of normals.
* @param siteFrequencyThreshold site-frequency threshold
* @return an {@link AllelicPanelOfNormals} containing sites
* above the site-frequency threshold
*/
public AllelicPanelOfNormals create(final double siteFrequencyThreshold) {
logger.info("Creating allelic panel of normals...");
//used to filter on frequency
final Map<SimpleInterval, MutableInt> numberOfSamplesMap = new HashMap<>();
//store only the total counts (smaller memory footprint)
final Map<SimpleInterval, AllelicCount> totalCountsMap = new HashMap<>();
int pulldownFileCounter = 1;
final int totalNumberOfSamples = pulldownFiles.size();
for (final File pulldownFile : pulldownFiles) {
logger.info("Processing pulldown file " + pulldownFileCounter++ + "/" + totalNumberOfSamples + " (" + pulldownFile + ")...");
final AllelicCountCollection pulldownCounts = new AllelicCountCollection(pulldownFile);
for (final AllelicCount count : pulldownCounts.getCounts()) {
//update the sum of ref and alt counts at each site
final SimpleInterval site = count.getInterval();
final AllelicCount currentCountAtSite = totalCountsMap.getOrDefault(site, new AllelicCount(site, 0, 0));
final AllelicCount updatedCountAtSite = new AllelicCount(site, currentCountAtSite.getRefReadCount() + count.getRefReadCount(), currentCountAtSite.getAltReadCount() + count.getAltReadCount());
totalCountsMap.put(site, updatedCountAtSite);
//update the number of samples seen possessing each site
final MutableInt numberOfSamplesAtSite = numberOfSamplesMap.get(site);
if (numberOfSamplesAtSite == null) {
numberOfSamplesMap.put(site, new MutableInt(1));
} else {
numberOfSamplesAtSite.increment();
}
}
}
logger.info("Total number of unique sites present in samples: " + totalCountsMap.size());
//filter out sites that appear at a frequency strictly less than the provided threshold
final AllelicCountCollection totalCounts = new AllelicCountCollection();
numberOfSamplesMap.entrySet().stream().filter(e -> e.getValue().doubleValue() / totalNumberOfSamples >= siteFrequencyThreshold).map(e -> totalCountsMap.get(e.getKey())).forEach(totalCounts::add);
logger.info(String.format("Number of unique sites present in samples above site frequency = %4.3f: %d", siteFrequencyThreshold, totalCounts.getCounts().size()));
return new AllelicPanelOfNormals(totalCounts);
}
use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.
the class AbstractStreamPatternMatcher method setup.
@Override
public void setup(Context.OperatorContext context) {
super.setup(context);
patternLength = new MutableInt(pattern.getStates().length - 1);
}
use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.
the class GPOUtils method serialize.
/**
* Serializes the given {@link GPOMutable} object to an array of bytes.
* @param gpo The {@link GPOMutable} object to serialize.
* @param byteArrayList A byte array list to pack serialized data into. Note that
* it is assumed that the byteArrayList is empty when passed to this method.
* @return The serialized {@link GPOMutable} object.
*/
public static byte[] serialize(GPOMutable gpo, GPOByteArrayList byteArrayList) {
int slength = serializedLength(gpo);
byte[] sbytes = new byte[slength];
MutableInt offset = new MutableInt(0);
boolean[] fieldsBoolean = gpo.getFieldsBoolean();
if (fieldsBoolean != null) {
for (int index = 0; index < fieldsBoolean.length; index++) {
serializeBoolean(fieldsBoolean[index], sbytes, offset);
}
}
char[] fieldsCharacter = gpo.getFieldsCharacter();
if (fieldsCharacter != null) {
for (int index = 0; index < fieldsCharacter.length; index++) {
serializeChar(fieldsCharacter[index], sbytes, offset);
}
}
byte[] fieldsByte = gpo.getFieldsByte();
if (fieldsByte != null) {
for (int index = 0; index < fieldsByte.length; index++) {
serializeByte(fieldsByte[index], sbytes, offset);
}
}
short[] fieldsShort = gpo.getFieldsShort();
if (fieldsShort != null) {
for (int index = 0; index < fieldsShort.length; index++) {
serializeShort(fieldsShort[index], sbytes, offset);
}
}
int[] fieldsInteger = gpo.getFieldsInteger();
if (fieldsInteger != null) {
for (int index = 0; index < fieldsInteger.length; index++) {
serializeInt(fieldsInteger[index], sbytes, offset);
}
}
long[] fieldsLong = gpo.getFieldsLong();
if (fieldsLong != null) {
for (int index = 0; index < fieldsLong.length; index++) {
serializeLong(fieldsLong[index], sbytes, offset);
}
}
float[] fieldsFloat = gpo.getFieldsFloat();
if (fieldsFloat != null) {
for (int index = 0; index < fieldsFloat.length; index++) {
serializeFloat(fieldsFloat[index], sbytes, offset);
}
}
double[] fieldsDouble = gpo.getFieldsDouble();
if (fieldsDouble != null) {
for (int index = 0; index < fieldsDouble.length; index++) {
serializeDouble(fieldsDouble[index], sbytes, offset);
}
}
String[] fieldsString = gpo.getFieldsString();
if (fieldsString != null) {
for (int index = 0; index < fieldsString.length; index++) {
serializeString(fieldsString[index], sbytes, offset);
}
}
if (sbytes.length > 0) {
byteArrayList.add(sbytes);
}
Object[] fieldsObject = gpo.getFieldsObject();
Serde[] serdes = gpo.getFieldDescriptor().getSerdes();
if (fieldsObject != null) {
for (int index = 0; index < fieldsObject.length; index++) {
byteArrayList.add(serdes[index].serializeObject(fieldsObject[index]));
}
}
byte[] bytes = byteArrayList.toByteArray();
byteArrayList.clear();
return bytes;
}
Aggregations