blob: 2f013f7f3315a4e6483a6720f03d2ac2e87d3c26 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.johnzon.core;
import java.math.BigDecimal;
import java.math.BigInteger;
import javax.json.JsonNumber;
final class JsonLongImpl implements JsonNumber {
private final long value;
JsonLongImpl(final long value) {
this.value = value;
}
@Override
public boolean isIntegral() {
return true;
}
@Override
public int intValue() {
return (int) value;
}
@Override
public int intValueExact() {
return intValue();
}
@Override
public long longValue() {
return value;
}
@Override
public long longValueExact() {
return value;
}
@Override
public BigInteger bigIntegerValue() {
return new BigInteger(toString());
}
@Override
public BigInteger bigIntegerValueExact() {
return bigIntegerValue();
}
@Override
public double doubleValue() {
return value;
}
@Override
public BigDecimal bigDecimalValue() {
return new BigDecimal(toString());
}
@Override
public ValueType getValueType() {
return ValueType.NUMBER;
}
@Override
public String toString() {
return Long.toString(value);
}
@Override
public int hashCode() {
return (int) value;
}
@Override
public boolean equals(final Object obj) {
return JsonNumber.class.isInstance(obj) && JsonNumber.class.cast(obj).longValue() == value;
}
}