use of org.apache.commons.lang.mutable.MutableInt in project tdi-studio-se by Talend.
the class EBCDICType3 method getNextByte.
private static byte getNextByte(String number, MutableInt recentlyReturned) {
MutableInt zero = new MutableInt(0);
recentlyReturned.decrement();
if (recentlyReturned.compareTo(zero) >= 0) {
while (!"0123456789".contains(String.valueOf(number.charAt(recentlyReturned.intValue())))) {
recentlyReturned.decrement();
if (recentlyReturned.compareTo(zero) < 0) {
return 0;
}
}
return (byte) (Character.getNumericValue(number.charAt(recentlyReturned.intValue())));
} else {
return 0;
}
}
use of org.apache.commons.lang.mutable.MutableInt in project tdi-studio-se by Talend.
the class EBCDICType3 method writeType3Value.
public static byte[] writeType3Value(int length, int decimal, BigDecimal value, boolean isSigned) throws Exception {
if (decimal != value.scale()) {
BigDecimal tmp = value.setScale(decimal, BigDecimal.ROUND_FLOOR);
value = tmp;
}
String str = value.toPlainString();
int len = str.length();
byte[] buf = new byte[length];
MutableInt k = new MutableInt(len);
// left and right nibble ( we go from right to left )
byte even;
byte odd;
for (int i = length - 1; i >= 0; i--) {
// Last byte needs sign nibble
if (i == (length - 1)) {
even = getNextByte(str, k);
if (isSigned) {
if (value.signum() >= 0) {
odd = 0x0C;
} else {
odd = 0x0D;
}
} else {
odd = (byte) 0x0F;
}
} else {
// Packing rest of the digits...
// Get even digit if exist or zero
odd = getNextByte(str, k);
even = getNextByte(str, k);
}
buf[i] = (byte) ((even << 4) | odd);
}
// TODO: Check if str ">" buf and eventually throw an Exc.
return buf;
}
use of org.apache.commons.lang.mutable.MutableInt in project incubator-systemml by apache.
the class ReaderTextCSV method readCSVMatrixFromHDFS.
@SuppressWarnings("unchecked")
private MatrixBlock readCSVMatrixFromHDFS(Path path, JobConf job, FileSystem fs, MatrixBlock dest, long rlen, long clen, int brlen, int bclen, boolean hasHeader, String delim, boolean fill, double fillValue) throws IOException {
//prepare file paths in alphanumeric order
ArrayList<Path> files = new ArrayList<Path>();
if (fs.isDirectory(path)) {
for (FileStatus stat : fs.listStatus(path, CSVReblockMR.hiddenFileFilter)) files.add(stat.getPath());
Collections.sort(files);
} else
files.add(path);
//determine matrix size via additional pass if required
if (dest == null) {
dest = computeCSVSize(files, job, fs, hasHeader, delim, fill, fillValue);
clen = dest.getNumColumns();
}
//actual read of individual files
long lnnz = 0;
MutableInt row = new MutableInt(0);
for (int fileNo = 0; fileNo < files.size(); fileNo++) {
lnnz += readCSVMatrixFromInputStream(fs.open(files.get(fileNo)), path.toString(), dest, row, rlen, clen, brlen, bclen, hasHeader, delim, fill, fillValue, fileNo == 0);
}
//post processing
dest.setNonZeros(lnnz);
return dest;
}
use of org.apache.commons.lang.mutable.MutableInt in project incubator-systemml by apache.
the class ReaderTextCSV method readMatrixFromInputStream.
@Override
public MatrixBlock readMatrixFromInputStream(InputStream is, long rlen, long clen, int brlen, int bclen, long estnnz) throws IOException, DMLRuntimeException {
//allocate output matrix block
MatrixBlock ret = createOutputMatrixBlock(rlen, clen, (int) rlen, (int) clen, estnnz, true, false);
//core read
long lnnz = readCSVMatrixFromInputStream(is, "external inputstream", ret, new MutableInt(0), rlen, clen, brlen, bclen, _props.hasHeader(), _props.getDelim(), _props.isFill(), _props.getFillValue(), true);
//finally check if change of sparse/dense block representation required
ret.setNonZeros(lnnz);
ret.examSparsity();
return ret;
}
use of org.apache.commons.lang.mutable.MutableInt in project gatk by broadinstitute.
the class AnnotateVcfWithBamDepth method apply.
@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext refContext, final FeatureContext fc) {
final MutableInt depth = new MutableInt(0);
for (final GATKRead read : readsContext) {
if (!read.failsVendorQualityCheck() && !read.isDuplicate() && !read.isUnmapped() && read.getEnd() > read.getStart() && new SimpleInterval(read).contains(vc)) {
depth.increment();
}
}
vcfWriter.add(new VariantContextBuilder(vc).attribute(POOLED_BAM_DEPTH_ANNOTATION_NAME, depth.intValue()).make());
}
Aggregations