org.millscript.millscript.datatypes
Class ListAwareTools

java.lang.Object
  extended by org.millscript.millscript.datatypes.ListAwareTools

public final class ListAwareTools
extends java.lang.Object

This utility class implements list aware tools for MillScript. List aware means that these methods unify different datatypes in a list-like way. e.g. getting a specified item in a list.

These static methods provide a location to optimize List-like operations for particular classes. Each one provides a general fallback defined in terms of ListFactory.make.


Method Summary
static void addLast(java.lang.Object obj, java.lang.Object val)
          Performs an add-last operation, adding the specified value to the given list.
static java.lang.Object append(java.lang.Object x, java.lang.Object y)
          Returns a new object that is the result of appending the two specified objects together.
static void explode(java.lang.Object obj, Machine mc)
          This method explodes the specified object into the specified machine.
static java.lang.Object get(java.lang.Object obj, int i)
          Returns the item at the specified position, from the specified object.
static org.millscript.commons.util.MapIterator mapIterator(java.lang.Object obj)
          Returns a map iterator to iterate over all the entries in the specified list like object.
static void removeLast(java.lang.Object obj)
          Performs a remove-last operation, removing the last value from the given list.
static java.lang.Object reverse(java.lang.Object obj)
          Returns an object containing the elements from the specified object, in reverse order.
static java.lang.Object subrange(java.lang.Object obj, int lo, int hi)
          Returns an object representing the specified subrange of items from the specified object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addLast

public static void addLast(java.lang.Object obj,
                           java.lang.Object val)
Performs an add-last operation, adding the specified value to the given list. This method allows MillScript to work with List implementations from the MillScript-Util API or the Java Collections API.

Parameters:
obj - the object to be resolved as a list
val - the value to add to the end of the list

append

public static java.lang.Object append(java.lang.Object x,
                                      java.lang.Object y)
Returns a new object that is the result of appending the two specified objects together.

Parameters:
x - the first object
y - the second object, to append to the first
Returns:
a new object resulting from appending the second object to the first

explode

public static void explode(java.lang.Object obj,
                           Machine mc)
This method explodes the specified object into the specified machine. If the object cannot be understood directly, this method will attempt to construct a new list from the specified object, get an iterator and then explode it.

Parameters:
obj - the object to explode
mc - the machine to put the pieces of the explosion into

get

public static java.lang.Object get(java.lang.Object obj,
                                   int i)
Returns the item at the specified position, from the specified object. If the object cannot be understood directly, this method attempts to contructs a new list from the specified object and then makes an iterator for that.

Parameters:
obj - the object to index as a list
i - the index
Returns:
the object at the specified index in the target object

mapIterator

public static org.millscript.commons.util.MapIterator mapIterator(java.lang.Object obj)
Returns a map iterator to iterate over all the entries in the specified list like object. If the object cannot be understood directly, this method attempts to contructs a new list from the specified object and then makes an iterator for that.

Parameters:
obj - the list like object to get a map interator for
Returns:
a MapIterator to iterate over the values in the list like object
See Also:
ListFactory

removeLast

public static void removeLast(java.lang.Object obj)
Performs a remove-last operation, removing the last value from the given list. This method allows MillScript to work with List implementations from the MillScript-Util API or the Java Collections API.

Parameters:
obj - the object to be resolved as a list

reverse

public static java.lang.Object reverse(java.lang.Object obj)
Returns an object containing the elements from the specified object, in reverse order. e.g. if list is passed, a new list is returned with the elements in the reverse order. if a string is passed a new string is returned with the characters in the reverse order.

Parameters:
obj - the object to reverse
Returns:
an object containing the elements from the specified object in reverse order

subrange

public static java.lang.Object subrange(java.lang.Object obj,
                                        int lo,
                                        int hi)
Returns an object representing the specified subrange of items from the specified object.

Parameters:
obj - the target object to subrange
lo - the low end of the range(one based, inclusive)
hi - the high end of the range(one based, inclusive)
Returns:
an object representing the subrange of the target object


Copyright © 2001-2007 Open World Ltd. All Rights Reserved.