|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.cycling74.max.Atom
public abstract class Atom
An element of a list or argument of a message. May contain an int, a float, or a String.
Field Summary | |
---|---|
static Atom[] |
emptyArray
A zero-length Atom array. |
Method Summary | |
---|---|
int |
compareTo(java.lang.Object o)
Determines if Object o is "bigger than" this
Atom . |
abstract boolean |
equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one. |
float |
getFloat()
Return the float contents of this Atom . |
int |
getInt()
Return the integer contents of this Atom . |
java.lang.String |
getString()
Return the String contents of this Atom . |
abstract int |
hashCode()
Returns a hash code for this Atom . |
static Atom[] |
intersection(Atom[] a,
Atom[] b)
Returns the intersection of two Atom arrays. |
boolean |
isFloat()
Does this Atom represent a float? |
static int |
isIn(Atom item,
Atom[] atoms)
Is item in array atoms ? |
static int |
isIn(Atom item,
Atom[] atoms,
int highIdx,
int lowIdx)
Is item in array atoms
between indices highIdx and lowIdx ? |
boolean |
isInt()
Does this Atom represent an integer? |
boolean |
isString()
Does this Atom represent a String? |
static Atom |
newAtom(boolean value)
Create and return an Atom containing a int
that is either 1 or 0 depending on the value of the argument. |
static Atom[] |
newAtom(boolean[] array)
Create and return an Atom array
which represents the array of boolean s. |
static Atom |
newAtom(byte value)
Create and return an Atom containing an int . |
static Atom[] |
newAtom(byte[] array)
Create and return an Atom array
which represents the array of byte s. |
static Atom |
newAtom(char value)
Create and return an Atom containing a String
made up of a single character. |
static Atom[] |
newAtom(char[] array)
Create and return an Atom array
which represents the array of char s as String s. |
static Atom |
newAtom(double value)
Create and return an Atom containing a float . |
static Atom[] |
newAtom(double[] array)
Create and return an Atom array
which represents the array of double s. |
static Atom |
newAtom(float value)
Create and return an Atom containing a float . |
static Atom[] |
newAtom(float[] array)
Create and return an Atom array
which represents the array of float s. |
static Atom |
newAtom(int value)
Create and return an Atom containing an int . |
static Atom[] |
newAtom(int[] array)
Create and return an Atom array
which represents the array of int s. |
static Atom |
newAtom(long value)
Create and return an Atom containing an int . |
static Atom[] |
newAtom(long[] array)
Create and return an Atom array
which represents the array of long s. |
static Atom |
newAtom(short value)
Create and return an Atom containing an int . |
static Atom[] |
newAtom(short[] array)
Create and return an Atom array
which represents the array of short s. |
static Atom |
newAtom(java.lang.String value)
Create and return an Atom containing a String . |
static Atom[] |
newAtom(java.lang.String[] array)
Create and return an Atom array
which represents the array of String s. |
static Atom[] |
newAtom(java.lang.String s,
Atom[] args)
Create and return an Atom array
with the String represented in the
first Atom and the args
array after. |
static Atom[] |
parse(java.lang.String str)
Parse a String as a sequence of tokens
and return an Atom array. |
static Atom[] |
parse(java.lang.String str,
boolean skipFirst)
Parse a String as a sequence of tokens
and return an Atom
array. |
static Atom[] |
removeFirst(Atom[] atoms)
Removes the first element of an Atom array
and returns the result. |
static Atom[] |
removeFirst(Atom[] atoms,
int howMany)
Removes the first howMany elements of an Atom
array and returns the result. |
static Atom[] |
removeLast(Atom[] atoms)
Removes the last element of an Atom array
and returns the result. |
static Atom[] |
removeLast(Atom[] atoms,
int howMany)
Removes the last howMany elements of an Atom
array and returns the result. |
static Atom[] |
removeOne(Atom[] atoms,
int index)
Removes one element of an Atom array
and returns the result. |
static Atom[] |
removeSome(Atom[] atoms,
int first,
int last)
Removes some elements of an Atom array
and returns the result. |
static Atom[] |
reverse(Atom[] atoms)
Reverses the elements of an Atom array
and returns the result. |
static Atom[] |
rotate(Atom[] atoms,
int numberOfPlaces)
Rotates the elements of an Atom array
by numberOfPlaces and returns the result. |
boolean |
toBoolean()
Convert an Atom to a boolean , following the
Atom type coercion rules if necessary. |
static boolean[] |
toBoolean(Atom[] array)
Convert an Atom array to a boolean array, following the
Atom type coercion rules if necessary. |
byte |
toByte()
Converts an Atom to a byte , following the
Atom type coercion rules if necessary. |
static byte[] |
toByte(Atom[] array)
Converts an Atom array to a byte array, following the
Atom type coercion rules if necessary. |
char |
toChar()
Convert an Atom to a char , following the
Atom type coercion rules if necessary. |
static char[] |
toChar(Atom[] array)
Convert an Atom array to a char array, following the
Atom type coercion rules if necessary. |
static java.lang.String |
toDebugString(Atom[] array)
Converts an Atom array to a printed representation suitable
for debugging. |
double |
toDouble()
Convert an Atom to a double , following the
Atom type coercion rules if necessary. |
static double[] |
toDouble(Atom[] array)
Convert an Atom array to a double array, following the
Atom type coercion rules if necessary. |
float |
toFloat()
Convert an Atom to a float , following the
Atom type coercion rules if necessary. |
static float[] |
toFloat(Atom[] array)
Convert an Atom array to a float array, following the
Atom type coercion rules if necessary. |
int |
toInt()
Convert an Atom to an int , following the
Atom type coercion rules if necessary. |
static int[] |
toInt(Atom[] array)
Convert an Atom array to an int array, following the
Atom type coercion rules if necessary. |
long |
toLong()
Convert an Atom to a long , following the
Atom type coercion rules if necessary. |
static long[] |
toLong(Atom[] array)
Convert an Atom array to a long array, following the
Atom type coercion rules if necessary. |
abstract java.lang.Object |
toObject()
Return the contents of this Atom as a Java object. |
static java.lang.String |
toOneString(Atom[] array)
Convert an Atom array to a single String . |
short |
toShort()
Converts an Atom to a short , following the
Atom type coercion rules if necessary. |
static short[] |
toShort(Atom[] array)
Converts an Atom array to a short array, following the
Atom type coercion rules if necessary. |
static java.lang.String[] |
toString(Atom[] array)
Convert an Atom array to an array of String s. |
static Atom[] |
union(Atom[] a,
Atom[] b)
Returns the union of two Atom arrays. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Atom[] emptyArray
Method Detail |
---|
public static Atom newAtom(byte value)
Atom
containing an int
.
value
- the byte value to represent in the Atom
public static Atom newAtom(short value)
Atom
containing an int
.
value
- the short value to represent in the Atom
public static Atom newAtom(int value)
Atom
containing an int
.
value
- the int value to represent in the Atom
public static Atom newAtom(long value)
Atom
containing an int
.
Be careful: if the input long is bigger than Integer.MAX_VALUE
the cast from long to int will overflow.
value
- the long value to represent in the Atom
public static Atom newAtom(float value)
Atom
containing a float
.
value
- the float value to represent in the Atom
public static Atom newAtom(double value)
Atom
containing a float
.
Be careful:the reduction in numerical precision when casting from double to float
can result in a loss of information and/or overflow.
value
- the double value to represent in the Atom
public static Atom newAtom(char value)
Atom
containing a String
made up of a single character.
value
- the character to represent in the Atom
public static Atom newAtom(java.lang.String value)
Atom
containing a String
.
value
- the String to represent in the Atom
public static Atom newAtom(boolean value)
Atom
containing a int
that is either 1 or 0 depending on the value of the argument.
value
- the boolean to represent in the Atom
public static Atom[] newAtom(byte[] array)
Atom
array
which represents the array of byte
s.
array
- the byte array to represent in the Atoms
public static Atom[] newAtom(short[] array)
Atom
array
which represents the array of short
s.
array
- the short array to represent in the Atoms
public static Atom[] newAtom(int[] array)
Atom
array
which represents the array of int
s.
array
- the int array to represent in the Atoms
public static Atom[] newAtom(long[] array)
Atom
array
which represents the array of long
s.
Be careful: if an input long is bigger than Integer.MAX_VALUE
the cast from long to int will overflow.
array
- the long array to represent in the Atoms
public static Atom[] newAtom(float[] array)
Atom
array
which represents the array of float
s.
array
- the float array to represent in the Atoms
public static Atom[] newAtom(double[] array)
Atom
array
which represents the array of double
s.
Be careful:the reduction in numerical precision when casting from double to float
can result in a loss of information and/or overflow.
array
- the double array to represent in the Atoms
public static Atom[] newAtom(char[] array)
Atom
array
which represents the array of char
s as String
s.
array
- the character array to represent in the Atoms
public static Atom[] newAtom(java.lang.String[] array)
Atom
array
which represents the array of String
s.
array
- the String array to represent in the Atoms
public static Atom[] newAtom(java.lang.String s, Atom[] args)
Atom
array
with the String
represented in the
first Atom
and the args
array after. Useful for forwarding an anything
message to a method like list that takes an
Atom
array.
s
- the first element of the Atom arrayargs
- all the other elements of the Atom array
public static Atom[] newAtom(boolean[] array)
Atom
array
which represents the array of boolean
s.
array
- the boolean array to represent in the Atoms
public boolean isInt()
Atom
represent an integer?
int
)public boolean isFloat()
Atom
represent a float?
float
public boolean isString()
Atom
represent a String?
String
public float getFloat()
float
contents of this Atom
.
float
value represented in the Atom
java.lang.UnsupportedOperationException
- if the
Atom
does not represent a float
.public int getInt()
Atom
.
int
value represented in the Atom
.
java.lang.UnsupportedOperationException
- if the
Atom
does not represent an int
.public java.lang.String getString()
String
contents of this Atom
.
String
value represented in the Atom
.
java.lang.UnsupportedOperationException
- if this Atom
does not represent a String
.public abstract java.lang.Object toObject()
Atom
as a Java object.
If it contains an int
, return an Integer
object;
if it contains a float
, return a Float
object;
and if it contains a String
, return a String
.
Atom
as an Object
.public abstract boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the other Object
to test for equivalence
true
if and only if the other
Object
is an Atom
of the same
content type (float
, int
, or String
)
with equal contents.public abstract int hashCode()
Atom
.
For an Atom
that represents an int
,
the value returned is the int
value itself. For an Atom
that represents a
float
the result is the integer bit
representation produced by the Float.floatToIntBits(float)
method. For an Atom
that represents a String
the result is the integer bit
representation produced by the String.hashCode()
method.
hashCode
in class java.lang.Object
Atom
's content type.public static Atom[] reverse(Atom[] atoms)
Atom
array
and returns the result.
atoms
- the array of Atom
s to operate on
atoms
parameterpublic static Atom[] rotate(Atom[] atoms, int numberOfPlaces)
Atom
array
by numberOfPlaces
and returns the result.
atoms
- the array of Atom
s to operate onnumberOfPlaces
- the number of places to rotate the array
by (can be negative)
atoms
parameterpublic static Atom[] intersection(Atom[] a, Atom[] b)
Atom
arrays.
a
- an array of Atom
s to operate onb
- another array of Atom
s to operate on
a
and b
public static Atom[] union(Atom[] a, Atom[] b)
Atom
arrays.
a
- an array of Atom
s to operate onb
- another array of Atom
s to operate on
a
and b
public static int isIn(Atom item, Atom[] atoms)
item
in array atoms
?
item
- the Atom
to search foratoms
- the array of Atom
s to search
public static int isIn(Atom item, Atom[] atoms, int highIdx, int lowIdx)
item
in array atoms
between indices highIdx
and lowIdx
?
item
- the Atom
to search foratoms
- the array of Atom
s to searchhighIdx
- the highest index of the array to checklowIdx
- the lowest index of the array to check
public static Atom[] removeOne(Atom[] atoms, int index)
Atom
array
and returns the result.
If atoms
has length of zero, returns it unchanged.
atoms
- the array of Atom
s to operate onindex
- the index of the element to remove
atoms
parameter, with the
index element removedpublic static Atom[] removeSome(Atom[] atoms, int first, int last)
Atom
array
and returns the result.
If atoms
has length of zero, returns it unchanged.
atoms
- the array of Atom
s to operate onfirst
- the index of the first element of the range to removelast
- the index of the last element of the range to remove
atoms
parameter, with all elements
between first and last (inclusive) removedpublic static Atom[] removeFirst(Atom[] atoms)
Atom
array
and returns the result.
If atoms
has length of zero, returns it unchanged.
If atoms
has a length of one, returns the
emptyArray
.
atoms
- the array of Atom
s to operate on
atoms
parameter, one element removed
from the leftpublic static Atom[] removeFirst(Atom[] atoms, int howMany)
howMany
elements of an Atom
array and returns the result.
If atoms
has length of zero, returns
it unchanged.
If atoms
has length of howMany
, returns the
emptyArray
.
atoms
- the Atom
array to operate onhowMany
- the number of elements to remove
atoms
parameter, howMany
elements removed from the left
java.lang.IllegalArgumentException
- If howMany is a negative
amount or more than the array's length.public static Atom[] removeLast(Atom[] atoms)
Atom
array
and returns the result.
If atoms
has length of zero, returns it unchanged.
If atoms
has a length of one, returns the
emptyArray
.
atoms
- the array of Atom
s to operate on
atoms
parameter, one element removed
from the leftpublic static Atom[] removeLast(Atom[] atoms, int howMany)
howMany
elements of an Atom
array and returns the result.
If atoms
has length of zero, returns
it unchanged.
If atoms
has length of howMany
, returns the
emptyArray
.
atoms
- the Atom
array to operate onhowMany
- the number of elements to remove
atoms
parameter, howMany
elements removed from the left
java.lang.IllegalArgumentException
- If howMany is a negative
amount or more than the array's length.public static java.lang.String toOneString(Atom[] array)
Atom
array to a single String
. The
resulting String
contains the result of calling
toString
on all of
the Atom
s in the array, separated by a space character.
array
- the Atom
array to convert to one String
.
String
containing representations of all of
the Atom
s in the arraypublic static java.lang.String[] toString(Atom[] array)
Atom
array to an array of String
s.
array
- the Atom
array to convert to a String
array.
String
array containing representations of all of
the Atom
s in the arraypublic byte toByte()
Atom
to a byte
, following the
Atom type coercion rules if necessary.
If the Atom represents a float
, its fractional portion
will be truncated, then the resulting int
will be cast to a byte
.
If the Atom represents a String
, 0 will be returned.
byte
that represents the value of the Atom
public static byte[] toByte(Atom[] array)
Atom
array to a byte
array, following the
Atom type coercion rules if necessary.
If the Atom represents a float
, its fractional portion
will be truncated and the resulting int
cast to a byte
.
If the Atom represents a String
, 0 will be returned.
array
- the Atom
array to convert to a byte
array.
int
array that represents the values of the
Atom
array, coerced to the integer type if necessarypublic short toShort()
Atom
to a short
, following the
Atom type coercion rules if necessary.
If the Atom represents a float
, its fractional portion
will be truncated, then the resulting int
will be cast to a short
.
If the Atom represents a String
, 0 will be returned.
short
that represents the value of the Atom
public static short[] toShort(Atom[] array)
Atom
array to a short
array, following the
Atom type coercion rules if necessary.
If the Atom represents a float
, its fractional portion
will be truncated and the resulting int
cast to a short
.
If the Atom represents a String
, 0 will be returned.
array
- the Atom
array to convert to a short
array.
short
array that represents the values of the
Atom
arraypublic int toInt()
Atom
to an int
, following the
Atom type coercion rules if necessary.
If the Atom represents a float
, its fractional portion
will be truncated. If the Atom represents a String
, 0
will be returned.
int
that represents the value of the Atom
, coerced
to the integer type if necessarypublic static int[] toInt(Atom[] array)
Atom
array to an int
array, following the
Atom type coercion rules if necessary.
If the Atom represents a float
, its fractional portion
will be truncated. If the Atom represents a String
, 0
will be returned.
array
- the Atom
array to convert to an int
array.
int
array that represents the values of the
Atom
array, coerced to the integer type if necessarypublic long toLong()
Atom
to a long
, following the
Atom type coercion rules if necessary.
If the Atom represents a float
, its fractional portion
will be truncated. If the Atom represents a String
, 0
will be returned.
long
that represents the value of the Atom
, coerced
to the long type if necessarypublic static long[] toLong(Atom[] array)
Atom
array to a long
array, following the
Atom type coercion rules if necessary.
If the Atom represents a float
, its fractional portion
will be truncated. If the Atom represents a String
, 0
will be returned.
array
- the Atom
array to convert to a long
array.
long
array that represents the values of the
Atom
arraypublic float toFloat()
Atom
to a float
, following the
Atom type coercion rules if necessary.
If the Atom represents an int
, it is converted to a float.
If the Atom represents a String
, 0.0f will be returned.
float
that represents the value of the Atom
, coerced
to the float type if necessarypublic static float[] toFloat(Atom[] array)
Atom
array to a float
array, following the
Atom type coercion rules if necessary.
If the Atom represents an int
, it is converted to a float.
If the Atom represents a String
, 0.0f will be returned.
array
- the Atom
array to convert to a float
array.
float
array that represents the values of the
Atom
array, coerced to the float
type if necessarypublic double toDouble()
Atom
to a double
, following the
Atom type coercion rules if necessary.
If the Atom represents an int
, it is converted to a double.
If the Atom represents a String
, 0.0 will be returned.
double
that represents the value of the Atom
, coerced
to the double type if necessarypublic static double[] toDouble(Atom[] array)
Atom
array to a double
array, following the
Atom type coercion rules if necessary.
If the Atom represents an int
, it is converted to a double.
If the Atom represents a String
, 0.0 will be returned.
array
- the Atom
array to convert to a double
array.
double
array that represents the values of the
Atom
array, coerced to the double
type if necessarypublic char toChar()
Atom
to a char
, following the
Atom type coercion rules if necessary.
If the Atom represents an int
or a float
,
it is cast to a char
.
If the Atom represents a String
, its first character is returned.
char
that represents the value of the Atom
public static char[] toChar(Atom[] array)
Atom
array to a char
array, following the
Atom type coercion rules if necessary.
If the Atom represents an int
or a float
,
it is cast to a char
.
If the Atom represents a String
, its first character is returned.
array
- the Atom
array to convert to a char
array
char
array that represents the values of the
Atom
arraypublic boolean toBoolean()
Atom
to a boolean
, following the
Atom type coercion rules if necessary.
If the Atom represents an int
, true is returned for all non-zero values.
If the Atom represents a float
, true is returned for all non-zero values.
If the Atom represents a String
, true is returned for all values that
aren't "false".
boolean
that represents the value of the Atom
public static boolean[] toBoolean(Atom[] array)
Atom
array to a boolean
array, following the
Atom type coercion rules if necessary.
If the Atom represents an int
, true is returned for all non-zero values.
If the Atom represents a float
, true is returned for all non-zero values.
If the Atom represents a String
, true is returned for all values that
aren't "false".
array
- the Atom
array to convert to a boolean
array.
boolean
array that represents the values of the
Atom
arraypublic static Atom[] parse(java.lang.String str)
String
as a sequence of tokens
and return an Atom
array.
str
- the String
to parse
Atom
array corresponding to the tokens in
the String
public static Atom[] parse(java.lang.String str, boolean skipFirst)
String
as a sequence of tokens
and return an Atom
array. If skipFirst
is true, do not include the first
Atom
in the result.
str
- the String
to parseskipFirst
- whether to include the first Atom
in the result
Atom
array corresponding to the tokens in
the String
public static java.lang.String toDebugString(Atom[] array)
Atom
array to a printed representation suitable
for debugging.
So if givena three-element Atom array containing the
int
1, the float
3.14 and the
String
"test" as input, the output would be
Atom[3]={1:I}{3.14:F}{test:S}
.
array
- an array of Atom
objects
String
describing the elements
of array
public int compareTo(java.lang.Object o)
Object o
is "bigger than" this
Atom
. Atom
s that
represent String
s are defined to be less than
int
s and float
s - that is, if you make use of the
Arrays.sort(Object[])
method, String
s
will be sorted first. Comparisons between Atom
s that
represent float
s and int
s give the results
you would expect.
compareTo
in interface java.lang.Comparable
o
- the Object
to compare with.
java.lang.NullPointerException
- if the input is null
java.lang.ClassCastException
- if something other than an Atom is passed
in as an argument
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |