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

de.lessvoid.nifty.NiftyIdCreator Maven / Gradle / Ivy

Go to download

Nifty GUI is a Java Library that supports the building of interactive user interfaces for games or similar applications. It utilizes OpenGL for rendering and it can be easily integrated into many rendering systems. The configuration of the GUI is stored in xml files with little supporting Java code. In short Nifty helps you to layout stuff, display it in a cool way and interact with it :)

There is a newer version: 1.4.3
Show newest version
package de.lessvoid.nifty;

import javax.annotation.Nonnull;
import java.util.concurrent.atomic.AtomicLong;

/**
 * This generator is used to create the IDs for Nifty-GUI elements that did not get a specific ID. It simply creates
 * new numbered IDs.
 *
 * @author void
 * @author Martin Karing <[email protected]>
 */
public final class NiftyIdCreator {
  /**
   * The provider for the IDs.
   */
  private static final AtomicLong nextId = new AtomicLong(1);

  /**
   * Generate a new ID.
   *
   * @return the string containing the new id.
   */
  @Nonnull
  public static String generate() {
    final long id = nextId.getAndIncrement();
    return Long.toString(id);
  }

  /**
   * Check if the ID supplied as string is a ID that is likely to be generated by this generator.
   *
   * @param stringId the string representation of the ID
   * @return {@code true} if the ID is likely a generated one, note that false positives are possible
   */
  public static boolean isGeneratedId(@Nonnull final String stringId) {
    try {
      final long id = Long.parseLong(stringId);
      final long currentId = nextId.get();
      return id < currentId;
    } catch (NumberFormatException e) {
      return false;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy