lp.unit
Class EmptyProgram

java.lang.Object
  extended by lp.unit.EmptyProgram
All Implemented Interfaces:
Iterable<LpRule>, Collection<LpRule>, Set<LpRule>, LogicProgram

 class EmptyProgram
extends Object
implements LogicProgram

An efficient implementation of an empty logic program that is immutable. May be useful in some cases :o)

Version:
1.0.0
Author:
Martin Slota
See Also:
LogicProgram, DynamicLogicProgram

Field Summary
private static Object[] AS_ARRAY
          Empty array used to return the program as an of rules.
private static EmptyProgram instance
          The singleton instance.
private static Iterator<LpRule> ITR
          A static iterator over an empty collection of rules.
 
Constructor Summary
private EmptyProgram()
          A private constructor because this class is a singleton.
 
Method Summary
 boolean add(LpRule r)
          Throws an UnsupportedOperationException.
 boolean addAll(Collection<? extends LpRule> c)
          Throws an UnsupportedOperationException.
 void clear()
          Throws an UnsupportedOperationException.
 boolean contains(Object o)
          Returns false.
 boolean containsAll(Collection<?> c)
          Returns the same as c.isEmpty().
 boolean equals(Object obj)
          Returns true iff obj implements the LogicProgram interface and contains no rules.
 LpRule get(int index)
          Throws an IndexOutOfBoundsException.
static EmptyProgram getInstance()
          Returns the singleton instance.
 int hashCode()
          Returns the hash code of an empty set.
 boolean isEmpty()
          Returns true.
 boolean isGround()
          Returns true.
 Iterator<LpRule> iterator()
          Returns the iterator for this empty collection.
 boolean remove(Object o)
          Throws an UnsupportedOperationException.
 boolean removeAll(Collection<?> c)
          Throws an UnsupportedOperationException.
 boolean retainAll(Collection<?> c)
          Throws an UnsupportedOperationException.
 int size()
          Returns 0.
 Object[] toArray()
          Returns an empty array.
<T> T[]
toArray(T[] a)
          Returns an empty array.
 String toString()
          Returns the string "[]".
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

instance

private static EmptyProgram instance
The singleton instance.


ITR

private static final Iterator<LpRule> ITR
A static iterator over an empty collection of rules.


AS_ARRAY

private static final Object[] AS_ARRAY
Empty array used to return the program as an of rules.

Constructor Detail

EmptyProgram

private EmptyProgram()
A private constructor because this class is a singleton.

Method Detail

getInstance

public static EmptyProgram getInstance()
Returns the singleton instance.

Returns:
the singleton instance of EmptyProgram

size

public int size()
Returns 0.

Specified by:
size in interface Collection<LpRule>
Specified by:
size in interface Set<LpRule>
Returns:
0

isEmpty

public boolean isEmpty()
Returns true.

Specified by:
isEmpty in interface Collection<LpRule>
Specified by:
isEmpty in interface Set<LpRule>
Returns:
true

contains

public boolean contains(Object o)
Returns false.

Specified by:
contains in interface Collection<LpRule>
Specified by:
contains in interface Set<LpRule>
Parameters:
o - the object to look for (cannot be contained in an empty collection)
Returns:
false

iterator

public Iterator<LpRule> iterator()
Returns the iterator for this empty collection.

Specified by:
iterator in interface Iterable<LpRule>
Specified by:
iterator in interface Collection<LpRule>
Specified by:
iterator in interface Set<LpRule>
Returns:
the iterator for this empty collection

toArray

public Object[] toArray()
Returns an empty array.

Specified by:
toArray in interface Collection<LpRule>
Specified by:
toArray in interface Set<LpRule>
Returns:
an empty array

toArray

public <T> T[] toArray(T[] a)
Returns an empty array.

Specified by:
toArray in interface Collection<LpRule>
Specified by:
toArray in interface Set<LpRule>
Returns:
an empty array

add

public boolean add(LpRule r)
Throws an UnsupportedOperationException.

Specified by:
add in interface Collection<LpRule>
Specified by:
add in interface Set<LpRule>
Parameters:
r - the rule to add
Throws:
UnsupportedOperationException - always

remove

public boolean remove(Object o)
Throws an UnsupportedOperationException.

Specified by:
remove in interface Collection<LpRule>
Specified by:
remove in interface Set<LpRule>
Parameters:
o - the rule to remove
Throws:
UnsupportedOperationException - always

containsAll

public boolean containsAll(Collection<?> c)
Returns the same as c.isEmpty().

Specified by:
containsAll in interface Collection<LpRule>
Specified by:
containsAll in interface Set<LpRule>
Returns:
as specified above

addAll

public boolean addAll(Collection<? extends LpRule> c)
Throws an UnsupportedOperationException.

Specified by:
addAll in interface Collection<LpRule>
Specified by:
addAll in interface Set<LpRule>
Parameters:
c - the collection of rules to add
Throws:
UnsupportedOperationException - always

removeAll

public boolean removeAll(Collection<?> c)
Throws an UnsupportedOperationException.

Specified by:
removeAll in interface Collection<LpRule>
Specified by:
removeAll in interface Set<LpRule>
Parameters:
c - the collection of rules to remove
Throws:
UnsupportedOperationException - always

retainAll

public boolean retainAll(Collection<?> c)
Throws an UnsupportedOperationException.

Specified by:
retainAll in interface Collection<LpRule>
Specified by:
retainAll in interface Set<LpRule>
Parameters:
c - the collection of rules to retain
Throws:
UnsupportedOperationException - always

get

public LpRule get(int index)
Throws an IndexOutOfBoundsException.

Specified by:
get in interface LogicProgram
Parameters:
index - the index of the rule to return
Throws:
IndexOutOfBoundsException - always

clear

public void clear()
Throws an UnsupportedOperationException.

Specified by:
clear in interface Collection<LpRule>
Specified by:
clear in interface Set<LpRule>
Throws:
UnsupportedOperationException - always

equals

public boolean equals(Object obj)
Returns true iff obj implements the LogicProgram interface and contains no rules.

Specified by:
equals in interface Collection<LpRule>
Specified by:
equals in interface Set<LpRule>
Overrides:
equals in class Object
Parameters:
obj - the object to compare with
Returns:
as specified above

hashCode

public int hashCode()
Returns the hash code of an empty set.

Specified by:
hashCode in interface Collection<LpRule>
Specified by:
hashCode in interface Set<LpRule>
Overrides:
hashCode in class Object
Returns:
the hash code of an empty set
See Also:
Collections.emptySet()

isGround

public boolean isGround()
Returns true.

Specified by:
isGround in interface LogicProgram
Returns:
true
See Also:
LpGroundDecider.isGround(LpStructureUnit)

toString

public String toString()
Returns the string "[]".

Overrides:
toString in class Object
Returns:
the string "[]"