package com.cycling74.max; import java.io.*; import java.util.*; /** * 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. */ public abstract class Atom implements Comparable, Serializable { /** * Empty array to use with the API when theres is no arguments. */ public static final Atom[] emptyArray = new Atom[] {}; int type; Atom(int type) { this.type = type; } // Atom factories /////////////////////////////////////////////////////////////////// /** * Creates a new atom with the specified type. * @param value the value of the atom * @return the new Atom */ public static Atom newAtom(int value) { return new AtomFloat(value); } /** * Creates a new atom with the specified type. * @param value the value of the atom * @return the new Atom */ public static Atom[] newAtom(int value[]) { Atom[] ret = new Atom[value.length]; for(int i=0;iobject. Similar to "ok".equals("ok"); */ public abstract boolean equals(Object object); /** * 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. */ public abstract int hashCode(); // Array utility classes /////////////////////////////////////////////////////////////////// /** * Returns the index of the first atom that is found in the list. * @param org the atom to find * @param list the list of atom to search * @return the index of the atom found. -1 if not found. */ public static int isIn(Atom org, Atom[] list) { return isIn(org, list, 0, list.length-1); } /** * Returns the index of the first atom that is found in the list. * @param org the atom to find * @param list the list of atom to search * @param from the start index to check * @param to the last index to check * @return the index of the atom found. -1 if not found. */ public static int isIn(Atom org, Atom[] list, int from, int to) { for(int i=from;ifrom to index to. * @param list the list to strip * @param from the start index * @param to the last index * @return the stripped array */ public static Atom[] removeSome(Atom[] list, int from, int to) { if ( from == 0 && from == list.length - 1 ) return new Atom[] {}; Atom[] ret = new Atom[list.length - (to-from+1)]; System.arraycopy(list, 0, ret, 0, from); System.arraycopy(list, to + 1, ret, from, list.length - to - 1); return ret; } /** * Removes one atom in the list. * @param list the list to strip * @param i the index of the atom to remove * @return the stripped array */ public static Atom[] removeOne(Atom[] list, int i) { return removeSome(list, i, i); } /** * Removes the first atom in the list. * @param list the list to strip * @return the stripped array */ public static Atom[] removeFirst(Atom[] list) { return removeFirst(list, 1); } /** * Removes the first howmany atoms in the list. * @param list the list to strip * @param howmany how many element to remove * @return the stripped array */ public static Atom[] removeFirst(Atom[] list, int howmany) { return removeSome(list, 0, howmany-1); } /** * Remove the last atom in the list. * @param list the list to strip * @return the stripped array */ public static Atom[] removeLast(Atom[] list) { return removeLast(list, 1); } /** * Removes the last howmany atoms in the list. * @param list the list to strip * @param howmany how many element to remove * @return the stripped array */ public static Atom[] removeLast(Atom[] list, int howmany) { return removeSome(list, list.length-howmany, list.length-1); } /** * Reverses the element content; the first element is the last and so on. * @param list the list to reverse * @return the reversed list */ public static Atom[] reverse(Atom[] list) { Atom[] ret = new Atom[list.length]; int last = list.length - 1; for(int i=0;i