org.apache.sis.math.Vector.longValue()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(96)

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

Vector.longValue介绍

[英]Returns the value at the given index as a long. If this vector uses floating point values, the value is rounded to the nearest integer.

The default implementation delegates to #doubleValue(int) and verifies if the result can be rounded to a long with an error not greater than 0.5. Subclasses that store or compute their values with an integer type should override this method.
[中]将给定索引处的值返回为long。如果此向量使用浮点值,则该值将四舍五入到最接近的整数。
默认实现将委托给#doubleValue(int),并验证结果是否可以四舍五入到long,且误差不大于0.5。使用整数类型存储或计算其值的子类应重写此方法。

代码示例

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Returns the value at the given index.
 */
@Override
public long longValue(int index) {
  final Vector v;
  if (index < limit) {
    v = first;
  } else {
    v = second;
    index -= limit;
  }
  return v.longValue(index);
}

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

/**
 * Returns the value at the given index.
 */
@Override
public long longValue(int index) {
  final Vector v;
  if (index < limit) {
    v = first;
  } else {
    v = second;
    index -= limit;
  }
  return v.longValue(index);
}

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

@Override public long     longValue  (int i)    {return Vector.this.longValue  (indices[i]);}
@Override public int      intValue   (int i)    {return Vector.this.intValue   (indices[i]);}

代码示例来源:origin: org.apache.sis.core/sis-utility

@Override public long     longValue  (int i)    {return Vector.this.longValue  (indices[i]);}
@Override public int      intValue   (int i)    {return Vector.this.intValue   (indices[i]);}

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

/**
   * Returns the instant at the given index.
   */
  @Override
  public Instant get(final int index) {
    return Instant.ofEpochMilli(times.longValue(index));
  }
}

代码示例来源:origin: org.apache.sis.core/sis-feature

/**
   * Returns the instant at the given index.
   */
  @Override
  public Instant get(final int index) {
    return Instant.ofEpochMilli(times.longValue(index));
  }
}

代码示例来源:origin: org.apache.sis.core/sis-utility

@Override public long    longValue  (int index)     {return Vector.this.longValue  (toBacking(index));}
@Override public int     intValue   (int index)     {return Vector.this.intValue   (toBacking(index));}

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

@Override public final long    longValue  (int i) {return base.longValue  (toBase(i));}
@Override public final int     intValue   (int i) {return base.intValue   (toBase(i));}

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

@Override public long    longValue  (int index)     {return Vector.this.longValue  (toBacking(index));}
@Override public int     intValue   (int index)     {return Vector.this.intValue   (toBacking(index));}

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

/**
 * Computes the tile width or height from the other size,
 * or returns a negative number if the size can not be computed.
 *
 * @param  knownSize  the tile width or height.
 * @return the tile width if the known size was height, or the tile height if the known size was width,
 *         or a negative number if the width or height can not be computed.
 * @throws ArithmeticException if the result overflows.
 */
private int computeTileSize(final int knownSize) {
  final int n = tileByteCounts.size();
  if (n != 0) {
    final long count = tileByteCounts.longValue(0);
    int i = 0;
    do if (++i == n) {
      // At this point, we verified that all vector values are equal.
      final long length = pixelToByteCount(knownSize);
      if (count % length != 0) break;
      return Math.toIntExact(count / length);
    } while (tileByteCounts.longValue(i) == n);
  }
  return -1;
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Returns the value at the given index as a {@code short}.
 * If this vector uses floating point values, the value is rounded to the nearest integer.
 *
 * <p>The default implementation delegates to {@link #longValue(int)} and verifies if the result
 * fits in the {@code short} type. Subclasses that store or compute their values with the {@code short}
 * or {@code byte} type should override this method.</p>
 *
 * @param  index  the index in the [0 … {@linkplain #size() size}-1] range.
 * @return the value at the given index.
 * @throws IndexOutOfBoundsException if the given index is out of bounds.
 * @throws NullPointerException if the value is {@code null} (never happen if this vector wraps an array of primitive type).
 * @throws NumberFormatException if the value is stored as a {@code String} and can not be parsed.
 * @throws ArithmeticException if the value is too large for the capacity of the {@code short} type.
 */
public short shortValue(final int index) {
  final long value = longValue(index);
  if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
    return (short) value;
  }
  throw canNotConvert(index, short.class);
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Returns the value at the given index as an {@code int}.
 * If this vector uses floating point values, the value is rounded to the nearest integer.
 *
 * <p>The default implementation delegates to {@link #longValue(int)} and verifies if the result
 * fits in the {@code int} type. Subclasses that store or compute their values with the {@code int},
 * {@code short} or {@code byte} type should override this method.</p>
 *
 * @param  index  the index in the [0 … {@linkplain #size() size}-1] range.
 * @return the value at the given index.
 * @throws IndexOutOfBoundsException if the given index is out of bounds.
 * @throws NullPointerException if the value is {@code null} (never happen if this vector wraps an array of primitive type).
 * @throws NumberFormatException if the value is stored as a {@code String} and can not be parsed.
 * @throws ArithmeticException if the value is too large for the capacity of the {@code int} type.
 */
public int intValue(final int index) {
  final long value = longValue(index);
  if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
    return (int) value;
  }
  throw canNotConvert(index, int.class);
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Returns the value at the given index as a {@code byte}.
 * If this vector uses floating point values, the value is rounded to the nearest integer.
 *
 * <p>The default implementation delegates to {@link #longValue(int)} and verifies if the result
 * fits in the {@code byte} type. Subclasses that store or compute their values with the {@code byte}
 * type should override this method.</p>
 *
 * @param  index  the index in the [0 … {@linkplain #size() size}-1] range.
 * @return the value at the given index.
 * @throws IndexOutOfBoundsException if the given index is out of bounds.
 * @throws NullPointerException if the value is {@code null} (never happen if this vector wraps an array of primitive type).
 * @throws NumberFormatException if the value is stored as a {@code String} and can not be parsed.
 * @throws ArithmeticException if the value is too large for the capacity of the {@code byte} type.
 */
public byte byteValue(final int index) {
  final long value = longValue(index);
  if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
    return (byte) value;
  }
  throw canNotConvert(index, byte.class);
}

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

/**
 * Returns the value at the given index as an {@code int}.
 * If this vector uses floating point values, the value is rounded to the nearest integer.
 *
 * <p>The default implementation delegates to {@link #longValue(int)} and verifies if the result
 * fits in the {@code int} type. Subclasses that store or compute their values with the {@code int},
 * {@code short} or {@code byte} type should override this method.</p>
 *
 * @param  index  the index in the [0 … {@linkplain #size() size}-1] range.
 * @return the value at the given index.
 * @throws IndexOutOfBoundsException if the given index is out of bounds.
 * @throws NullPointerException if the value is {@code null} (never happen if this vector wraps an array of primitive type).
 * @throws NumberFormatException if the value is stored as a {@code String} and can not be parsed.
 * @throws ArithmeticException if the value is too large for the capacity of the {@code int} type.
 */
public int intValue(final int index) {
  final long value = longValue(index);
  if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
    return (int) value;
  }
  throw canNotConvert(index, int.class);
}

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

/**
 * Returns the value at the given index as a {@code byte}.
 * If this vector uses floating point values, the value is rounded to the nearest integer.
 *
 * <p>The default implementation delegates to {@link #longValue(int)} and verifies if the result
 * fits in the {@code byte} type. Subclasses that store or compute their values with the {@code byte}
 * type should override this method.</p>
 *
 * @param  index  the index in the [0 … {@linkplain #size() size}-1] range.
 * @return the value at the given index.
 * @throws IndexOutOfBoundsException if the given index is out of bounds.
 * @throws NullPointerException if the value is {@code null} (never happen if this vector wraps an array of primitive type).
 * @throws NumberFormatException if the value is stored as a {@code String} and can not be parsed.
 * @throws ArithmeticException if the value is too large for the capacity of the {@code byte} type.
 */
public byte byteValue(final int index) {
  final long value = longValue(index);
  if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
    return (byte) value;
  }
  throw canNotConvert(index, byte.class);
}

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

/**
 * Returns the value at the given index as a {@code short}.
 * If this vector uses floating point values, the value is rounded to the nearest integer.
 *
 * <p>The default implementation delegates to {@link #longValue(int)} and verifies if the result
 * fits in the {@code short} type. Subclasses that store or compute their values with the {@code short}
 * or {@code byte} type should override this method.</p>
 *
 * @param  index  the index in the [0 … {@linkplain #size() size}-1] range.
 * @return the value at the given index.
 * @throws IndexOutOfBoundsException if the given index is out of bounds.
 * @throws NullPointerException if the value is {@code null} (never happen if this vector wraps an array of primitive type).
 * @throws NumberFormatException if the value is stored as a {@code String} and can not be parsed.
 * @throws ArithmeticException if the value is too large for the capacity of the {@code short} type.
 */
public short shortValue(final int index) {
  final long value = longValue(index);
  if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
    return (short) value;
  }
  throw canNotConvert(index, short.class);
}

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

/**
 * Creates a new compressed vector initialized to a copy of the data provided by the given vector.
 *
 * @param  source     the vector to copy.
 * @param  increment  the common divisor of all (sample minus offset) values.
 * @param  offset     the minimal value in the source vector.
 * @param  delta      the maximal value in the source vector minus {@code offset} divided by {@code increment}.
 */
private PackedVector(final Vector source, final long increment, final long offset, final int delta) {
  this.increment = increment;
  this.offset    = offset;
  final int length = source.size();
  data = new IntegerList(length, delta, true);
  for (int i=0; i<length; i++) {
    data.setInt(i, Math.toIntExact((source.longValue(i) - offset) / increment));
  }
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Creates a new compressed vector initialized to a copy of the data provided by the given vector.
 *
 * @param  source     the vector to copy.
 * @param  increment  the common divisor of all (sample minus offset) values.
 * @param  offset     the minimal value in the source vector.
 * @param  delta      the maximal value in the source vector minus {@code offset} divided by {@code increment}.
 */
private PackedVector(final Vector source, final long increment, final long offset, final int delta) {
  this.increment = increment;
  this.offset    = offset;
  final int length = source.size();
  data = new IntegerList(length, delta, true);
  for (int i=0; i<length; i++) {
    data.setInt(i, JDK8.toIntExact((source.longValue(i) - offset) / increment));
  }
}

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

/**
 * Tests the case where values in a grid are repeated vertically.
 */
@Test
public void testVertical() {
  Vector vec = Vector.create(new int[] {
      10, 12, 15, 18,
      10, 12, 15, 18,
      10, 12, 15, 18}, false);
  vec = new RepeatedVector(vec, vec.repetitions(), 0);
  assertArrayEquals(new int[] {1,4}, vec.repetitions());
  assertEquals(10, vec.intValue  ( 0));
  assertEquals(12, vec.shortValue( 1));
  assertEquals(15, vec.longValue ( 2));
  assertEquals(18, vec.intValue  ( 3));
  assertEquals(10, vec.intValue  ( 4));
  assertEquals(18, vec.shortValue( 7));
  assertEquals(10, vec.longValue ( 8));
  assertEquals(15, vec.intValue  (10));
  Vector sub = vec.subList(0, 4);
  assertFalse("Expected the backing array.", sub instanceof RepeatedVector);
  assertArrayEquals(new float[] {10, 12, 15, 18}, sub.floatValues(), (float) STRICT);
}

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

/**
 * Tests the case where values in a grid are repeated horizontally.
 */
@Test
public void testHorizontal() {
  Vector vec = Vector.create(new int[] {
      10, 10, 10, 10,
      12, 12, 12, 12,
      15, 15, 15, 15}, false);
  vec = new RepeatedVector(vec, vec.repetitions(), 0);
  assertArrayEquals(new int[] {4}, vec.repetitions());
  assertEquals(10, vec.intValue  ( 0));
  assertEquals(10, vec.shortValue( 1));
  assertEquals(10, vec.longValue ( 2));
  assertEquals(10, vec.intValue  ( 3));
  assertEquals(12, vec.intValue  ( 4));
  assertEquals(12, vec.shortValue( 7));
  assertEquals(15, vec.longValue ( 8));
  assertEquals(15, vec.intValue  (11));
  Vector sub = vec.subSampling(0, 4, 3);
  assertFalse("Expected the backing array.", sub instanceof RepeatedVector);
  assertArrayEquals(new float[] {10, 12, 15}, sub.floatValues(), (float) STRICT);
}

相关文章