List of usage examples for org.apache.commons.lang3.mutable MutableInt longValue
@Override public long longValue()
From source file:com.gs.obevo.mongodb.impl.MongoDbDeployExecutionDao.java
@Override public void persistNew(DeployExecution deployExecution, PhysicalSchema physicalSchema) { MongoDatabase database = mongoClient.getDatabase(physicalSchema.getPhysicalName()); MongoCollection<Document> auditCollection = database.getCollection(deployExecutionTableName); MutableInt mutableInt = nextIdBySchema.get(physicalSchema); mutableInt.increment();//from ww w. jav a2s . com ((DeployExecutionImpl) deployExecution).setId(mutableInt.longValue()); Document doc = getDocumentFromDeployExecution(deployExecution, false); auditCollection.insertOne(doc); }
From source file:com.epam.catgenome.manager.protein.ProteinSequenceReconstructionManager.java
private void addProteinSequenceEntry(Track<Gene> track, final Gene cds, List<ProteinSequenceEntry> proteinSequences, String aminoAcid, long tripleStartIndex, int newExtendedStart, final MutableInt aminoAcidCounter) { if (tripleStartIndex >= track.getStartIndex() && tripleStartIndex <= track.getEndIndex()) { long tripleEndIndex = tripleStartIndex + 2; if (newExtendedStart != 0) { tripleEndIndex = tripleEndIndex - Math.abs(newExtendedStart); }/* w ww . j a v a 2s .com*/ if (tripleEndIndex > cds.getEndIndex()) { tripleEndIndex = cds.getEndIndex(); } if (!(tripleStartIndex > track.getStartIndex() && tripleEndIndex > track.getEndIndex()) && !(tripleStartIndex < track.getStartIndex() && tripleEndIndex < track.getEndIndex())) { ProteinSequenceEntry protein = new ProteinSequenceEntry(aminoAcid, track.getId(), cds.getStartIndex().longValue(), cds.getEndIndex().longValue(), tripleStartIndex, tripleEndIndex); protein.setIndex(aminoAcidCounter.longValue() - 1); proteinSequences.add(protein); } } }
From source file:org.apache.nifi.util.orc.OrcUtils.java
public static void putToRowBatch(ColumnVector col, MutableInt vectorOffset, int rowNumber, Schema fieldSchema, Object o) {//from www . j a va2s . co m Schema.Type fieldType = fieldSchema.getType(); if (fieldType == null) { throw new IllegalArgumentException("Field type is null"); } if (o == null) { col.isNull[rowNumber] = true; } else { switch (fieldType) { case INT: ((LongColumnVector) col).vector[rowNumber] = (int) o; break; case LONG: ((LongColumnVector) col).vector[rowNumber] = (long) o; break; case BOOLEAN: ((LongColumnVector) col).vector[rowNumber] = ((boolean) o) ? 1 : 0; break; case BYTES: ByteBuffer byteBuffer = ((ByteBuffer) o); int size = byteBuffer.remaining(); byte[] buf = new byte[size]; byteBuffer.get(buf, 0, size); ((BytesColumnVector) col).setVal(rowNumber, buf); break; case DOUBLE: ((DoubleColumnVector) col).vector[rowNumber] = (double) o; break; case FLOAT: ((DoubleColumnVector) col).vector[rowNumber] = (float) o; break; case STRING: case ENUM: ((BytesColumnVector) col).setVal(rowNumber, o.toString().getBytes()); break; case UNION: // If the union only has one non-null type in it, it was flattened in the ORC schema if (col instanceof UnionColumnVector) { UnionColumnVector union = ((UnionColumnVector) col); Schema.Type avroType = OrcUtils.getAvroSchemaTypeOfObject(o); // Find the index in the union with the matching Avro type int unionIndex = -1; List<Schema> types = fieldSchema.getTypes(); final int numFields = types.size(); for (int i = 0; i < numFields && unionIndex == -1; i++) { if (avroType.equals(types.get(i).getType())) { unionIndex = i; } } if (unionIndex == -1) { throw new IllegalArgumentException("Object type " + avroType.getName() + " not found in union '" + fieldSchema.getName() + "'"); } // Need nested vector offsets MutableInt unionVectorOffset = new MutableInt(0); putToRowBatch(union.fields[unionIndex], unionVectorOffset, rowNumber, fieldSchema.getTypes().get(unionIndex), o); } else { // Find and use the non-null type from the union List<Schema> types = fieldSchema.getTypes(); Schema effectiveType = null; for (Schema type : types) { if (!Schema.Type.NULL.equals(type.getType())) { effectiveType = type; break; } } putToRowBatch(col, vectorOffset, rowNumber, effectiveType, o); } break; case ARRAY: Schema arrayType = fieldSchema.getElementType(); ListColumnVector array = ((ListColumnVector) col); if (o instanceof int[] || o instanceof long[]) { int length = (o instanceof int[]) ? ((int[]) o).length : ((long[]) o).length; for (int i = 0; i < length; i++) { ((LongColumnVector) array.child).vector[vectorOffset.getValue() + i] = (o instanceof int[]) ? ((int[]) o)[i] : ((long[]) o)[i]; } array.offsets[rowNumber] = vectorOffset.longValue(); array.lengths[rowNumber] = length; vectorOffset.add(length); } else if (o instanceof float[]) { float[] floatArray = (float[]) o; for (int i = 0; i < floatArray.length; i++) { ((DoubleColumnVector) array.child).vector[vectorOffset.getValue() + i] = floatArray[i]; } array.offsets[rowNumber] = vectorOffset.longValue(); array.lengths[rowNumber] = floatArray.length; vectorOffset.add(floatArray.length); } else if (o instanceof double[]) { double[] doubleArray = (double[]) o; for (int i = 0; i < doubleArray.length; i++) { ((DoubleColumnVector) array.child).vector[vectorOffset.getValue() + i] = doubleArray[i]; } array.offsets[rowNumber] = vectorOffset.longValue(); array.lengths[rowNumber] = doubleArray.length; vectorOffset.add(doubleArray.length); } else if (o instanceof String[]) { String[] stringArray = (String[]) o; BytesColumnVector byteCol = ((BytesColumnVector) array.child); for (int i = 0; i < stringArray.length; i++) { if (stringArray[i] == null) { byteCol.isNull[rowNumber] = true; } else { byteCol.setVal(vectorOffset.getValue() + i, stringArray[i].getBytes()); } } array.offsets[rowNumber] = vectorOffset.longValue(); array.lengths[rowNumber] = stringArray.length; vectorOffset.add(stringArray.length); } else if (o instanceof Map[]) { Map[] mapArray = (Map[]) o; MutableInt mapVectorOffset = new MutableInt(0); for (int i = 0; i < mapArray.length; i++) { if (mapArray[i] == null) { array.child.isNull[rowNumber] = true; } else { putToRowBatch(array.child, mapVectorOffset, vectorOffset.getValue() + i, arrayType, mapArray[i]); } } array.offsets[rowNumber] = vectorOffset.longValue(); array.lengths[rowNumber] = mapArray.length; vectorOffset.add(mapArray.length); } else if (o instanceof List) { List listArray = (List) o; MutableInt listVectorOffset = new MutableInt(0); int numElements = listArray.size(); for (int i = 0; i < numElements; i++) { if (listArray.get(i) == null) { array.child.isNull[rowNumber] = true; } else { putToRowBatch(array.child, listVectorOffset, vectorOffset.getValue() + i, arrayType, listArray.get(i)); } } array.offsets[rowNumber] = vectorOffset.longValue(); array.lengths[rowNumber] = numElements; vectorOffset.add(numElements); } else { throw new IllegalArgumentException( "Object class " + o.getClass().getName() + " not supported as an ORC list/array"); } break; case MAP: MapColumnVector map = ((MapColumnVector) col); // Avro maps require String keys @SuppressWarnings("unchecked") Map<String, ?> mapObj = (Map<String, ?>) o; int effectiveRowNumber = vectorOffset.getValue(); for (Map.Entry<String, ?> entry : mapObj.entrySet()) { putToRowBatch(map.keys, vectorOffset, effectiveRowNumber, Schema.create(Schema.Type.STRING), entry.getKey()); putToRowBatch(map.values, vectorOffset, effectiveRowNumber, fieldSchema.getValueType(), entry.getValue()); effectiveRowNumber++; } map.offsets[rowNumber] = vectorOffset.longValue(); map.lengths[rowNumber] = mapObj.size(); vectorOffset.add(mapObj.size()); break; default: throw new IllegalArgumentException("Field type " + fieldType.getName() + " not recognized"); } } }