info.aduna.gee.publication.util
Class Result

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable
          extended by info.aduna.gee.publication.util.Result
All Implemented Interfaces:
Serializable, Cloneable, Map

public class Result
extends Hashtable

Class Result is a utility class for returning multiple values from a method, where no modelling is available or required (i.e. a sort of anonymous object). It has advantages over using one of the default Java containers (where excessive casting is required, esp. with basic types), or encoding the information into a String (which will have to be parsed). Example: public Result findChapterAndPage(Book b, String textToFind) { Result result = new Result(); Chapter chapter = getChapter(...); int page = getPage(...); result.put("chapter", chapter); result.put("page", page); return result; } ... Result chapterAndPage = findChapterAndPage(book, "mytext"); Chapter chapter = (Chapter)result.get("chapter"); int page = result.getInt("page");

See Also:
Serialized Form

Constructor Summary
Result()
           
Result(int initialCapacity)
           
Result(int initialCapacity, float loadFactor)
           
 
Method Summary
 boolean getBoolean(Object key)
          return the boolean value corresponding to the specified key Note: returns Boolean.FALSE if the key was not found or the value is not a Boolean
 char getChar(Object key)
          return the char value corresponding to the specified key Note: returns Char.MIN_VALUE if the key was not found or the value is not a Character
 double getDouble(Object key)
          return the double value corresponding to the specified key Note: returns Double.MIN_VALUE if the key was not found or the value is not a Double
 float getFloat(Object key)
          return the float value corresponding to the specified key Note: returns Float.MIN_VALUE if the key was not found or the value is not a Float
 int getInt(Object key)
          return the int value corresponding to the specified key Note: returns Integer.MIN_VALUE if the key was not found or the value is not an Integer
 long getLong(Object key)
          return the long value corresponding to the specified key Note: returns Long.MIN_VALUE if the key was not found or the value is not a Long
 String getString(Object key)
          return the String value corresponding to the specified key Note: returns null if the key was not found or the value is not a String
 void put(Object key, boolean booleanValue)
          Wrap a boolean in a Boolean and put it in the Result.
 void put(Object key, char charValue)
          Wrap a char in a Character and put it in the Result.
 void put(Object key, double doubleValue)
          Wrap a double in a Double and put it in the Result.
 void put(Object key, float floatValue)
          Wrap a float in a Float and put it in the Result.
 void put(Object key, int intValue)
          Wrap a int in an Integer and put it in the Result.
 void put(Object key, long longValue)
          Wrap a long in a Long and put it in the Result.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Result

public Result()

Result

public Result(int initialCapacity)

Result

public Result(int initialCapacity,
              float loadFactor)
Method Detail

getBoolean

public boolean getBoolean(Object key)
return the boolean value corresponding to the specified key Note: returns Boolean.FALSE if the key was not found or the value is not a Boolean


getChar

public char getChar(Object key)
return the char value corresponding to the specified key Note: returns Char.MIN_VALUE if the key was not found or the value is not a Character


getDouble

public double getDouble(Object key)
return the double value corresponding to the specified key Note: returns Double.MIN_VALUE if the key was not found or the value is not a Double


getFloat

public float getFloat(Object key)
return the float value corresponding to the specified key Note: returns Float.MIN_VALUE if the key was not found or the value is not a Float


getInt

public int getInt(Object key)
return the int value corresponding to the specified key Note: returns Integer.MIN_VALUE if the key was not found or the value is not an Integer


getLong

public long getLong(Object key)
return the long value corresponding to the specified key Note: returns Long.MIN_VALUE if the key was not found or the value is not a Long


getString

public String getString(Object key)
return the String value corresponding to the specified key Note: returns null if the key was not found or the value is not a String


put

public void put(Object key,
                boolean booleanValue)
Wrap a boolean in a Boolean and put it in the Result.

See Also:
Map.put(Object key, Object value)

put

public void put(Object key,
                char charValue)
Wrap a char in a Character and put it in the Result.

See Also:
Map.put(Object key, Object value)

put

public void put(Object key,
                double doubleValue)
Wrap a double in a Double and put it in the Result.

See Also:
Map.put(Object key, Object value)

put

public void put(Object key,
                float floatValue)
Wrap a float in a Float and put it in the Result.

See Also:
Map.put(Object key, Object value)

put

public void put(Object key,
                int intValue)
Wrap a int in an Integer and put it in the Result.

See Also:
Map.put(Object key, Object value)

put

public void put(Object key,
                long longValue)
Wrap a long in a Long and put it in the Result.

See Also:
Map.put(Object key, Object value)


Copyright © 1997-2008 Aduna. All Rights Reserved.