net.sourceforge.msscodefactory.cfbam.v2_7.CFBamRam.CFBamRamClusterId64Gen.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfbam.v2_7.CFBamRam.CFBamRamClusterId64Gen.java

Source

// Description: Java 8 implementation of a Cluster 64-bit RAM Id Generator object.

/*
 *   CFBam
 *
 *   Copyright (c) 2014-2016 Mark Sobkow
 *   
 *   Licensed 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 net.sourceforge.msscodefactory.cfbam.v2_7.CFBamRam;

import java.lang.reflect.*;
import java.io.*;
import java.math.*;
import java.net.*;
import java.rmi.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cflib.v2_7.CFLib.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_7.CFSecurity.*;
import net.sourceforge.msscodefactory.cfinternet.v2_7.CFInternet.*;
import net.sourceforge.msscodefactory.cfbam.v2_7.CFBam.*;

/*
 *   CFBamRamClusterId64Gen RAM 64-bit Id Generator for Cluster
 */
public class CFBamRamClusterId64Gen implements Comparable<Object>, Serializable {

    protected long requiredId;
    protected short sliceId = 0;
    protected long nextId = 1L;

    public CFBamRamClusterId64Gen() {
        requiredId = CFSecurityClusterBuff.ID_INIT_VALUE;
        sliceId = 0;
        nextId = 1L;
    }

    public long getNextId() {
        long retNext = nextId++;
        return (retNext);
    }

    public long getRequiredId() {
        return (requiredId);
    }

    public void setRequiredId(long value) {
        if (value < CFSecurityClusterBuff.ID_MIN_VALUE) {
            throw CFLib.getDefaultExceptionFactory().newArgumentUnderflowException(getClass(), "setRequiredId", 1,
                    "value", value, CFSecurityClusterBuff.ID_MIN_VALUE);
        }
        requiredId = value;
    }

    public short getRequiredSliceId() {
        return (sliceId);
    }

    public void setRequiredSliceId(short value) {
        sliceId = value;
    }

    public boolean equals(Object obj) {
        if (obj == null) {
            return (false);
        } else if (obj instanceof CFBamRamClusterId64Gen) {
            CFBamRamClusterId64Gen rhs = (CFBamRamClusterId64Gen) obj;
            if (getRequiredId() != rhs.getRequiredId()) {
                return (false);
            }
            if (getRequiredSliceId() != rhs.getRequiredSliceId()) {
                return (false);
            }
            return (true);
        } else {
            return (false);
        }
    }

    public int hashCode() {
        int hashCode = 0;
        hashCode = hashCode + (int) (getRequiredId());
        hashCode = (hashCode * 0x10000) + getRequiredSliceId();
        return (hashCode & 0x7fffffff);
    }

    public int compareTo(Object obj) {
        if (obj == null) {
            return (-1);
        } else if (obj instanceof CFBamRamClusterId64Gen) {
            CFBamRamClusterId64Gen rhs = (CFBamRamClusterId64Gen) obj;
            if (getRequiredId() < rhs.getRequiredId()) {
                return (-1);
            } else if (getRequiredId() > rhs.getRequiredId()) {
                return (1);
            }
            {
                short lhsSliceId = getRequiredSliceId();
                short rhsSliceId = rhs.getRequiredSliceId();
                if (lhsSliceId < rhsSliceId) {
                    return (-1);
                } else if (lhsSliceId > rhsSliceId) {
                    return (1);
                }
            }
            return (0);
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), "compareTo", "obj",
                    obj, "CFBamClusterId64Gen");
        }
    }

    public String toString() {
        String ret = "<CFBamClusterId64Gen" + " RequiredId=" + "\"" + Long.toString(getRequiredId()) + "\""
                + ", SliceId=\"" + Short.toString(getRequiredSliceId()) + "\"" + ", NextId=\""
                + Long.toString(nextId) + "\"/>";
        return (ret);
    }
}