ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/value/ValueNumeric.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/value/ValueNumeric.java
Status
scanned
Type
file
Name
ValueNumeric.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
5886 (5.7 KB)
MD5
23f3927b6999b1b7e71433cbe60ac2ee
SHA1
7a76123131ccedc93db73fad0ef5fa998f2903d5
SHA256
caeb7148e2a78e3e1d9d7c3e617b12c7019c36e7703e7767a0022b7c4d8f7701
SHA512

      
    
SHA1_git
d70ff14c54382db2bd30fc776c58b8ba521786be
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
ValueNumeric.java | 5.7 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.value; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import org.h2.api.ErrorCode; import org.h2.engine.CastDataProvider; import org.h2.message.DbException; /** * Implementation of the NUMERIC data type. */ public final class ValueNumeric extends ValueBigDecimalBase { /** * The value 'zero'. */ public static final ValueNumeric ZERO = new ValueNumeric(BigDecimal.ZERO); /** * The value 'one'. */ public static final ValueNumeric ONE = new ValueNumeric(BigDecimal.ONE); /** * The default scale for a NUMERIC value. */ public static final int DEFAULT_SCALE = 0; /** * The maximum scale. */ public static final int MAXIMUM_SCALE = 100_000; private ValueNumeric(BigDecimal value) { super(value); if (value == null) { throw new IllegalArgumentException("null"); } int scale = value.scale(); if (scale < 0 || scale > MAXIMUM_SCALE) { throw DbException.get(ErrorCode.INVALID_VALUE_SCALE, Integer.toString(scale), "0", "" + MAXIMUM_SCALE); } } @Override public String getString() { return value.toPlainString(); } @Override public StringBuilder getSQL(StringBuilder builder, int sqlFlags) { String s = getString(); if ((sqlFlags & NO_CASTS) == 0 && s.indexOf('.') < 0 && value.compareTo(MAX_LONG_DECIMAL) <= 0 && value.compareTo(MIN_LONG_DECIMAL) >= 0) { return builder.append("CAST(").append(value).append(" AS NUMERIC(").append(value.precision()).append("))"); } return builder.append(s); } @Override public TypeInfo getType() { TypeInfo type = this.type; if (type == null) { this.type = type = new TypeInfo(NUMERIC, value.precision(), value.scale(), null); } return type; } @Override public int getValueType() { return NUMERIC; } @Override public Value add(Value v) { return get(value.add(((ValueNumeric) v).value)); } @Override public Value subtract(Value v) { return get(value.subtract(((ValueNumeric) v).value)); } @Override public Value negate() { return get(value.negate()); } @Override public Value multiply(Value v) { return get(value.multiply(((ValueNumeric) v).value)); } @Override public Value divide(Value v, TypeInfo quotientType) { BigDecimal divisor = ((ValueNumeric) v).value; if (divisor.signum() == 0) { throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getTraceSQL()); } return get(value.divide(divisor, quotientType.getScale(), RoundingMode.HALF_DOWN)); } @Override public Value modulus(Value v) { ValueBigDecimalBase dec = (ValueNumeric) v; if (dec.value.signum() == 0) { throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getTraceSQL()); } return get(value.remainder(dec.value)); } @Override public int compareTypeSafe(Value o, CompareMode mode, CastDataProvider provider) { return value.compareTo(((ValueNumeric) o).value); } @Override public int getSignum() { return value.signum(); } @Override public BigDecimal getBigDecimal() { return value; } @Override public float getFloat() { return value.floatValue(); } @Override public double getDouble() { return value.doubleValue(); } @Override public int hashCode() { return getClass().hashCode() * 31 + value.hashCode(); } @Override public boolean equals(Object other) { return other instanceof ValueNumeric && value.equals(((ValueNumeric) other).value); } @Override public int getMemory() { return value.precision() + 120; } /** * Get or create a NUMERIC value for the given big decimal. * * @param dec the big decimal * @return the value */ public static ValueNumeric get(BigDecimal dec) { if (BigDecimal.ZERO.equals(dec)) { return ZERO; } else if (BigDecimal.ONE.equals(dec)) { return ONE; } return (ValueNumeric) Value.cache(new ValueNumeric(dec)); } /** * Get or create a NUMERIC value for the given big decimal with possibly * negative scale. If scale is negative, it is normalized to 0. * * @param dec * the big decimal * @return the value */ public static ValueNumeric getAnyScale(BigDecimal dec) { if (dec.scale() < 0) { dec = dec.setScale(0, RoundingMode.UNNECESSARY); } return get(dec); } /** * Get or create a NUMERIC value for the given big integer. * * @param bigInteger the big integer * @return the value */ public static ValueNumeric get(BigInteger bigInteger) { if (bigInteger.signum() == 0) { return ZERO; } else if (BigInteger.ONE.equals(bigInteger)) { return ONE; } return (ValueNumeric) Value.cache(new ValueNumeric(new BigDecimal(bigInteger))); } /** * Set the scale of a BigDecimal value. * * @param bd the BigDecimal value * @param scale the new scale * @return the scaled value */ public static BigDecimal setScale(BigDecimal bd, int scale) { if (scale < 0 || scale > MAXIMUM_SCALE) { throw DbException.getInvalidValueException("scale", scale); } return bd.setScale(scale, RoundingMode.HALF_UP); } }
Detected license expression

      
    
Detected license expression (SPDX)

      
    
Percentage of license text
1.8
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License expression License clue details
(mpl-2.0 OR epl-1.0) AND proprietary-license {'score': 20.37, 'matcher': '3-seq', 'end_line': 3, 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'from_file': None, 'start_line': 2, 'matched_text': ' * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,\n * and the EPL 1.0 (https://h2database.com/html/license.html).', 'match_coverage': 20.37, 'matched_length': 11, 'rule_relevance': 100, 'rule_identifier': 'mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'license_expression': '(mpl-2.0 OR epl-1.0) AND proprietary-license', 'license_expression_spdx': '(MPL-2.0 OR EPL-1.0) AND LicenseRef-scancode-proprietary-license'}
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220