Genuts API

com.genuts.gameui.util
Class SpriteChecker

java.lang.Object
  extended bycom.genuts.gameui.util.SpriteChecker

public class SpriteChecker
extends java.lang.Object

This class implements a sprites checker to store an uniq instance of sprites.

An instance of SpriteChecker has two parameters that affect its efficiency: its capacity and its load factor. The load factor should be between 0.0 and 1.0. When the number of entries in the sprites checker exceeds the product of the load factor and the current capacity, the capacity is increased by calling the rehash method. Larger load factors use memory more efficiently, at the expense of larger expected time per lookup.

If many entries are to be made into a SpriteChecker, creating it with a sufficiently large capacity may allow the entries to be inserted more efficiently than letting it perform automatic rehashing as needed to grow the table.


Nested Class Summary
 class SpriteChecker.HashSimpleVector
          Vector specialy designed for HashEntry.
(package private)  class SpriteChecker.HashtableEntry
          Sprites Checker collision list.
(package private)  class SpriteChecker.SpriteCheckerEnumerator
          A sprites checker enumerator class.
 
Field Summary
protected  int count
          The total number of entries in the sprites checker.
protected  SpriteChecker.HashSimpleVector freeEntries
          Unused HashEntry
protected  float loadFactor
          The load factor for the sprites checker.
protected  SpriteChecker.HashtableEntry[] table
          The sprites checker data.
protected  int threshold
          Rehashes the table when count exceeds this threshold.
 
Constructor Summary
SpriteChecker()
          Constructs a new, empty sprites checker with a default capacity and load factor.
SpriteChecker(int initialCapacity)
          Constructs a new, empty sprites checker with the specified initial capacity and default load factor.
SpriteChecker(int initialCapacity, float loadFactor)
          Constructs a new, empty sprites checker with the specified initial capacity and the specified load factor.
 
Method Summary
 void clear()
          Clears this sprites checker so that it contains no sprites.
 boolean contains(Sprite sprite)
          Tests if the specified sprite is contained in this sprites checker.
 boolean isEmpty()
          Tests if this sprites checker is empty.
static void main(java.lang.String[] args)
           
protected  void rehash()
          Rehashes the contents of the sprites checker into a checker with a larger capacity.
 boolean remove(Sprite sprite)
          Removes the sprite from this sprites checker.
 int size()
          Returns the number of sprites in this sprites checker.
 java.util.Enumeration sprites()
          Returns an enumeration of contains sprites in this sprites checker.
 boolean store(Sprite sprite)
          Stores the specified sprite in this sprites checker.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

table

protected SpriteChecker.HashtableEntry[] table
The sprites checker data.


freeEntries

protected SpriteChecker.HashSimpleVector freeEntries
Unused HashEntry


count

protected int count
The total number of entries in the sprites checker.


threshold

protected int threshold
Rehashes the table when count exceeds this threshold.


loadFactor

protected float loadFactor
The load factor for the sprites checker.

Constructor Detail

SpriteChecker

public SpriteChecker(int initialCapacity,
                     float loadFactor)
Constructs a new, empty sprites checker with the specified initial capacity and the specified load factor.

Parameters:
initialCapacity - the initial capacity of the sprites checker.
loadFactor - a number between 0.0 and 1.0.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than or equal to zero, or if the load factor is less than or equal to zero.

SpriteChecker

public SpriteChecker(int initialCapacity)
Constructs a new, empty sprites checker with the specified initial capacity and default load factor.

Parameters:
initialCapacity - the initial capacity of the sprites checker.

SpriteChecker

public SpriteChecker()
Constructs a new, empty sprites checker with a default capacity and load factor.

Method Detail

size

public int size()
Returns the number of sprites in this sprites checker.

Returns:
the number of sprites in this sprites checker.

isEmpty

public boolean isEmpty()
Tests if this sprites checker is empty.

Returns:
true if this sprites checker contains no sprites, false otherwise.

sprites

public java.util.Enumeration sprites()
Returns an enumeration of contains sprites in this sprites checker.

Returns:
an enumeration of the keys in this sprites checker.
See Also:
Enumeration

contains

public boolean contains(Sprite sprite)
Tests if the specified sprite is contained in this sprites checker.

Parameters:
sprite - Sprite to check.
Returns:
true if the specified sprite is contained in this sprites checker, false otherwise.
Since:
JDK1.0

rehash

protected void rehash()
Rehashes the contents of the sprites checker into a checker with a larger capacity. This method is called automatically when the number of keys in the checker exceeds this sprites checker's capacity and load factor.

Since:
JDK1.0

store

public boolean store(Sprite sprite)
Stores the specified sprite in this sprites checker. The sprite be null.

Parameters:
sprite - the sprite to store.
Returns:
true if the sprite was already stored in this sprite checker, false otherwise.
Throws:
java.lang.NullPointerException - if the sprite is null.

remove

public boolean remove(Sprite sprite)
Removes the sprite from this sprites checker. This method does nothing if the sprite is not in the sprites checker.

Parameters:
sprite - the sprite that needs to be removed.
Returns:
true if the sprite was removed from this sprite checker, false otherwise.

clear

public void clear()
Clears this sprites checker so that it contains no sprites.


main

public static void main(java.lang.String[] args)

Genuts API

Genuts API