Re: Mathematical set operations in Java / searching for library
mowsen@googlemail.com writes:
thanks. i'm not quite sure, but is it possible to define for
example all natural numbers easily with enumset/set?!
The set of all Java Integer objects (just written - never
compiled, so there will still be errors, but you get the idea):
class Integers extends java.util.AbstractSet implements java.util.Set
{ public Integers(){} @java.lang.Override
public void clear(){ throw new java.lang.UnsupportedOperationException; }
@java.lang.Override public boolean contains( final java.lang.Object key )
{ return java.lang.Integer.class.isAssignableFrom( key.getClass()); }
@java.lang.Override public boolean remove( final java.lang.Object key )
{ throw new java.lang.UnsupportedOperationException; }
@java.lang.Override public int size()
{ return java.lang.Integer.MAX_VALUE; }
@java.lang.Override public boolean add( final java.lang.Object arg0 )
{ throw new java.lang.UnsupportedOperationException; }
@java.lang.Override public java.util.Iterator iterator()
{ return new java.util.Iterator()
{ int i = java.lang.Integer.MIN_VALUE;
public boolean hasNext(){ return i + 1 > i; }
public java.lang.Object next(){ return ++i; } public void remove()
{ throw new java.lang.UnsupportedOperationException; }}}}
Mathematical integers can not all be represented as distinct
objects or values by a computer, because they are not limited
in size, so a storage for a single mathematical integer value
would need to have more states the possible different states
of our whole universe. This also holds for storages of sets of
mathematical integers.