/** * 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); } }
/** * 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); } }
/** * 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; } }
/** * 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; } }
/** * 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."); } }
/** * 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."); } }
switch (getEnumConstant(value.getClass())) { default: { final double doubleValue = value.doubleValue();
switch (getEnumConstant(value.getClass())) { default: { final double doubleValue = value.doubleValue();
/** * 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); } }
/** * 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()))); } }
return (T) value; switch (getEnumConstant(type)) { case CHARACTER: {
/** * 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()))); } }
return (T) value; switch (getEnumConstant(type)) { case CHARACTER: {
switch (getEnumConstant(type)) { case BYTE: number = (N) Byte .valueOf((byte) value); break; case SHORT: number = (N) Short .valueOf((short) value); break;
switch (getEnumConstant(type)) { case BYTE: number = (N) Byte .valueOf((byte) value); break; case SHORT: number = (N) Short .valueOf((short) value); break;
switch (getEnumConstant(type)) { case BYTE: number = (N) Byte .valueOf((byte) value); break; case SHORT: number = (N) Short .valueOf((short) value); break;
switch (getEnumConstant(type)) { case BYTE: number = (N) Byte .valueOf((byte) value); break; case SHORT: number = (N) Short .valueOf((short) value); break;
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);
/** * 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); } }
return "Dummy value for " + property + '.'; switch (Numbers.getEnumConstant(type)) { case Numbers.DOUBLE: return random.nextDouble() * 90; case Numbers.FLOAT: return random.nextFloat() * 90f;