org.apache.sis.util.Numbers.getEnumConstant()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(144)

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

Numbers.getEnumConstant介绍

[英]Returns a numeric constant for the given type. The constants are #BIG_DECIMAL, #BIG_INTEGER, #DOUBLE, #FLOAT, #LONG, #INTEGER, #SHORT, #BYTE, #CHARACTER, #BOOLEAN, or #OTHERconstants for the given type. This is a commodity for usage in switch statements.
[中]返回给定类型的数值常量。对于给定的类型,常量是#大#十进制、#大#整数、#双精度、#浮点、#长、#整数、#短、#字节、#字符、#布尔值或#其他常量。这是一种用于switch语句的商品。

代码示例

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

/**
   * Returns {@code true} if the given type is one of the types supported
   * by {@link NumberConverter}.
   */
  private static boolean isSupportedNumber(final Class<?> type) {
    final int code = Numbers.getEnumConstant(type);
    return (code >= Numbers.BYTE && code <= Numbers.BIG_DECIMAL);
  }
}

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

/**
   * Returns {@code true} if the given type is one of the types supported
   * by {@link NumberConverter}.
   */
  private static boolean isSupportedNumber(final Class<?> type) {
    final int code = Numbers.getEnumConstant(type);
    return (code >= Numbers.BYTE && code <= Numbers.BIG_DECIMAL);
  }
}

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

/**
 * Gets an instance of the given type, or {@code null} if the given type is not supported.
 */
static Format getInstance(final Class<?> type) {
  final int index;
  if (type == Number.class) {
    index = 0;
  } else {
    index = Numbers.getEnumConstant(type) - (Numbers.BYTE - 1);
    if (index < 0 || index >= INSTANCES.length) {
      return null;
    }
  }
  synchronized (INSTANCES) {
    Format format = INSTANCES[index];
    if (format == null) {
      INSTANCES[index] = format = new DefaultFormat(type);
    }
    return format;
  }
}

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

/**
 * Gets an instance of the given type, or {@code null} if the given type is not supported.
 */
static Format getInstance(final Class<?> type) {
  final int index;
  if (type == Number.class) {
    index = 0;
  } else {
    index = Numbers.getEnumConstant(type) - (Numbers.BYTE - 1);
    if (index < 0 || index >= INSTANCES.length) {
      return null;
    }
  }
  synchronized (INSTANCES) {
    Format format = INSTANCES[index];
    if (format == null) {
      INSTANCES[index] = format = new DefaultFormat(type);
    }
    return format;
  }
}

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

/**
 * Constructs an initially empty set of ranges.
 * This constructor is provided for sub-classing only.
 * Client code should use the static {@link #create(Class, boolean, boolean)} method instead.
 *
 * @param elementType    the type of the range elements.
 * @param isMinIncluded  {@code true} if the minimal values are inclusive, or {@code false} if exclusive.
 * @param isMaxIncluded  {@code true} if the maximal values are inclusive, or {@code false} if exclusive.
 */
protected RangeSet(final Class<E> elementType, final boolean isMinIncluded, final boolean isMaxIncluded) {
  ArgumentChecks.ensureNonNull("elementType", elementType);
  // Following assertion may fail only if the user bypass the parameterized type checks.
  assert Comparable.class.isAssignableFrom(elementType) : elementType;
  this.elementType   = elementType;
  this.elementCode   = getEnumConstant(elementType);
  this.isMinIncluded = isMinIncluded;
  this.isMaxIncluded = isMaxIncluded;
  if (!isMinIncluded && !isMaxIncluded) {
    /*
     * We do not localize this error message because it may disaspear
     * in a future SIS version if we decide to support closed intervals.
     */
    throw new IllegalArgumentException("Open intervals are not yet supported.");
  }
}

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

/**
 * Constructs an initially empty set of ranges.
 * This constructor is provided for sub-classing only.
 * Client code should use the static {@link #create(Class, boolean, boolean)} method instead.
 *
 * @param elementType    the type of the range elements.
 * @param isMinIncluded  {@code true} if the minimal values are inclusive, or {@code false} if exclusive.
 * @param isMaxIncluded  {@code true} if the maximal values are inclusive, or {@code false} if exclusive.
 */
protected RangeSet(final Class<E> elementType, final boolean isMinIncluded, final boolean isMaxIncluded) {
  ArgumentChecks.ensureNonNull("elementType", elementType);
  // Following assertion may fail only if the user bypass the parameterized type checks.
  assert Comparable.class.isAssignableFrom(elementType) : elementType;
  this.elementType   = elementType;
  this.elementCode   = getEnumConstant(elementType);
  this.isMinIncluded = isMinIncluded;
  this.isMaxIncluded = isMaxIncluded;
  if (!isMinIncluded && !isMaxIncluded) {
    /*
     * We do not localize this error message because it may disaspear
     * in a future SIS version if we decide to support closed intervals.
     */
    throw new IllegalArgumentException("Open intervals are not yet supported.");
  }
}

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

switch (getEnumConstant(value.getClass())) {
  default: {
    final double doubleValue = value.doubleValue();

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

switch (getEnumConstant(value.getClass())) {
  default: {
    final double doubleValue = value.doubleValue();

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

/**
 * Creates a sequence of the given type.
 */
static Vector createSequence(final Class<? extends Number> type, final Number first, final Number increment, final int length) {
  final int t = Numbers.getEnumConstant(type);
  if (t >= Numbers.BYTE && t <= Numbers.LONG) {
    // Use the long type if possible because not all long values can be represented as double.
    return new SequenceVector.Longs(type, first, increment, length);
  } else {
    return new SequenceVector.Doubles(type, first, increment, length);
  }
}

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

/**
 * Verifies that a value of the given type can be casted to the expected type.
 * The expected type must be one of the {@link Numbers} constants.
 */
final void verifyType(final Class<? extends Number> type, final byte expected) {
  final byte t = Numbers.getEnumConstant(type);
  if (t < Numbers.BYTE || t > expected) {
    throw new ClassCastException(Errors.format(Errors.Keys.CanNotConvertFromType_2,
      type, Numbers.wrapperToPrimitive(getElementType())));
  }
}

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

return (T) value;
switch (getEnumConstant(type)) {
  case CHARACTER: {

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

/**
 * Verifies that a value of the given type can be casted to the expected type.
 * The expected type must be one of the {@link Numbers} constants.
 */
final void verifyType(final Class<? extends Number> type, final byte expected) {
  final byte t = Numbers.getEnumConstant(type);
  if (t < Numbers.BYTE || t > expected) {
    throw new ClassCastException(Errors.format(Errors.Keys.CanNotConvertFromType_2,
      type, Numbers.wrapperToPrimitive(getElementType())));
  }
}

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

return (T) value;
switch (getEnumConstant(type)) {
  case CHARACTER: {

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

switch (getEnumConstant(type)) {
  case BYTE:        number = (N) Byte      .valueOf((byte)  value); break;
  case SHORT:       number = (N) Short     .valueOf((short) value); break;

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

switch (getEnumConstant(type)) {
  case BYTE:        number = (N) Byte      .valueOf((byte)  value); break;
  case SHORT:       number = (N) Short     .valueOf((short) value); break;

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

switch (getEnumConstant(type)) {
  case BYTE:        number = (N) Byte      .valueOf((byte)   value); break;
  case SHORT:       number = (N) Short     .valueOf((short)  value); break;

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

switch (getEnumConstant(type)) {
  case BYTE:        number = (N) Byte      .valueOf((byte)   value); break;
  case SHORT:       number = (N) Short     .valueOf((short)  value); break;

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

switch (Numbers.getEnumConstant(type)) {
  case Numbers.BYTE:    return NumberRange.create(minimum.byteValue(),  true, maximum.byteValue(),   true);
  case Numbers.SHORT:   return NumberRange.create(minimum.shortValue(), true, maximum.shortValue(),  true);

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

/**
 * Creates a sequence of the given type.
 */
static Vector createSequence(final Class<? extends Number> type, final Number first, final Number increment, final int length) {
  final int t = Numbers.getEnumConstant(type);
  if (t >= Numbers.BYTE && t <= Numbers.LONG) {
    // Use the long type if possible because not all long values can be represented as double.
    return new SequenceVector.Longs(type, first, increment, length);
  } else if (t == Numbers.FLOAT) {
    return new SequenceVector.Floats(type, first, increment, length);
  } else {
    return new SequenceVector.Doubles(type, first, increment, length);
  }
}

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

return "Dummy value for " + property + '.';
switch (Numbers.getEnumConstant(type)) {
  case Numbers.DOUBLE:  return         random.nextDouble() * 90;
  case Numbers.FLOAT:   return         random.nextFloat()  * 90f;

相关文章