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

com.intenthq.icicle.Id Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package com.intenthq.icicle;

/**
 * Represents an ID that can be used to store records in the immutable data-store with strong
 * guarantees of k-ordering.
 */
public class Id {
  /**
   * A long value representing an ID as generated by the IdGenerator.
   */
  private final long id;

  /**
   * The timestamp this ID was created at, in milliseconds.
   */
  private final long time;

  public Id(final long id, final long time) {
    this.id = id;
    this.time = time;
  }

  public long getId() {
    return id;
  }

  public long getTime() {
    return time;
  }

  @Override
  public String toString() {
    return Long.toString(id);
  }

  public String toBinaryString() {
    StringBuilder sb = new StringBuilder();

    for(int i = 0; i < Long.numberOfLeadingZeros(id); i++) {
      sb.append('0');
    }

    sb.append(Long.toBinaryString(id));
    return sb.toString();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy