001/**
002 *
003 * Copyright 2019-2020 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack.datatypes;
018
019import org.jivesoftware.smack.util.DefaultCharSequence;
020
021public abstract class Scalar extends java.lang.Number implements DefaultCharSequence {
022
023    /**
024     *
025     */
026    private static final long serialVersionUID = 1L;
027
028    private final java.lang.Number number;
029
030    protected Scalar(java.lang.Number number) {
031        this.number = number;
032    }
033
034    public final Number number() {
035        return number;
036    }
037
038    @Override
039    public final int intValue() {
040        return number.intValue();
041    }
042
043    @Override
044    public final long longValue() {
045        return number.longValue();
046    }
047
048    @Override
049    public final float floatValue() {
050        return number.floatValue();
051    }
052
053    @Override
054    public final double doubleValue() {
055        return number.doubleValue();
056    }
057
058    @Override
059    public abstract int hashCode();
060
061    @Override
062    public boolean equals(Object other) {
063        if (!(other instanceof Scalar)) {
064            return false;
065        }
066
067        Scalar otherScalar = (Scalar) other;
068
069        if (longValue() == otherScalar.longValue()) {
070            return true;
071        }
072
073        if (doubleValue() == otherScalar.doubleValue()) {
074            return true;
075        }
076
077        if (floatValue() == otherScalar.floatValue()) {
078            return true;
079        }
080
081        return false;
082    }
083
084    @Override
085    public final String toString() {
086        return number.toString();
087    }
088
089    public abstract Scalar getMinValue();
090
091    public abstract Scalar getMaxValue();
092
093    public abstract Scalar incrementedByOne();
094
095}