Java Code Examples for org.apache.commons.lang3.mutable.MutableInt#add()

The following examples show how to use org.apache.commons.lang3.mutable.MutableInt#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
/**
 * This method deserializes a double from the given byte array from the given offset,
 * and increments the offset appropriately.
 * @param buffer The byte buffer to deserialize from.
 * @param offset The offset to deserialize from.
 * @return The deserialized double.
 */
public static double deserializeDouble(byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  long val = (((long)buffer[0 + offsetInt]) & 0xFFL) << 56 |
      ((((long)buffer[1 + offsetInt]) & 0xFFL) << 48) |
      ((((long)buffer[2 + offsetInt]) & 0xFFL) << 40) |
      ((((long)buffer[3 + offsetInt]) & 0xFFL) << 32) |
      ((((long)buffer[4 + offsetInt]) & 0xFFL) << 24) |
      ((((long)buffer[5 + offsetInt]) & 0xFFL) << 16) |
      ((((long)buffer[6 + offsetInt]) & 0xFFL) << 8) |
      (((long)buffer[7 + offsetInt]) & 0xFFL);

  offset.add(Type.DOUBLE.getByteSize());
  return Double.longBitsToDouble(val);
}
 
Example 2
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
/**
 * This method serializes the given double to the given byte buffer to the given offset,
 * the method also increments the offset appropriately.
 * @param valD The value to serialize.
 * @param buffer The byte buffer to serialize to.
 * @param offset The offset in the buffer to serialize to and also to increment appropriately.
 */
public static void serializeDouble(double valD, byte[] buffer, MutableInt offset)
{
  long val = Double.doubleToLongBits(valD);

  int offsetInt = offset.intValue();
  buffer[0 + offsetInt] = (byte)((val >> 56) & 0xFFL);
  buffer[1 + offsetInt] = (byte)((val >> 48) & 0xFFL);
  buffer[2 + offsetInt] = (byte)((val >> 40) & 0xFFL);
  buffer[3 + offsetInt] = (byte)((val >> 32) & 0xFFL);
  buffer[4 + offsetInt] = (byte)((val >> 24) & 0xFFL);
  buffer[5 + offsetInt] = (byte)((val >> 16) & 0xFFL);
  buffer[6 + offsetInt] = (byte)((val >> 8) & 0xFFL);
  buffer[7 + offsetInt] = (byte)(val & 0xFFL);

  offset.add(Type.DOUBLE.getByteSize());
}
 
Example 3
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method deserializes a character from the given byte array from the given offset,
 * and increments the offset appropriately.
 * @param buffer The byte buffer to deserialize from.
 * @param offset The offset to deserialize from.
 * @return The deserialized character.
 */
public static char deserializeChar(byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  char val = (char)(((((int)buffer[0 + offsetInt]) & 0xFF) << 8) |
      (((int)buffer[1 + offsetInt]) & 0xFF));

  offset.add(Type.CHAR.getByteSize());
  return val;
}
 
Example 4
Source File: SimpleOffsetSerializer.java    From teku with Apache License 2.0 5 votes vote down vote up
private static Object deserializePrimitive(
    Class classInfo, SSZReader reader, MutableInt bytePointer) {
  switch (classInfo.getSimpleName()) {
    case "UnsignedLong":
      bytePointer.add(8);
      return UnsignedLong.fromLongBits(reader.readUInt64());
    case "ArrayWrappingBytes32":
    case "Bytes32":
      bytePointer.add(32);
      return Bytes32.wrap(reader.readFixedBytes(32));
    case "Bytes4":
      bytePointer.add(4);
      return new Bytes4(reader.readFixedBytes(4));
    case "BLSSignature":
      bytePointer.add(96);
      return BLSSignature.fromBytes(reader.readFixedBytes(96));
    case "BLSPublicKey":
      bytePointer.add(48);
      return BLSPublicKey.fromBytes(reader.readFixedBytes(48));
    case "Boolean":
    case "boolean":
      bytePointer.add(1);
      return reader.readBoolean();
    default:
      throw new IllegalArgumentException("Unable to deserialize " + classInfo.getSimpleName());
  }
}
 
Example 5
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method deserializes a byte from the given byte array from the given offset,
 * and increments the offset appropriately.
 * @param buffer The byte buffer to deserialize from.
 * @param offset The offset to deserialize from.
 * @return The deserialized byte.
 */
public static byte deserializeByte(byte[] buffer, MutableInt offset)
{
  byte val = buffer[offset.intValue()];

  offset.add(Type.BYTE.getByteSize());
  return val;
}
 
Example 6
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method deserializes a string from the given byte array from the given offset,
 * and increments the offset appropriately.
 * @param buffer The byte buffer to deserialize from.
 * @param offset The offset to deserialize from.
 * @return The deserialized string.
 */
public static String deserializeString(byte[] buffer, MutableInt offset)
{
  int length = deserializeInt(buffer, offset);

  String val = new String(buffer, offset.intValue(), length);
  offset.add(length);
  return val;
}
 
Example 7
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method serializes the given short to the given byte buffer to the given offset,
 * the method also increments the offset appropriately.
 * @param val The value to serialize.
 * @param buffer The byte buffer to serialize to.
 * @param offset The offset in the buffer to serialize to and also to increment appropriately.
 */
public static void serializeShort(short val, byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  buffer[0 + offsetInt] = (byte)((val >> 8) & 0xFF);
  buffer[1 + offsetInt] = (byte)(val & 0xFF);

  offset.add(Type.SHORT.getByteSize());
}
 
Example 8
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method serializes the given character to the given byte buffer to the given offset,
 * the method also increments the offset appropriately.
 * @param val The value to serialize.
 * @param buffer The byte buffer to serialize to.
 * @param offset The offset in the buffer to serialize to and also to increment appropriately.
 */
public static void serializeChar(char val, byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  buffer[0 + offsetInt] = (byte)((val >> 8) & 0xFF);
  buffer[1 + offsetInt] = (byte)(val & 0xFF);

  offset.add(Type.CHAR.getByteSize());
}
 
Example 9
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method serializes the given long to the given byte buffer to the given offset,
 * the method also increments the offset appropriately.
 * @param val The value to serialize.
 * @param buffer The byte buffer to serialize to.
 * @param offset The offset in the buffer to serialize to and also to increment appropriately.
 */
public static void serializeLong(long val, byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  buffer[0 + offsetInt] = (byte)((val >> 56) & 0xFFL);
  buffer[1 + offsetInt] = (byte)((val >> 48) & 0xFFL);
  buffer[2 + offsetInt] = (byte)((val >> 40) & 0xFFL);
  buffer[3 + offsetInt] = (byte)((val >> 32) & 0xFFL);
  buffer[4 + offsetInt] = (byte)((val >> 24) & 0xFFL);
  buffer[5 + offsetInt] = (byte)((val >> 16) & 0xFFL);
  buffer[6 + offsetInt] = (byte)((val >> 8) & 0xFFL);
  buffer[7 + offsetInt] = (byte)(val & 0xFFL);

  offset.add(Type.LONG.getByteSize());
}
 
Example 10
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method deserializes an integer from the given byte array from the given offset,
 * and increments the offset appropriately.
 * @param buffer The byte buffer to deserialize from.
 * @param offset The offset to deserialize from.
 * @return The deserialized integer.
 */
public static int deserializeInt(byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  int val = ((((int)buffer[0 + offsetInt]) & 0xFF) << 24) |
      ((((int)buffer[1 + offsetInt]) & 0xFF) << 16) |
      ((((int)buffer[2 + offsetInt]) & 0xFF) << 8) |
      (((int)buffer[3 + offsetInt]) & 0xFF);

  offset.add(Type.INTEGER.getByteSize());
  return val;
}
 
Example 11
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method serializes the given integer to the given byte buffer to the given offset,
 * the method also increments the offset appropriately.
 * @param val The value to serialize.
 * @param buffer The byte buffer to serialize to.
 * @param offset The offset in the buffer to serialize to and also to increment appropriately.
 */
public static void serializeInt(int val, byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  buffer[0 + offsetInt] = (byte)((val >> 24) & 0xFF);
  buffer[1 + offsetInt] = (byte)((val >> 16) & 0xFF);
  buffer[2 + offsetInt] = (byte)((val >> 8) & 0xFF);
  buffer[3 + offsetInt] = (byte)(val & 0xFF);

  offset.add(Type.INTEGER.getByteSize());
}
 
Example 12
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method deserializes a float from the given byte array from the given offset,
 * and increments the offset appropriately.
 * @param buffer The byte buffer to deserialize from.
 * @param offset The offset to deserialize from.
 * @return The deserialized float.
 */
public static float deserializeFloat(byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  int val = ((((int)buffer[0 + offsetInt]) & 0xFF) << 24) |
      ((((int)buffer[1 + offsetInt]) & 0xFF) << 16) |
      ((((int)buffer[2 + offsetInt]) & 0xFF) << 8) |
      (((int)buffer[3 + offsetInt]) & 0xFF);

  offset.add(Type.FLOAT.getByteSize());
  return Float.intBitsToFloat(val);
}
 
Example 13
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method serializes the given float to the given byte buffer to the given offset,
 * the method also increments the offset appropriately.
 * @param valf The value to serialize.
 * @param buffer The byte buffer to serialize to.
 * @param offset The offset in the buffer to serialize to and also to increment appropriately.
 */
public static void serializeFloat(float valf, byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  int val = Float.floatToIntBits(valf);

  buffer[0 + offsetInt] = (byte)((val >> 24) & 0xFF);
  buffer[1 + offsetInt] = (byte)((val >> 16) & 0xFF);
  buffer[2 + offsetInt] = (byte)((val >> 8) & 0xFF);
  buffer[3 + offsetInt] = (byte)(val & 0xFF);

  offset.add(Type.FLOAT.getByteSize());
}
 
Example 14
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method deserializes a short from the given byte array from the given offset,
 * and increments the offset appropriately.
 * @param buffer The byte buffer to deserialize from.
 * @param offset The offset to deserialize from.
 * @return The deserialized short.
 */
public static short deserializeShort(byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  short val = (short)(((((int)buffer[0 + offsetInt]) & 0xFF) << 8) |
      (((int)buffer[1 + offsetInt]) & 0xFF));

  offset.add(Type.SHORT.getByteSize());
  return val;
}
 
Example 15
Source File: SumInt.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public MutableInt accumulate(MutableInt accumulatedValue, Integer input)
{
  accumulatedValue.add(input);
  return accumulatedValue;
}
 
Example 16
Source File: SumInt.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public MutableInt merge(MutableInt accumulatedValue1, MutableInt accumulatedValue2)
{
  accumulatedValue1.add(accumulatedValue2);
  return accumulatedValue1;
}
 
Example 17
Source File: SimpleOffsetSerializer.java    From teku with Apache License 2.0 4 votes vote down vote up
private static int readOffset(SSZReader reader, MutableInt bytesPointer) {
  bytesPointer.add(4);
  return reader.readInt32();
}
 
Example 18
Source File: SimpleOffsetSerializer.java    From teku with Apache License 2.0 4 votes vote down vote up
private static Bitvector deserializeBitvector(
    int bitvectorSize, SSZReader reader, MutableInt bytesPointer) {
  int bitvectorByteSize = (bitvectorSize + 7) / 8;
  bytesPointer.add(bitvectorByteSize);
  return Bitvector.fromBytes(reader.readFixedBytes(bitvectorByteSize), bitvectorSize);
}
 
Example 19
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 3 votes vote down vote up
/**
 * This method serializes the given byte to the given byte buffer to the given offset,
 * the method also increments the offset appropriately.
 * @param val The value to serialize.
 * @param buffer The byte buffer to serialize to.
 * @param offset The offset in the buffer to serialize to and also to increment appropriately.
 */
public static void serializeByte(byte val, byte[] buffer, MutableInt offset)
{
  buffer[offset.intValue()] = val;

  offset.add(Type.BYTE.getByteSize());
}
 
Example 20
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 3 votes vote down vote up
/**
 * This method serializes the given boolean to the given byte buffer to the given offset,
 * the method also increments the offset appropriately.
 * @param val The value to serialize.
 * @param buffer The byte buffer to serialize to.
 * @param offset The offset in the buffer to serialize to and also to increment appropriately.
 */
public static void serializeBoolean(boolean val, byte[] buffer, MutableInt offset)
{
  buffer[offset.intValue()] = (byte)(val ? 1 : 0);

  offset.add(Type.BOOLEAN.getByteSize());
}