org.apache.kylin.common.util.Bytes.binaryIncrementPos()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(3.0k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中org.apache.kylin.common.util.Bytes.binaryIncrementPos()方法的一些代码示例,展示了Bytes.binaryIncrementPos()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.binaryIncrementPos()方法的具体详情如下:
包路径:org.apache.kylin.common.util.Bytes
类名称:Bytes
方法名:binaryIncrementPos

Bytes.binaryIncrementPos介绍

暂无

代码示例

代码示例来源:origin: apache/kylin

/**
 * Bytewise binary increment/deincrement of long contained in byte array
 * on given amount.
 *
 * @param value  - array of bytes containing long (length <= SIZEOF_LONG)
 * @param amount value will be incremented on (deincremented if negative)
 * @return array of bytes containing incremented long (length == SIZEOF_LONG)
 */
public static byte[] incrementBytes(byte[] value, long amount) {
  byte[] val = value;
  if (val.length < SIZEOF_LONG) {
    // Hopefully this doesn't happen too often.
    byte[] newvalue;
    if (val[0] < 0) {
      newvalue = new byte[] { -1, -1, -1, -1, -1, -1, -1, -1 };
    } else {
      newvalue = new byte[SIZEOF_LONG];
    }
    System.arraycopy(val, 0, newvalue, newvalue.length - val.length, val.length);
    val = newvalue;
  } else if (val.length > SIZEOF_LONG) {
    throw new IllegalArgumentException("Increment Bytes - value too big: " + val.length);
  }
  if (amount == 0)
    return val;
  if (val[0] < 0) {
    return binaryIncrementNeg(val, amount);
  }
  return binaryIncrementPos(val, amount);
}

代码示例来源:origin: org.apache.kylin/kylin-common

/**
 * Bytewise binary increment/deincrement of long contained in byte array
 * on given amount.
 *
 * @param value  - array of bytes containing long (length <= SIZEOF_LONG)
 * @param amount value will be incremented on (deincremented if negative)
 * @return array of bytes containing incremented long (length == SIZEOF_LONG)
 */
public static byte[] incrementBytes(byte[] value, long amount) {
  byte[] val = value;
  if (val.length < SIZEOF_LONG) {
    // Hopefully this doesn't happen too often.
    byte[] newvalue;
    if (val[0] < 0) {
      newvalue = new byte[] { -1, -1, -1, -1, -1, -1, -1, -1 };
    } else {
      newvalue = new byte[SIZEOF_LONG];
    }
    System.arraycopy(val, 0, newvalue, newvalue.length - val.length, val.length);
    val = newvalue;
  } else if (val.length > SIZEOF_LONG) {
    throw new IllegalArgumentException("Increment Bytes - value too big: " + val.length);
  }
  if (amount == 0)
    return val;
  if (val[0] < 0) {
    return binaryIncrementNeg(val, amount);
  }
  return binaryIncrementPos(val, amount);
}

代码示例来源:origin: org.apache.kylin/kylin-core-common

/**
 * Bytewise binary increment/deincrement of long contained in byte array
 * on given amount.
 *
 * @param value  - array of bytes containing long (length <= SIZEOF_LONG)
 * @param amount value will be incremented on (deincremented if negative)
 * @return array of bytes containing incremented long (length == SIZEOF_LONG)
 */
public static byte[] incrementBytes(byte[] value, long amount) {
  byte[] val = value;
  if (val.length < SIZEOF_LONG) {
    // Hopefully this doesn't happen too often.
    byte[] newvalue;
    if (val[0] < 0) {
      newvalue = new byte[] { -1, -1, -1, -1, -1, -1, -1, -1 };
    } else {
      newvalue = new byte[SIZEOF_LONG];
    }
    System.arraycopy(val, 0, newvalue, newvalue.length - val.length, val.length);
    val = newvalue;
  } else if (val.length > SIZEOF_LONG) {
    throw new IllegalArgumentException("Increment Bytes - value too big: " + val.length);
  }
  if (amount == 0)
    return val;
  if (val[0] < 0) {
    return binaryIncrementNeg(val, amount);
  }
  return binaryIncrementPos(val, amount);
}

相关文章