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

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

      
    
Rootfs path

      
    
Size
5892 (5.8 KB)
MD5
d21c57d7ad5c4702860f77a5b8161b84
SHA1
0504fb71aa71c73355d5f4718d49d6037710a2ad
SHA256
2e8e5379b4b1d8465b51a95a1229adcc0dba4a88955167e488eba7b4809d490e
SHA512

      
    
SHA1_git
bf533b1b65ce54024043701e3be582c606719cc4
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
ValueBigint.java | 5.8 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 org.h2.api.ErrorCode; import org.h2.engine.CastDataProvider; import org.h2.message.DbException; import org.h2.util.Bits; /** * Implementation of the BIGINT data type. */ public final class ValueBigint extends Value { /** * The smallest {@code ValueLong} value. */ public static final ValueBigint MIN = get(Long.MIN_VALUE); /** * The largest {@code ValueLong} value. */ public static final ValueBigint MAX = get(Long.MAX_VALUE); /** * The largest Long value, as a BigInteger. */ public static final BigInteger MAX_BI = BigInteger.valueOf(Long.MAX_VALUE); /** * The precision in bits. */ static final int PRECISION = 64; /** * The approximate precision in decimal digits. */ public static final int DECIMAL_PRECISION = 19; /** * The maximum display size of a BIGINT. * Example: -9223372036854775808 */ public static final int DISPLAY_SIZE = 20; private static final int STATIC_SIZE = 100; private static final ValueBigint[] STATIC_CACHE; private final long value; static { STATIC_CACHE = new ValueBigint[STATIC_SIZE]; for (int i = 0; i < STATIC_SIZE; i++) { STATIC_CACHE[i] = new ValueBigint(i); } } private ValueBigint(long value) { this.value = value; } @Override public Value add(Value v) { long x = value; long y = ((ValueBigint) v).value; long result = x + y; /* * If signs of both summands are different from the sign of the sum there is an * overflow. */ if (((x ^ result) & (y ^ result)) < 0) { throw getOverflow(); } return ValueBigint.get(result); } @Override public int getSignum() { return Long.signum(value); } @Override public Value negate() { if (value == Long.MIN_VALUE) { throw getOverflow(); } return ValueBigint.get(-value); } private DbException getOverflow() { return DbException.get(ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_1, Long.toString(value)); } @Override public Value subtract(Value v) { long x = value; long y = ((ValueBigint) v).value; long result = x - y; /* * If minuend and subtrahend have different signs and minuend and difference * have different signs there is an overflow. */ if (((x ^ y) & (x ^ result)) < 0) { throw getOverflow(); } return ValueBigint.get(result); } @Override public Value multiply(Value v) { long x = value; long y = ((ValueBigint) v).value; long result = x * y; // Check whether numbers are large enough to overflow and second value != 0 if ((Math.abs(x) | Math.abs(y)) >>> 31 != 0 && y != 0 // Check with division && (result / y != x // Also check the special condition that is not handled above || x == Long.MIN_VALUE && y == -1)) { throw getOverflow(); } return ValueBigint.get(result); } @Override public Value divide(Value v, TypeInfo quotientType) { long y = ((ValueBigint) v).value; if (y == 0) { throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getTraceSQL()); } long x = value; if (x == Long.MIN_VALUE && y == -1) { throw getOverflow(); } return ValueBigint.get(x / y); } @Override public Value modulus(Value v) { ValueBigint other = (ValueBigint) v; if (other.value == 0) { throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getTraceSQL()); } return ValueBigint.get(this.value % other.value); } @Override public StringBuilder getSQL(StringBuilder builder, int sqlFlags) { if ((sqlFlags & NO_CASTS) == 0 && value == (int) value) { return builder.append("CAST(").append(value).append(" AS BIGINT)"); } return builder.append(value); } @Override public TypeInfo getType() { return TypeInfo.TYPE_BIGINT; } @Override public int getValueType() { return BIGINT; } @Override public byte[] getBytes() { byte[] b = new byte[8]; Bits.writeLong(b, 0, getLong()); return b; } @Override public long getLong() { return value; } @Override public BigDecimal getBigDecimal() { return BigDecimal.valueOf(value); } @Override public float getFloat() { return value; } @Override public double getDouble() { return value; } @Override public int compareTypeSafe(Value o, CompareMode mode, CastDataProvider provider) { return Long.compare(value, ((ValueBigint) o).value); } @Override public String getString() { return Long.toString(value); } @Override public int hashCode() { return (int) (value ^ (value >> 32)); } /** * Get or create a BIGINT value for the given long. * * @param i the long * @return the value */ public static ValueBigint get(long i) { if (i >= 0 && i < STATIC_SIZE) { return STATIC_CACHE[(int) i]; } return (ValueBigint) Value.cache(new ValueBigint(i)); } @Override public boolean equals(Object other) { return other instanceof ValueBigint && value == ((ValueBigint) other).value; } }
Detected license expression

      
    
Detected license expression (SPDX)

      
    
Percentage of license text
1.72
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