All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.commons.util.SegmentAwareKey Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.commons.util;

import java.util.Objects;

/**
 * Encapsulates the key and its segment.
 *
 * @author Pedro Ruivo
 * @since 12
 */
public class SegmentAwareKey {

   private final K key;
   private final int segment;

   public SegmentAwareKey(K key, int segment) {
      this.key = Objects.requireNonNull(key);
      this.segment = segment;
   }

   public K getKey() {
      return key;
   }

   public int getSegment() {
      return segment;
   }

   @Override
   public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      SegmentAwareKey that = (SegmentAwareKey) o;
      return segment == that.segment && key.equals(that.key);
   }

   @Override
   public int hashCode() {
      return Objects.hash(key, segment);
   }

   @Override
   public String toString() {
      return "SegmentAwareKey{" +
            "key=" + Util.toStr(key) +
            ", segment=" + segment +
            '}';
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy