001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase.util; 020 021import org.apache.yetus.audience.InterfaceAudience; 022 023 /** 024 * This implementation is not smart and just treats nonce group and nonce as random bits. 025 */ 026 // TODO: we could use pure byte arrays, but then we wouldn't be able to use hash map. 027@InterfaceAudience.Private 028public class NonceKey { 029 private long group; 030 private long nonce; 031 032 public NonceKey(long group, long nonce) { 033 this.group = group; 034 this.nonce = nonce; 035 } 036 037 @Override 038 public boolean equals(Object obj) { 039 if (obj == null || !(obj instanceof NonceKey)) { 040 return false; 041 } 042 NonceKey nk = ((NonceKey)obj); 043 return this.nonce == nk.nonce && this.group == nk.group; 044 } 045 046 @Override 047 public int hashCode() { 048 return (int)((group >> 32) ^ group ^ (nonce >> 32) ^ nonce); 049 } 050 051 @Override 052 public String toString() { 053 return "[" + group + ":" + nonce + "]"; 054 } 055 056 public long getNonceGroup() { 057 return group; 058 } 059 060 public long getNonce() { 061 return nonce; 062 } 063}