com.cycling74.max
Class Atom

java.lang.Object
  extended by com.cycling74.max.Atom
All Implemented Interfaces:
Serializable, Comparable

public abstract class Atom
extends Object
implements Comparable, Serializable

PD element that is used in message or arguments. It can contains a float, a int (always map to a float in pd) or a string.

See Also:
Serialized Form

Field Summary
static Atom[] emptyArray
          Empty array to use with the API when theres is no arguments.
 
Method Summary
abstract  boolean equals(Object object)
          Returns true if the instance has the same value of the object object.
 float getFloat()
          Get float value for this Atom.
 int getInt()
          Get int value for this Atom.
 String getString()
          Get string value for this Atom.
abstract  int hashCode()
          Returns the hashCode representation for this Atom.
static Atom[] intersection(Atom[] first, Atom[] second)
          Don't know what this does.
 boolean isFloat()
          Returns true if the Atom has been created with a float.
static int isIn(Atom org, Atom[] list)
          Returns the index of the first atom that is found in the list.
static int isIn(Atom org, Atom[] list, int from, int to)
          Returns the index of the first atom that is found in the list.
 boolean isInt()
          Returns true if the Atom has been created with a int.
 boolean isString()
          Returns true if the Atom has been created with a String.
static Atom newAtom(boolean value)
          Creates a new atom with the specified type.
static Atom[] newAtom(boolean[] value)
          Creates a new atom with the specified type.
static Atom newAtom(byte value)
          Creates a new atom with the specified type.
static Atom[] newAtom(byte[] value)
          Creates a new atom with the specified type.
static Atom newAtom(char value)
          Creates a new atom with the specified type.
static Atom[] newAtom(char[] value)
          Creates a new atom with the specified type.
static Atom newAtom(double value)
          Creates a new atom with the specified type.
static Atom[] newAtom(double[] value)
          Creates a new atom with the specified type.
static Atom newAtom(float value)
          Creates a new atom with the specified type.
static Atom[] newAtom(float[] value)
          Creates a new atom with the specified type.
static Atom newAtom(int value)
          Creates a new atom with the specified type.
static Atom[] newAtom(int[] value)
          Creates a new atom with the specified type.
static Atom newAtom(long value)
          Creates a new atom with the specified type.
static Atom[] newAtom(long[] value)
          Creates a new atom with the specified type.
static Atom newAtom(short value)
          Creates a new atom with the specified type.
static Atom[] newAtom(short[] value)
          Creates a new atom with the specified type.
static Atom newAtom(String value)
          Creates a new atom with the specified type.
static Atom[] newAtom(String[] value)
          Creates a new atom with the specified type.
static Atom[] parse(String values)
          Creates an array of atoms from string tokens.
static Atom[] parse(String values, boolean skipfirst)
          Creates an array of atoms from strings tokens.
static Atom[] removeFirst(Atom[] list)
          Removes the first atom in the list.
static Atom[] removeFirst(Atom[] list, int howmany)
          Removes the first howmany atoms in the list.
static Atom[] removeLast(Atom[] list)
          Remove the last atom in the list.
static Atom[] removeLast(Atom[] list, int howmany)
          Removes the last howmany atoms in the list.
static Atom[] removeOne(Atom[] list, int i)
          Removes one atom in the list.
static Atom[] removeSome(Atom[] list, int from, int to)
          Remove at index from to index to.
static Atom[] reverse(Atom[] list)
          Reverses the element content; the first element is the last and so on.
static Atom[] rotate(Atom[] list, int nbTimes)
          Rotates array content x number of times.
 boolean toBoolean()
          Returns the boolean value of this atom.
static boolean[] toBoolean(Atom[] values)
          Transform an array of Atom into an array of booleans.
 byte toByte()
          Returns the byte value of this atom.
static byte[] toByte(Atom[] values)
          Transform an array of Atom into an array of bytes.
 char toChar()
          Returns the char value of this atom.
static char[] toChar(Atom[] values)
          Transform an array of Atom into an array of chars.
static String toDebugString(Atom[] values)
          Used to return a string representation of the list with atom type.
 double toDouble()
          Returns the double value of this atom.
static double[] toDouble(Atom[] values)
          Transform an array of Atom into an array of doubles.
 float toFloat()
          Returns the float value of this atom.
static float[] toFloat(Atom[] values)
          Transform an array of Atom into an array of floats.
 int toInt()
          Returns the int value of this atom.
static int[] toInt(Atom[] values)
          Transform an array of Atom into an array of ints.
 long toLong()
          Returns the long value of this atom.
static long[] toLong(Atom[] values)
          Transform an array of Atom into an array of longs.
static String toOneString(Atom[] array)
          Returns the array of Atom into one string.
 short toShort()
          Returns the short value of this atom.
static short[] toShort(Atom[] values)
          Transform an array of Atom into an array of shorts.
static String[] toString(Atom[] array)
          Transform an array of Atom into an array of strings.
static Atom[] union(Atom[] first, Atom[] second)
          Don't know what this does.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

emptyArray

public static final Atom[] emptyArray
Empty array to use with the API when theres is no arguments.

Method Detail

newAtom

public static Atom newAtom(int value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom[] newAtom(int[] value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom newAtom(long value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom[] newAtom(long[] value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom newAtom(short value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom[] newAtom(short[] value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom newAtom(byte value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom[] newAtom(byte[] value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom newAtom(char value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom[] newAtom(char[] value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom newAtom(boolean value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom[] newAtom(boolean[] value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom newAtom(float value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom[] newAtom(float[] value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom newAtom(double value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom[] newAtom(double[] value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom newAtom(String value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

newAtom

public static Atom[] newAtom(String[] value)
Creates a new atom with the specified type.

Parameters:
value - the value of the atom
Returns:
the new Atom

parse

public static Atom[] parse(String values)
Creates an array of atoms from string tokens.

Parameters:
values - the atoms value seperated by string
Returns:
the array of atoms created from the list

parse

public static Atom[] parse(String values,
                           boolean skipfirst)
Creates an array of atoms from strings tokens.

Parameters:
values - the atoms value seperated by string
skipfirst - skip the first token
Returns:
the array of atoms created from the list

getString

public String getString()
Get string value for this Atom. If the Atom does not contains a string it will throw an UnsupportedOperationException.


getInt

public int getInt()
Get int value for this Atom. If the Atom does not contains a int it will throw an UnsupportedOperationException.


getFloat

public float getFloat()
Get float value for this Atom. If the Atom does not contains a float it will throw an UnsupportedOperationException.


toDouble

public double toDouble()
Returns the double value of this atom.

Returns:
the double value

toDouble

public static double[] toDouble(Atom[] values)
Transform an array of Atom into an array of doubles.

Parameters:
values - the array of atoms
Returns:
array of doubles

toInt

public int toInt()
Returns the int value of this atom.

Returns:
the int value

toInt

public static int[] toInt(Atom[] values)
Transform an array of Atom into an array of ints.

Parameters:
values - the array of atoms
Returns:
array of ints

toChar

public char toChar()
Returns the char value of this atom.

Returns:
the char value

toChar

public static char[] toChar(Atom[] values)
Transform an array of Atom into an array of chars.

Parameters:
values - the array of atoms
Returns:
array of chars

toByte

public byte toByte()
Returns the byte value of this atom.

Returns:
the byte value

toByte

public static byte[] toByte(Atom[] values)
Transform an array of Atom into an array of bytes.

Parameters:
values - the array of atoms
Returns:
array of bytes

toLong

public long toLong()
Returns the long value of this atom.

Returns:
the long value

toLong

public static long[] toLong(Atom[] values)
Transform an array of Atom into an array of longs.

Parameters:
values - the array of atoms
Returns:
array of longs

toShort

public short toShort()
Returns the short value of this atom.

Returns:
the short value

toShort

public static short[] toShort(Atom[] values)
Transform an array of Atom into an array of shorts.

Parameters:
values - the array of atoms
Returns:
array of shorts

toFloat

public float toFloat()
Returns the float value of this atom.

Returns:
the float value

toFloat

public static float[] toFloat(Atom[] values)
Transform an array of Atom into an array of floats.

Parameters:
values - the array of atoms
Returns:
array of floats

toBoolean

public boolean toBoolean()
Returns the boolean value of this atom.

Returns:
the boolean value

toBoolean

public static boolean[] toBoolean(Atom[] values)
Transform an array of Atom into an array of booleans.

Parameters:
values - the array of atoms
Returns:
array of booleans

toString

public static String[] toString(Atom[] array)
Transform an array of Atom into an array of strings.

Parameters:
array - the array of atoms
Returns:
array of strings

isFloat

public boolean isFloat()
Returns true if the Atom has been created with a float.

Returns:
true if the Atom has been created with a float

isString

public boolean isString()
Returns true if the Atom has been created with a String.

Returns:
true if the Atom has been created with a String

isInt

public boolean isInt()
Returns true if the Atom has been created with a int.

Returns:
true if the Atom has been created with a int

toOneString

public static String toOneString(Atom[] array)
Returns the array of Atom into one string. Atom elements are seperated by spaces.

Parameters:
array - the array of atom
Returns:
one string representation of the atom

equals

public abstract boolean equals(Object object)
Returns true if the instance has the same value of the object object. Similar to "ok".equals("ok");

Overrides:
equals in class Object

hashCode

public abstract int hashCode()
Returns the hashCode representation for this Atom. If it is an float, the float into bit value is return and if it is an String, the hashcode value of the string is returned.

Overrides:
hashCode in class Object

isIn

public static int isIn(Atom org,
                       Atom[] list)
Returns the index of the first atom that is found in the list.

Parameters:
org - the atom to find
list - the list of atom to search
Returns:
the index of the atom found. -1 if not found.

isIn

public static int isIn(Atom org,
                       Atom[] list,
                       int from,
                       int to)
Returns the index of the first atom that is found in the list.

Parameters:
org - the atom to find
list - the list of atom to search
from - the start index to check
to - the last index to check
Returns:
the index of the atom found. -1 if not found.

removeSome

public static Atom[] removeSome(Atom[] list,
                                int from,
                                int to)
Remove at index from to index to.

Parameters:
list - the list to strip
from - the start index
to - the last index
Returns:
the stripped array

removeOne

public static Atom[] removeOne(Atom[] list,
                               int i)
Removes one atom in the list.

Parameters:
list - the list to strip
i - the index of the atom to remove
Returns:
the stripped array

removeFirst

public static Atom[] removeFirst(Atom[] list)
Removes the first atom in the list.

Parameters:
list - the list to strip
Returns:
the stripped array

removeFirst

public static Atom[] removeFirst(Atom[] list,
                                 int howmany)
Removes the first howmany atoms in the list.

Parameters:
list - the list to strip
howmany - how many element to remove
Returns:
the stripped array

removeLast

public static Atom[] removeLast(Atom[] list)
Remove the last atom in the list.

Parameters:
list - the list to strip
Returns:
the stripped array

removeLast

public static Atom[] removeLast(Atom[] list,
                                int howmany)
Removes the last howmany atoms in the list.

Parameters:
list - the list to strip
howmany - how many element to remove
Returns:
the stripped array

reverse

public static Atom[] reverse(Atom[] list)
Reverses the element content; the first element is the last and so on.

Parameters:
list - the list to reverse
Returns:
the reversed list

rotate

public static Atom[] rotate(Atom[] list,
                            int nbTimes)
Rotates array content x number of times.

Parameters:
list - the list to rotate
nbTimes - the number of time that the array must be rotated
Returns:
the rotated list

union

public static Atom[] union(Atom[] first,
                           Atom[] second)
                    throws UnsupportedOperationException
Don't know what this does. Max/MSP says: it does an union. If you want me to support this, send me an email and what it does.

Parameters:
first -
second -
Returns:
nothing yet
Throws:
UnsupportedOperationException

intersection

public static Atom[] intersection(Atom[] first,
                                  Atom[] second)
                           throws UnsupportedOperationException
Don't know what this does. Max/MSP says: it does an intersection. If you want me to support this, send me an email and what it does.

Parameters:
first -
second -
Returns:
nothing yet
Throws:
UnsupportedOperationException

toDebugString

public static String toDebugString(Atom[] values)
Used to return a string representation of the list with atom type.

Parameters:
values - the array of atoms
Returns:
the string representation of the array


This API is based on mxj for Max/MSP by Cycling74. Please see original MXJ implementation.