anvil.core
Class Array

java.lang.Object
  |
  +--anvil.core.Any
        |
        +--anvil.core.Array
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable

public class Array
extends Any


Nested Class Summary
 class Array.Entry
          Array collision list.
 
Field Summary
static NativeClass _class
           
protected  Any _default
           
static java.lang.Object[] newInstance
           
static java.lang.Object[] p_append
           
static java.lang.Object[] p_both
           
static java.lang.Object[] p_concat
           
static java.lang.Object[] p_crop
           
static java.lang.Object[] p_cut
           
static java.lang.Object[] p_enqueue
           
static java.lang.Object[] p_find
           
static java.lang.Object[] p_findAll
           
static java.lang.Object[] p_get
           
static java.lang.Object[] p_grep
           
static java.lang.Object[] p_grepKeys
           
static java.lang.Object[] p_grepValues
           
static java.lang.Object[] p_insert
           
static java.lang.Object[] p_intersect
           
static java.lang.Object[] p_join
           
static java.lang.Object[] p_key
           
static java.lang.Object[] p_next
           
static java.lang.Object[] p_nextKey
           
static java.lang.Object[] p_nextValue
           
static java.lang.Object[] p_pop
           
static java.lang.Object[] p_pos
           
static java.lang.Object[] p_previous
           
static java.lang.Object[] p_previousKey
           
static java.lang.Object[] p_previousValue
           
static java.lang.Object[] p_push
           
static java.lang.Object[] p_select
           
static java.lang.Object[] p_set
           
static java.lang.Object[] p_setDefault
           
static java.lang.Object[] p_slice
           
static java.lang.Object[] p_sort
           
static java.lang.Object[] p_sortByKey
           
static java.lang.Object[] p_sortByValue
           
static java.lang.Object[] p_subtract
           
static java.lang.Object[] p_swap
           
static java.lang.Object[] p_swapOrder
           
static java.lang.Object[] p_union
           
static java.lang.Object[] p_unshift
           
static java.lang.Object[] p_value
           
 
Fields inherited from class anvil.core.Any
ARRAY0, DOUBLE_MINUS_ONE, DOUBLE_ONE, DOUBLE_ZERO, EMPTY_STRING, EMPTY_TUPLE, FALSE, INF, IS_ARRAY, IS_BINARY, IS_BOOLEAN, IS_BUFFER, IS_CLASS, IS_DOUBLE, IS_ENUMERATION, IS_INF, IS_INT, IS_LIST, IS_MAP, IS_NEG_INF, IS_NULL, IS_PATTERN, IS_RANGE, IS_STRING, IS_TUPLE, IS_UNDEFINED, MINUS_ONE, NAN, NEG_INF, NULL, ONE, p_compareTo, p_each, p_equals, p_pipe, THREE, TRUE, TWO, UNDEFINED, ZERO
 
Constructor Summary
Array()
          Constructs a new, empty hashlist with a default capacity and load factor.
Array(int initialCapacity)
          Constructs a new, empty hashlist with the specified initial capacity and default load factor.
Array(int initialCapacity, float loadFactor)
          Constructs a new, empty hashlist with the specified initial capacity and the specified load factor.
 
Method Summary
 Array append(Any value)
           
 Array append(Any key, Any value)
           
 Array append(int index, Any value)
           
 Array append(java.lang.String index, Any value)
           
 Array attach(Any value)
           
 ClassType classOf()
          Returns the type of this Any.
 void clear()
          Clears this hashlist so that it contains no keys.
 java.lang.Object clone()
          Creates a shallow copy of this hashlist.
protected  int compare(Any other)
           
 int compareTo(Array b)
           
 boolean contains(Any value)
          Tests if some key maps into the specified value in this hashlist.
 boolean containsKey(Any key)
          Tests if the specified object is a key in this hashlist.
 boolean containsValue(Any value)
           
 Any copy()
          Creates a copy of this array.
 Array crop(int start, int length)
           
 boolean cut(Any start, Any end)
           
 boolean cut(int start, int length)
           
 boolean deleteAttribute(Context context, java.lang.String attribute)
           
 boolean deleteReference(Context context, Any index)
           
 Any elementAt(int index)
           
 BindingIterator elements()
          Returns an iterator of the values in this hashlist.
 Array.Entry entryAt(int index)
           
 boolean equals(java.lang.Object obj)
          Tests for equality.
 Any execute(Context context)
           
 Any execute(Context context, Any param1)
           
 Any execute(Context context, Any[] parameters)
           
 Any execute(Context context, Any param1, Any param2)
           
 Any execute(Context context, Any param1, Any param2, Any param3)
           
 Any execute(Context context, Any param1, Any param2, Any param3, Any param4)
           
 Any get(Any key)
          Returns the value to which the specified key is mapped in this hashlist.
 Any get(int index)
          Returns the Any to which the specified index (Integer) is mapped in this hashlist.
 Any getAttribute(Context context, java.lang.String attribute)
           
 Array.Entry getEntry(Any key)
          Returns the entry to which the specified key is mapped in this hashlist.
 Array.Entry getEntry(int index)
          Returns the Entry to which the specified index (Integer) is mapped in this hashlist.
 int getNextSequence()
          Gets the next available integer slot.
 Any getReference(Context context, Any index)
           
 int hashCode()
           
 int indexOf(Any key)
           
 Array insert(Any value)
           
 Array insert(Any key, Any value)
           
 Array insert(Any start, Any end, Any slice)
           
 Array insert(int start, int length, Array array)
           
 Array insertAt(int index, Any value)
           
 Array insertAt(int index, Any key, Any value)
           
 Array intersect(Array set)
           
 boolean isArray()
          Checks if this any is array.
 boolean isEmpty()
          Tests if this hashlist maps no keys to values.
 boolean isMutable()
           
protected  boolean isReverseOrder(Array.Entry p, Array.Entry q)
           
 BindingIterator iterator()
           
 Any keyAt(int index)
           
 BindingIterator keys()
          Returns an iterator of the keys in this hashlist.
 BindingIterator keysAndElements()
          Returns an iterator of the values in this hashlist.
 Any m_append(Any element, Any[] elements)
           
 Any m_both(int index)
           
 Any m_clear()
           
 Any m_concat(Any value)
           
 Any m_crop(int start, int length)
           
 Any m_cut(int start, int length)
           
 Any m_dequeue()
           
 Any m_elements()
           
 Any m_enqueue(Any p, Any q)
           
 Any m_find(Any value)
           
 Any m_findAll(Any value)
           
 Any m_first()
           
 Any m_firstKey()
           
 Any m_firstValue()
           
 Any m_get(Any[] parameters)
           
 Any m_getDefault()
           
 Any m_getElements()
           
 Any m_getKeys()
           
 Any m_grep(Context context, Any key, Any value, boolean both)
           
 Any m_grepKeys(Context context, Any pattern)
           
 Any m_grepValues(Context context, Any pattern)
           
 Any m_insert(int start, Any p, Any insert)
           
 Any m_intersect(Any array)
           
 Any m_join(java.lang.String clue)
           
 Any m_key(int index)
           
 Any m_keys()
           
 Any m_keysAndElements()
           
 Any m_last()
           
 Any m_lastKey()
           
 Any m_lastValue()
           
 Any m_minmax()
           
 Any m_minmaxKeys()
           
 Any m_next(Any key)
           
 Any m_nextKey(Any key)
           
 Any m_nextValue(Any key)
           
 Any m_pop(Any index)
           
 Any m_pos(Any key)
           
 Any m_previous(Any key)
           
 Any m_previousKey(Any key)
           
 Any m_previousValue(Any key)
           
 Any m_push(Any element, Any[] elements)
           
 Any m_reverse()
           
 Any m_select(Context context, Any selector)
           
 Any m_set(Context context, Any[] parameters)
           
 Any m_setDefault(Any value)
           
 Any m_shift()
           
 Any m_size()
          Exposed methods
 Any m_sizeOf()
           
 Any m_slice(int start, int length)
           
 Any m_sort(Context context, Any comparator_)
           
 Any m_sortByKey(boolean ascending)
           
 Any m_sortByValue(boolean ascending)
           
 Any m_subtract(Any array)
           
 Any m_swap(Any key1, Any key2)
           
 Any m_swapOrder(Any key1, Any key2)
           
 Any m_union(Any array)
           
 Any m_unshift(Any[] elements)
           
 Any m_value(int index)
           
static Any newInstance(Context context, Any[] list)
           
 Array.Entry nextOf(Any index)
           
 Array.Entry previousOf(Any index)
           
 Any put(Any key, Any value)
          Maps the specified key to the specified value in this hashlist.
 Any put(int index, Any value)
          Maps the specified index to the specified value in this hashlist.
protected  Any putBefore(Any key, Any value, Array.Entry before)
           
protected  Any putBefore(Any value, Array.Entry entry)
           
protected  Any putBefore(int index, Any value, Array.Entry entry)
           
protected  Array.Entry putEntry(Any key, Any value)
          Maps the specified key to the specified value in this hashlist.
 Array.Entry putEntry(int index, Any value)
          Maps the specified index to the specified value in this hashlist.
protected  void rehash()
          Rehashes the contents of the hashlist into a hashlist with a larger capacity.
 Any remove(Any key)
          Removes the key (and its corresponding value) from this hashlist.
 Any removeAt(int index)
           
 Array reverse()
          List operations
 void serialize(Serializer serializer)
          Serializes this Array to OutputStream.
 Any setAt(int index, Any value)
           
 Any setAttribute(Context context, java.lang.String attribute, Any value)
           
 Array setDefault(Any defaultValue)
           
 Any setReference(Context context, Any value)
           
 Any setReference(Context context, Any index, Any value)
           
 int size()
          Returns the number of keys in this hashlist.
 int sizeOf()
          Returns the logical size of this any.
 Array slice(Any start, Any end)
           
 Array slice(Array slice, Any start, Any end)
           
 Array slice(Array array, int start, int length)
           
 Array slice(int start, int length)
           
 Array sort(java.util.Comparator comparator, boolean ascending)
           
 Array subtract(Array set)
           
 java.io.Writer toAnvil(java.io.Writer writer)
           
 Array toArray()
          Gets the contained vaelue as Array.
 Any[] toArray(boolean values)
           
 boolean toBoolean()
          Gets the contained value as boolean.
 Code toCode(Code code)
           
 java.lang.Object toObject()
          Gets the contained value as java.lang.Object.
 java.lang.String toString()
          Returns a rather long string representation of this hashlist.
 int typeOf()
          Returns the type of contained value.
 Array union(Array set)
           
static Array unserialize(Unserializer unserializer)
           
protected  void updateSequence(Any key)
           
 
Methods inherited from class anvil.core.Any
_clone, _copy, _invoke, _invoke, _invoke, _invoke, _invoke, _invoke, _serialize, _unserialize, _wakeup, add, classNameOf, coerce, compareTo, concat, create, create, create, create, create, create, create, create, create, create, create, create, create, create, decrease, divide, getRef, has, increase, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invoke, isBinary, isBoolean, isBuffer, isDefined, isDouble, isInstanceOf, isInt, isIterator, isList, isMap, isNull, isPattern, isRange, isRef, isSequence, isString, isTuple, isUndefined, m_clone, m_compareTo, m_copy, m_each, m_equals, m_hashCode, m_pipe, m_toBoolean, m_toString, minus, modulo, multiply, not, plus, setRef, subtract, toAnvil, toAnyBoolean, toAnyDouble, toAnyInt, toAnyString, toBinary, toBuffer, toByte, toChar, toDouble, toInt, toList, toLong, toMap, toPattern, toRange, toTuple, type
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

newInstance

public static final java.lang.Object[] newInstance

_default

protected Any _default

p_join

public static final java.lang.Object[] p_join

p_push

public static final java.lang.Object[] p_push

p_pop

public static final java.lang.Object[] p_pop

p_unshift

public static final java.lang.Object[] p_unshift

p_select

public static final java.lang.Object[] p_select

p_slice

public static final java.lang.Object[] p_slice

p_cut

public static final java.lang.Object[] p_cut

p_crop

public static final java.lang.Object[] p_crop

p_append

public static final java.lang.Object[] p_append

p_concat

public static final java.lang.Object[] p_concat

p_insert

public static final java.lang.Object[] p_insert

p_union

public static final java.lang.Object[] p_union

p_intersect

public static final java.lang.Object[] p_intersect

p_subtract

public static final java.lang.Object[] p_subtract

p_pos

public static final java.lang.Object[] p_pos

p_key

public static final java.lang.Object[] p_key

p_value

public static final java.lang.Object[] p_value

p_both

public static final java.lang.Object[] p_both

p_next

public static final java.lang.Object[] p_next

p_nextKey

public static final java.lang.Object[] p_nextKey

p_nextValue

public static final java.lang.Object[] p_nextValue

p_previous

public static final java.lang.Object[] p_previous

p_previousKey

public static final java.lang.Object[] p_previousKey

p_previousValue

public static final java.lang.Object[] p_previousValue

p_sortByKey

public static final java.lang.Object[] p_sortByKey

p_sortByValue

public static final java.lang.Object[] p_sortByValue

p_sort

public static final java.lang.Object[] p_sort

p_find

public static final java.lang.Object[] p_find

p_findAll

public static final java.lang.Object[] p_findAll

p_grep

public static final java.lang.Object[] p_grep

p_grepKeys

public static final java.lang.Object[] p_grepKeys

p_grepValues

public static final java.lang.Object[] p_grepValues

p_setDefault

public static final java.lang.Object[] p_setDefault

p_enqueue

public static final java.lang.Object[] p_enqueue

p_get

public static final java.lang.Object[] p_get

p_set

public static final java.lang.Object[] p_set

p_swap

public static final java.lang.Object[] p_swap

p_swapOrder

public static final java.lang.Object[] p_swapOrder

_class

public static final NativeClass _class
Constructor Detail

Array

public Array(int initialCapacity,
             float loadFactor)
Constructs a new, empty hashlist with the specified initial capacity and the specified load factor.

Parameters:
initialCapacity - the initial capacity of the hashlist.
loadFactor - a number between 0.0 and 1.0.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than or equal to zero, or if the load factor is less than or equal to zero.

Array

public Array(int initialCapacity)
Constructs a new, empty hashlist with the specified initial capacity and default load factor.

Parameters:
initialCapacity - the initial capacity of the hashlist.

Array

public Array()
Constructs a new, empty hashlist with a default capacity and load factor.

Method Detail

newInstance

public static final Any newInstance(Context context,
                                    Any[] list)

rehash

protected void rehash()
Rehashes the contents of the hashlist into a hashlist with a larger capacity. This method is called automatically when the number of keys in the hashlist exceeds this hashlist's capacity and load factor.


updateSequence

protected void updateSequence(Any key)

size

public int size()
Returns the number of keys in this hashlist.

Returns:
the number of keys in this hashlist.

isEmpty

public boolean isEmpty()
Tests if this hashlist maps no keys to values.

Returns:
true if this hashlist maps no keys to values; false otherwise.

keys

public BindingIterator keys()
Returns an iterator of the keys in this hashlist.

Returns:
an iterator of the keys in this hashlist.
See Also:
elements()

elements

public BindingIterator elements()
Returns an iterator of the values in this hashlist. Use the Iterator methods on the returned object to fetch the elements sequentially.

Returns:
an iterator of the values in this hashlist.
See Also:
keys()

keysAndElements

public BindingIterator keysAndElements()
Returns an iterator of the values in this hashlist. Use the Iterator methods on the returned object to fetch the elements sequentially.

Returns:
an iterator of the values in this hashlist.
See Also:
keys()

containsValue

public boolean containsValue(Any value)

contains

public boolean contains(Any value)
Tests if some key maps into the specified value in this hashlist. This operation is more expensive than the containsKey method.

Overrides:
contains in class Any
Parameters:
value - a value to search for.
Returns:
true if some key maps to the value argument in this hashlist; false otherwise.
Throws:
java.lang.NullPointerException - if the value is null.
See Also:
containsKey(anvil.core.Any)

containsKey

public boolean containsKey(Any key)
Tests if the specified object is a key in this hashlist.

Parameters:
key - possible key.
Returns:
true if the specified object is a key in this hashlist; false otherwise.
See Also:
contains(anvil.core.Any)

getEntry

public Array.Entry getEntry(Any key)
Returns the entry to which the specified key is mapped in this hashlist.

Parameters:
key - a key in the hashlist.
Returns:
the entry to which the key is mapped in this hashlist; null if the key is not mapped to any entry in this hashlist.
See Also:
put(anvil.core.Any, anvil.core.Any)

getEntry

public Array.Entry getEntry(int index)
Returns the Entry to which the specified index (Integer) is mapped in this hashlist.

Returns:
the Entry to which the index is mapped in this hashlist; null if the index is not mapped to any Entry in this hashlist.
See Also:
put(anvil.core.Any, anvil.core.Any)

get

public Any get(Any key)
Returns the value to which the specified key is mapped in this hashlist.

Parameters:
key - a key in the hashlist.
Returns:
the value to which the key is mapped in this hashlist; null if the key is not mapped to any value in this hashlist.
See Also:
put(anvil.core.Any, anvil.core.Any)

get

public Any get(int index)
Returns the Any to which the specified index (Integer) is mapped in this hashlist.

Returns:
the Entry to which the index is mapped in this hashlist; null if the index is not mapped to any entry in this hashlist.
See Also:
put(anvil.core.Any, anvil.core.Any)

put

public Any put(Any key,
               Any value)
Maps the specified key to the specified value in this hashlist. Neither the key nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
key - the hashlist key.
value - the value.
Returns:
the previous value of the specified key in this hashlist, or null if it did not have one.
Throws:
java.lang.NullPointerException - if the key or value is null.
See Also:
get(anvil.core.Any)

putBefore

protected Any putBefore(Any key,
                        Any value,
                        Array.Entry before)

putBefore

protected Any putBefore(int index,
                        Any value,
                        Array.Entry entry)

putBefore

protected Any putBefore(Any value,
                        Array.Entry entry)

putEntry

protected Array.Entry putEntry(Any key,
                               Any value)
Maps the specified key to the specified value in this hashlist. Neither the key nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
key - the hashlist key.
value - the value.
Returns:
Entry where the key and value were stored
Throws:
java.lang.NullPointerException - if the key or value is null.
See Also:
getEntry(anvil.core.Any)

put

public Any put(int index,
               Any value)
Maps the specified index to the specified value in this hashlist. Neither the index nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
index - the hashlist index.
value - the value.
Returns:
the previous value of the specified key in this hashlist, or null if it did not have one.
Throws:
java.lang.NullPointerException - if the index or value is null.
See Also:
get(int)

putEntry

public Array.Entry putEntry(int index,
                            Any value)
Maps the specified index to the specified value in this hashlist. Neither the index nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
index - the hashlist index.
value - the value.
Returns:
Entry where key and value were stored
Throws:
java.lang.NullPointerException - if the index or value is null.
See Also:
anvil.core.Array#get(java.lang.Integer)

remove

public Any remove(Any key)
Removes the key (and its corresponding value) from this hashlist. This method does nothing if the key is not in the hashlist.

Parameters:
key - the key that needs to be removed.
Returns:
the value to which the key had been mapped in this hashlist, or null if the key did not have a mapping.

clear

public void clear()
Clears this hashlist so that it contains no keys.


clone

public java.lang.Object clone()
Creates a shallow copy of this hashlist. The keys and values themselves are not cloned. This is a rather expensive operation.

Overrides:
clone in class Any
Returns:
a clone of the hashlist.

copy

public Any copy()
Creates a copy of this array.

Overrides:
copy in class Any
Returns:
a copy of the array.

toString

public java.lang.String toString()
Returns a rather long string representation of this hashlist.

Overrides:
toString in class Any
Returns:
a string representation of this hashlist.

toAnvil

public java.io.Writer toAnvil(java.io.Writer writer)
                       throws java.io.IOException
Overrides:
toAnvil in class Any
java.io.IOException

toCode

public Code toCode(Code code)
Overrides:
toCode in class Any

getNextSequence

public int getNextSequence()
Gets the next available integer slot.

Returns:
Sequence

reverse

public Array reverse()
List operations


crop

public Array crop(int start,
                  int length)

entryAt

public Array.Entry entryAt(int index)

indexOf

public int indexOf(Any key)

keyAt

public Any keyAt(int index)

elementAt

public Any elementAt(int index)

append

public Array append(Any value)

append

public Array append(int index,
                    Any value)

append

public Array append(java.lang.String index,
                    Any value)

append

public Array append(Any key,
                    Any value)

insert

public Array insert(Any value)

insert

public Array insert(Any key,
                    Any value)

insertAt

public Array insertAt(int index,
                      Any key,
                      Any value)

insertAt

public Array insertAt(int index,
                      Any value)

setAt

public Any setAt(int index,
                 Any value)

removeAt

public Any removeAt(int index)

previousOf

public Array.Entry previousOf(Any index)

nextOf

public Array.Entry nextOf(Any index)

toArray

public Any[] toArray(boolean values)

slice

public Array slice(Any start,
                   Any end)

isReverseOrder

protected boolean isReverseOrder(Array.Entry p,
                                 Array.Entry q)

slice

public Array slice(Array slice,
                   Any start,
                   Any end)

slice

public Array slice(int start,
                   int length)

slice

public Array slice(Array array,
                   int start,
                   int length)

cut

public boolean cut(int start,
                   int length)

cut

public boolean cut(Any start,
                   Any end)

insert

public Array insert(int start,
                    int length,
                    Array array)

insert

public Array insert(Any start,
                    Any end,
                    Any slice)

union

public Array union(Array set)

intersect

public Array intersect(Array set)

subtract

public Array subtract(Array set)

sort

public Array sort(java.util.Comparator comparator,
                  boolean ascending)

serialize

public void serialize(Serializer serializer)
               throws java.io.IOException
Serializes this Array to OutputStream.

Overrides:
serialize in class Any
Returns:
Serialized structure as String
Throws:
java.io.IOException - if something goes wrong

unserialize

public static final Array unserialize(Unserializer unserializer)
                               throws UnserializationException
UnserializationException

setDefault

public Array setDefault(Any defaultValue)

classOf

public ClassType classOf()
Description copied from class: Any
Returns the type of this Any.

Overrides:
classOf in class Any

typeOf

public int typeOf()
Description copied from class: Any
Returns the type of contained value.

Overrides:
typeOf in class Any
Returns:
Type of this any as int.

sizeOf

public int sizeOf()
Description copied from class: Any
Returns the logical size of this any.

Overrides:
sizeOf in class Any
Returns:
L