T
- type of objects.V
- type of object values.public final class AllocationTable<T,V>
extends java.lang.Object
AllocationTable
implements a resource allocation table, which is a finite set of objects
(registers, pages, etc.) in couple with allocation / deallocation methods.Constructor and Description |
---|
AllocationTable(AllocationStrategy strategy,
java.util.Collection<T> objects)
Constructs a resource allocation table.
|
AllocationTable(AllocationStrategy strategy,
java.util.Map<java.lang.String,java.lang.String> attributes,
java.util.Collection<T> objects)
Constructs a resource allocation table.
|
AllocationTable(AllocationStrategy strategy,
java.util.Map<java.lang.String,java.lang.String> attributes,
Supplier<T> supplier)
Constructs a resource allocation table.
|
AllocationTable(AllocationStrategy strategy,
Supplier<T> supplier)
Constructs a resource allocation table.
|
Modifier and Type | Method and Description |
---|---|
T |
allocate()
Allocates an object (peeks an object and marks it as being in use).
|
T |
allocate(java.util.Set<T> exclude)
Allocates an object and marks it as being in use.
|
T |
allocateAndDefine(java.util.Set<T> exclude,
V value)
Allocates an object and defines it.
|
T |
allocateAndDefine(V value)
Allocates an object and defines it.
|
int |
countDefinedObjects()
Returns the number of defined (initialized) objects.
|
int |
countUsedObjects()
Returns the number of used objects.
|
void |
define(T object,
V value)
Defines (initializes) the object.
|
boolean |
exists(T object)
Checks whether the object exists in the allocation table.
|
void |
free(T object)
Frees (deallocates) the object.
|
java.util.Set<T> |
getAllObjects()
Returns the set of all objects.
|
Allocator |
getAllocator()
Returns the currently used allocator.
|
Supplier<T> |
getSupplier()
Returns the object generator.
|
java.util.Set<T> |
getUsedObjects()
Returns the set of used objects.
|
V |
getValue(T object)
Returns the object value (if is defined) or
null (otherwise). |
boolean |
isDefined(T object)
Checks whether the object is defined (initialized).
|
boolean |
isFree(T object)
Checks whether the object is free (belongs to the initial set of objects and not in use).
|
boolean |
isUsed(T object)
Checks whether the object is in use.
|
T |
peek()
Peeks a free object.
|
T |
peek(java.util.Set<T> exclude)
Peeks a free object.
|
void |
reset()
Resets the resource allocation table.
|
void |
setAllocator(Allocator allocator)
Replaces the current allocator with a new one.
|
int |
size()
Returns the number of available objects (both free and used).
|
java.lang.String |
toString() |
void |
use(T object)
Marks the object as being in use.
|
public AllocationTable(AllocationStrategy strategy, java.util.Map<java.lang.String,java.lang.String> attributes, java.util.Collection<T> objects)
strategy
- the allocation strategy.attributes
- the strategy parameters or null
.objects
- the collection of available objects.public AllocationTable(AllocationStrategy strategy, java.util.Collection<T> objects)
strategy
- the allocation strategy.objects
- the collection of available objects.public AllocationTable(AllocationStrategy strategy, java.util.Map<java.lang.String,java.lang.String> attributes, Supplier<T> supplier)
strategy
- the allocation strategy.attributes
- the strategy parameters or null
.supplier
- the object generator.public AllocationTable(AllocationStrategy strategy, Supplier<T> supplier)
strategy
- the allocation strategy.supplier
- the object generator.public Allocator getAllocator()
public void setAllocator(Allocator allocator)
allocator
- New allocator.java.lang.IllegalArgumentException
- if the argument is null
.public void reset()
public int size()
public int countUsedObjects()
public int countDefinedObjects()
public boolean exists(T object)
object
- the object to be checked.true
if the object exists; false
otherwise.java.lang.IllegalArgumentException
- if object
does not exist (i.e. it is unknown).public boolean isFree(T object)
object
- the object to be checked.true
if the object is free; false
otherwise.java.lang.IllegalArgumentException
- if object
is null.java.lang.IllegalArgumentException
- if object
is unknown.public boolean isUsed(T object)
object
- the object to be checked.true
if the object is in use; false
otherwise.java.lang.IllegalArgumentException
- if object
is null.java.lang.IllegalArgumentException
- if object
is unknown.public boolean isDefined(T object)
object
- the object to be checked.true
if the object is defined; false
otherwise.java.lang.IllegalArgumentException
- if object
is null.java.lang.IllegalArgumentException
- if object
is unknown.public V getValue(T object)
null
(otherwise).object
- the object whose value to be returned.null
otherwise.java.lang.IllegalArgumentException
- if object
is null.java.lang.IllegalArgumentException
- if object
is unknown.public void free(T object)
object
- the object to be freed.java.lang.IllegalArgumentException
- if object
is null.java.lang.IllegalArgumentException
- if object
is unknown.public void use(T object)
object
- the object to be used.java.lang.IllegalArgumentException
- if object
is null.java.lang.IllegalArgumentException
- if object
is unknown.public void define(T object, V value)
object
- the object to defined.value
- the object value.java.lang.IllegalArgumentException
- if object
is null or value
is null.java.lang.IllegalArgumentException
- if object
is unknown.public T peek()
java.lang.IllegalStateException
- if an object cannot be peeked.public T peek(java.util.Set<T> exclude)
exclude
- the objects that should not be peeked.java.lang.IllegalArgumentException
- if exclude
is null.java.lang.IllegalStateException
- if an object cannot be peeked.public T allocate()
java.lang.IllegalStateException
- if an object cannot be allocated.public T allocate(java.util.Set<T> exclude)
exclude
- the objects that should not be allocated.java.lang.IllegalArgumentException
- if exclude
is null.java.lang.IllegalStateException
- if an object cannot be allocated.public T allocateAndDefine(V value)
value
- the object value.java.lang.IllegalArgumentException
- if value
is null.java.lang.IllegalStateException
- if an object cannot be allocated.public T allocateAndDefine(java.util.Set<T> exclude, V value)
exclude
- the objects that should not be allocated.value
- the object value.java.lang.IllegalArgumentException
- if exclude
or value
is null.java.lang.IllegalStateException
- if an object cannot be allocated.public java.util.Set<T> getUsedObjects()
public java.util.Set<T> getAllObjects()
public Supplier<T> getSupplier()
public java.lang.String toString()
toString
in class java.lang.Object