http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/GenericMessage.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/GenericMessage.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/GenericMessage.java deleted file mode 100644 index 5921e22..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/GenericMessage.java +++ /dev/null @@ -1,807 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.cache.data; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.DataOutput; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -import com.gemstone.gemfire.DataSerializable; -import com.gemstone.gemfire.DataSerializer; - -/** - * GenericMessage is a light weight message class for holding (key, value) paired - * data. It holds all primitive values and nested GenericMessage objects. - * @author dpark - * - */ -public class GenericMessage implements GenericMap, Cloneable -{ - private static final long serialVersionUID = 1L; - - /** - * Used to dump messages. - */ - private final static StringBuffer spaces = new StringBuffer(" "); - private static int CHUNK_SIZE_IN_BYTES = 100000; - - private ArrayList entryList = new ArrayList(10); - - - /** - * Creates an empty ObjectMessage object. - */ - public GenericMessage() - { - } - - /** - * Appends a GenericData object to the message. - * @param key The key identifying the value. Note that this key needs - * not be unique. - * @param value The value associated with the specified key. - */ - public GenericMap.Entry add(String key, GenericMap value) - { - if (key == null) { - return null; - } - return addEntry(new GenericMap.Entry(key, value, GenericMap.Entry.TYPE_GENERIC_DATA)); - } - - public GenericMap.Entry add(String key, Mappable value) - { - if (key == null) { - return null; - } - return addEntry(new GenericMap.Entry(key, value, GenericMap.Entry.TYPE_MAPPABLE)); - } - - /** - * Appends a String to the message. - * @param key The key identifying the value. Note that this key needs - * not be unique. - * @param value The value associated with the specified key. - */ - public GenericMap.Entry add(String key, String value) - { - if (key == null) { - return null; - } - return addEntry(new GenericMap.Entry(key, value, GenericMap.Entry.TYPE_STRING)); - } - - /** - * Appends a boolean value to the message. - * @param key The key identifying the value. Note that this key needs - * not be unique. - * @param value The value associated with the specified key. - */ - public GenericMap.Entry add(String key, boolean value) - { - if (key == null) { - return null; - } - return addEntry(new GenericMap.Entry(key, Boolean.valueOf(value), GenericMap.Entry.TYPE_BOOLEAN)); - } - - /** - * Appends a byte value to the message. - * @param key The key identifying the value. Note that this key needs - * not be unique. - * @param value The value associated with the specified key. - */ - public GenericMap.Entry add(String key, byte value) - { - if (key == null) { - return null; - } - return addEntry(new GenericMap.Entry(key, Byte.valueOf(value), GenericMap.Entry.TYPE_BYTE)); - } - - /** - * Appends a short value to the message. - * @param key The key identifying the value. Note that this key needs - * not be unique. - * @param value The value associated with the specified key. - */ - public GenericMap.Entry add(String key, short value) - { - if (key == null) { - return null; - } - return addEntry(new GenericMap.Entry(key, Short.valueOf(value), GenericMap.Entry.TYPE_SHORT)); - } - - /** - * Appends a int value to the message. - * @param key The key identifying the value. Note that this key needs - * not be unique. - * @param value The value associated with the specified key. - */ - public GenericMap.Entry add(String key, int value) - { - if (key == null) { - return null; - } - return addEntry(new GenericMap.Entry(key, Integer.valueOf(value), GenericMap.Entry.TYPE_INTEGER)); - } - - /** - * Appends a long value to the message. - * @param key The key identifying the value. Note that this key needs - * not be unique. - * @param value The value associated with the specified key. - */ - public GenericMap.Entry add(String key, long value) - { - if (key == null) { - return null; - } - return addEntry(new GenericMap.Entry(key, Long.valueOf(value), GenericMap.Entry.TYPE_LONG)); - } - - /** - * Appends a float value to the message. - * @param key The key identifying the value. Note that this key needs - * not be unique. - * @param value The value associated with the specified key. - */ - public GenericMap.Entry add(String key, float value) - { - if (key == null) { - return null; - } - return addEntry(new GenericMap.Entry(key, new Float(value), GenericMap.Entry.TYPE_FLOAT)); - } - - /** - * Appends a double value to the message. - * @param key The key identifying the value. Note that this key needs - * not be unique. - * @param value The value associated with the specified key. - */ - public GenericMap.Entry add(String key, double value) - { - if (key == null) { - return null; - } - return addEntry(new GenericMap.Entry(key, new Double(value), GenericMap.Entry.TYPE_DOUBLE)); - } - - /** - * Appends an GenericMap.Entry object to the message. - * @param entry The entry associated with the specified key. - */ - public GenericMap.Entry addEntry(Entry entry) - { - if (entry == null) { - return null; - } - entryList.add(entry); - return entry; - } - - /** - * Returns the Entry object located at the specified index. - * @param index The index. - */ - public GenericMap.Entry getEntry(int index) - { - if (index < 0 || index >= entryList.size()) { - return null; - } - return (Entry)entryList.get(index); - } - - /** - * Returns the first Entry object identified by the specified key found - * in the message. There may be multiple Entry objects associated with - * the same key. - */ - public GenericMap.Entry getEntry(String key) - { - if (key == null) { - return null; - } - GenericMap.Entry array[] = (Entry[])entryList.toArray(new GenericMap.Entry[0]); - for (int i = 0; i < array.length; i++) { - if (array[i].getKey().equals(key)) { - return array[i]; - } - } - return null; - } - - /** - * Returns the first value identified by the specified key found in - * the message. There may be multiple Entry objects associated with - * the same key. - * @param key The key identifying the interested value. - */ - public Object getValue(String key) - { - GenericMap.Entry entry = getEntry(key); - if (entry == null) { - return null; - } - return entry.getValue(); - } - - public boolean getBoolean(String key) throws NoSuchFieldException, InvalidTypeException - { - GenericMap.Entry entry = getEntry(key); - if (entry == null) { - throw new NoSuchFieldException("The field " + key + " is not found."); - } - Object val = entry.getValue(); - if (val == null) { - throw new NullPointerException("The field " + key + " has null value."); - } - if (entry.getType() != GenericMap.Entry.TYPE_BOOLEAN) { - if (val instanceof Boolean == false) { - throw new InvalidTypeException("The field " + key + " has the type " + val.getClass().getName()); - } - } - return ((Boolean)val).booleanValue(); - } - - public byte getByte(String key) throws NoSuchFieldException, InvalidTypeException - { - GenericMap.Entry entry = getEntry(key); - if (entry == null) { - throw new NoSuchFieldException("The field " + key + " is not found."); - } - Object val = entry.getValue(); - if (val == null) { - throw new NullPointerException("The field " + key + " has null value."); - } - if (entry.getType() != GenericMap.Entry.TYPE_BYTE) { - if (val instanceof Byte == false) { - throw new InvalidTypeException("The field " + key + " has the type " + val.getClass().getName()); - } - } - return ((Byte)val).byteValue(); - } - - public char getChar(String key) throws NoSuchFieldException, InvalidTypeException - { - GenericMap.Entry entry = getEntry(key); - if (entry == null) { - throw new NoSuchFieldException("The field " + key + " is not found."); - } - Object val = entry.getValue(); - if (val == null) { - throw new NullPointerException("The field " + key + " has null value."); - } - if (entry.getType() != GenericMap.Entry.TYPE_CHAR) { - if (val instanceof Character == false) { - throw new InvalidTypeException("The field " + key + " has the type " + val.getClass().getName()); - } - } - return ((Character)val).charValue(); - } - - public short getShort(String key) throws NoSuchFieldException, InvalidTypeException - { - GenericMap.Entry entry = getEntry(key); - if (entry == null) { - throw new NoSuchFieldException("The field " + key + " is not found."); - } - Object val = entry.getValue(); - if (val == null) { - throw new NullPointerException("The field " + key + " has null value."); - } - if (entry.getType() != GenericMap.Entry.TYPE_SHORT) { - if (val instanceof Short == false) { - throw new InvalidTypeException("The field " + key + " has the type " + val.getClass().getName()); - } - } - return ((Short)val).shortValue(); - } - - public int getInt(String key) throws NoSuchFieldException, InvalidTypeException - { - GenericMap.Entry entry = getEntry(key); - if (entry == null) { - throw new NoSuchFieldException("The field " + key + " is not found."); - } - Object val = entry.getValue(); - if (val == null) { - throw new NullPointerException("The field " + key + " has null value."); - } - if (entry.getType() != GenericMap.Entry.TYPE_INTEGER) { - if (val instanceof Integer == false) { - throw new InvalidTypeException("The field " + key + " has the type " + val.getClass().getName()); - } - } - return ((Integer)val).intValue(); - } - - public long getLong(String key) throws NoSuchFieldException, InvalidTypeException - { - GenericMap.Entry entry = getEntry(key); - if (entry == null) { - throw new NoSuchFieldException("The field " + key + " is not found."); - } - Object val = entry.getValue(); - if (val == null) { - throw new NullPointerException("The field " + key + " has null value."); - } - if (entry.getType() != GenericMap.Entry.TYPE_LONG) { - if (val instanceof Long == false) { - throw new InvalidTypeException("The field " + key + " has the type " + val.getClass().getName()); - } - } - return ((Long)val).longValue(); - } - - public float getFloat(String key) throws NoSuchFieldException, InvalidTypeException - { - GenericMap.Entry entry = getEntry(key); - if (entry == null) { - throw new NoSuchFieldException("The field " + key + " is not found."); - } - Object val = entry.getValue(); - if (val == null) { - throw new NullPointerException("The field " + key + " has null value."); - } - if (entry.getType() != GenericMap.Entry.TYPE_LONG) { - if (val instanceof Long == false) { - throw new InvalidTypeException("The field " + key + " has the type " + val.getClass().getName()); - } - } - return ((Long)val).longValue(); - } - - public double getDouble(String key) throws NoSuchFieldException, InvalidTypeException - { - GenericMap.Entry entry = getEntry(key); - if (entry == null) { - throw new NoSuchFieldException("The field " + key + " is not found."); - } - Object val = entry.getValue(); - if (val == null) { - throw new NullPointerException("The field " + key + " has null value."); - } - if (entry.getType() != GenericMap.Entry.TYPE_DOUBLE) { - if (val instanceof Double == false) { - throw new InvalidTypeException("The field " + key + " has the type " + val.getClass().getName()); - } - } - return ((Double)val).doubleValue(); - } - - public String getString(String key) throws NoSuchFieldException, InvalidTypeException - { - GenericMap.Entry entry = getEntry(key); - if (entry == null) { - throw new NoSuchFieldException("The field " + key + " is not found."); - } - Object val = entry.getValue(); - if (entry.getType() != GenericMap.Entry.TYPE_STRING) { - if (val instanceof String == false) { - throw new InvalidTypeException("The field " + key + " has the type " + val.getClass().getName()); - } - } - return (String)val; - } - - /** - * Returns the Entry at the specified index position. It returns null if the index - * is out of range. - */ - public GenericMap.Entry getEntryAt(int index) - { - if (index < 0 && index >= size()) { - return null; - } - return (Entry)entryList.get(index); - } - - /** - * Returns the value found at the specified index position. Ir returns null if - * the index is out of range. - */ - public Object getValueAt(int index) - { - GenericMap.Entry entry = getEntryAt(index); - if (entry == null) { - return null; - } - return entry.getValue(); - } - - /** - * Returns the key of the entry found at the specified index position. It returns null - * if the index is out of range. - */ - public String getNameAt(int index) - { - GenericMap.Entry entry = getEntryAt(index); - if (entry == null) { - return null; - } - return entry.getKey(); - } - - /** - * Returns the index of the first Entry that matches the specified key. - * It returns -1 if not found. - * @param key The Entry key. - */ - public int indexOf(String key) - { - if (key == null) { - return -1; - } - int index = -1; - GenericMap.Entry array[] = (Entry[])entryList.toArray(new GenericMap.Entry[0]); - for (int i = 0; i < array.length; i++) { - if (array[i].getKey().equals(key)) { - index = i; - break; - } - } - return index; - } - - /** - * Returns the index of the last Entry that matches the specified key. - * It returns -1 if not found. - * @param key The Entry key. - */ - public int lastIndexOf(String key) - { - if (key == null) { - return -1; - } - int index = -1; - GenericMap.Entry array[] = (Entry[])entryList.toArray(new GenericMap.Entry[0]); - for (int i = array.length - 1; i >= 0; i--) { - if (array[i].getKey().equals(key)) { - index = i; - break; - } - } - return index; - } - - /** - * Returns the last Entry found in the message. t returns null if the message - * does not contain any data. - */ - public GenericMap.Entry getLastEntry() - { - if (entryList.size() > 0) { - return (Entry)entryList.get(entryList.size()-1); - } else { - return null; - } - } - - /** - * Returns the last value found in the message. t returns null if the message - * does not contain any data. - */ - public Object getLastValue() - { - GenericMap.Entry entry = getLastEntry(); - if (entry == null) { - return null; - } - return entry.getValue(); - } - - /** - * Returns the first Entry found in the message. It returns null if the message - * does not contain any data. - */ - public GenericMap.Entry getFirstEntry() - { - if (entryList.size() > 0) { - return (Entry)entryList.get(0); - } else { - return null; - } - } - - /** - * Returns the first value found in the message. It returns null if the message - * does not contain any data. - */ - public Object getFirstValue() - { - GenericMap.Entry entry = getFirstEntry(); - if (entry == null) { - return null; - } - return entry.getValue(); - } - - /** - * Returns true if the message contains nested ObjectMessage. - */ - public boolean hasGenericData() - { - GenericMap.Entry data[] = getAllEntries(); - for (int i = 0; i < data.length; i++) { - if (data[i].getValue() instanceof GenericMap) { - return true; - } - } - return false; - } - - /** - * Removes the specified entry from the message. - */ - public boolean remove(Entry entry) - { - return entryList.remove(entry); - } - - /** - * Removes the Entry object at the specified position. - */ - public GenericMap.Entry remove(int index) - { - return (Entry)entryList.remove(index); - } - - public Collection getEntries() - { - return entryList; - } - - - /** - * Returns the number of Entry objects contained in this message. - */ - public int size() - { - return entryList.size(); - } - - /** - * Returns all of the Entry objects in the form of array. - */ - public GenericMap.Entry[] getAllEntries() - { - return (Entry[])entryList.toArray(new GenericMap.Entry[0]); - } - - /** - * Returns all of the Entry objects that contain the non-ObjectMessage type, - * i.e., no nested messages. - */ - public GenericMap.Entry[] getAllPrimitives() - { - GenericMap.Entry data[] = getAllEntries(); - GenericMap.Entry messages[] = new GenericMap.Entry[data.length]; - int count = 0; - for (int i = 0; i < data.length; i++) { - if (data[i].getValue() instanceof GenericMap == false) { - messages[count++] = data[i]; - } - } - GenericMap.Entry m[] = new GenericMap.Entry[count]; - System.arraycopy(messages, 0, m, 0, count); - return m; - } - - /** - * Returns the number of non-ObjectMessage objects in this message. - */ - public int getPrimitiveCount() - { - GenericMap.Entry data[] = getAllEntries(); -// GenericMap.Entry messages[] = new GenericMap.Entry[data.length]; //FindBugs - unused - int count = 0; - for (int i = 0; i < data.length; i++) { - if (data[i].getValue() instanceof GenericMap == false) { - count++; - } - } - return count; - } - - /** - * Returns all of the Entry objects that contain the ObjectMessage type, i.e., nested - * messages. - */ - public GenericMap.Entry[] getAllGenericData() - { - GenericMap.Entry data[] = getAllEntries(); - GenericMap.Entry messages[] = new GenericMap.Entry[data.length]; - int count = 0; - for (int i = 0; i < data.length; i++) { - if (data[i].getValue() instanceof GenericMap) { - messages[count++] = data[i]; - } - } - GenericMap.Entry m[] = new GenericMap.Entry[count]; - System.arraycopy(messages, 0, m, 0, count); - return m; - } - - /** - * Returns the number of ObjectMessage objects in this message. - */ - public int getGenericDataCount() - { - GenericMap.Entry data[] = getAllEntries(); -// GenericMap.Entry messages[] = new GenericMap.Entry[data.length]; //FindBugs - unused - int count = 0; - for (int i = 0; i < data.length; i++) { - if (data[i].getValue() instanceof GenericMap) { - count++; - } - } - return count; - } - - public void clear() - { - entryList.clear(); - } - - private void convertToString(StringBuffer buffer, GenericMap message, int level) - { - GenericMap.Entry data[] = message.getAllEntries(); - for (int i = 0; i < data.length; i++) { - if (data[i].getType() == GenericMap.Entry.TYPE_MAPPABLE) { - buffer.append(spaces.substring(0, level*3) + data[i].getKey() + "*****" + "\n"); - convertToString(buffer, (GenericMap)data[i].getValue(), level+1); - } else { - buffer.append(spaces.substring(0, level*3)+ data[i].getKey() + " = " + data[i].getValue() + "\n"); - } - } - } - -// public void convertToString(StringBuffer buffer) -// { -// if (buffer == null) { -// return; -// } -// convertToString(buffer); -// } - - public String toString() - { - StringBuffer buffer = new StringBuffer(100); - convertToString(buffer, this, 0); - return buffer.toString(); - } - - /** - * Recursively dumps the message contents to the specified writer. - */ - private void dump(PrintWriter writer, GenericMap message, int level) - { - GenericMap.Entry data[] = message.getAllEntries(); - for (int i = 0; i < data.length; i++) { - if (data[i].getType() == GenericMap.Entry.TYPE_MAPPABLE) { - writer.println(spaces.substring(0, level*3) + data[i].getKey() + "*****"); - dump(writer, (GenericMap)data[i].getValue(), level+1); - } else { - writer.println(spaces.substring(0, level*3)+ data[i].getKey() + " = " + data[i].getValue()); - } - } - } - - /** - * Dumps the message contents to the specified output stream. - * @param out The outputstream to which the contents are dumped. - */ - public void dump(OutputStream out) - { - if (out == null) { - return; - } - PrintWriter writer = new PrintWriter(out); - dump(writer, this, 0); - writer.flush(); - } - - /** - * Dumps the message contents to the standard output stream (System.out). - */ - public void dump() - { - PrintWriter writer = new PrintWriter(System.out); - dump(writer, this, 0); - writer.flush(); - } - - private static byte[] serializeDataSerializable(DataSerializable obj) throws IOException - { - byte[] ba = null; - ByteArrayOutputStream baos = new ByteArrayOutputStream(CHUNK_SIZE_IN_BYTES); - DataOutputStream dos = new DataOutputStream(baos); - DataSerializer.writeObject(obj, dos); - dos.flush(); - ba = baos.toByteArray(); - - return ba; - } - - private static Object deserializeDataSerializable(byte[] byteArray) - throws IOException, ClassNotFoundException - { - ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); - DataInputStream dis = new DataInputStream(bais); - Object obj = DataSerializer.readObject(dis); - return obj; - } - - private byte[] serialize(Object obj) throws IOException - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(obj); - oos.flush(); - byte array[] = baos.toByteArray(); - baos.close(); - return array; - } - - private Object deserialize(byte objArray[]) throws IOException, ClassNotFoundException - { - ByteArrayInputStream bais = new ByteArrayInputStream(objArray); - ObjectInputStream ois = new ObjectInputStream(bais); - Object obj = ois.readObject(); - return obj; - } - - /** - * Returns a shallow copy of this <tt>ObjectMessage</tt> instance. (The - * elements themselves are not copied.) - * - * @return a clone of this <tt>ObjectMessage</tt> instance. - */ - public Object clone() - { - GenericMessage dup = new GenericMessage(); - dup.entryList = (ArrayList)this.entryList.clone(); - return dup; - } - - public void fromData(DataInput dataInput) throws IOException, ClassNotFoundException - { - int count = dataInput.readInt(); - Entry entry; - byte type; - String key; - Object value; - for (int i = 0; i < count; i++) { - type = dataInput.readByte(); - key = DataSerializer.readString(dataInput); - value = DataSerializer.readObject(dataInput); - entry = new GenericMap.Entry(key, value, type); - entryList.add(entry); - } - } - - public void toData(DataOutput dataOutput) throws IOException - { - int count = entryList.size(); - dataOutput.writeInt(count); - Entry entry; - for (Iterator iterator = entryList.iterator(); iterator.hasNext();) { - entry = (Entry)iterator.next(); - dataOutput.writeByte(entry.getType()); - DataSerializer.writeString(entry.getKey(), dataOutput); - DataSerializer.writeObject(entry.getValue(), dataOutput); - } - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/InvalidTypeException.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/InvalidTypeException.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/InvalidTypeException.java deleted file mode 100644 index 1f2aa30..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/InvalidTypeException.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.cache.data; - -/** - * Thrown when the object type is invalid. - */ -public class InvalidTypeException extends Exception -{ - /** - * Constructs an <code>InvalidTypeException</code> with <code>null</code> - * as its error detail message. - */ - public InvalidTypeException() { - super(); - } - - /** - * Constructs an <code>InvalidTypeException</code> with the specified detail - * message. The error message string <code>s</code> can later be - * retrieved by the <code>{@link java.lang.Throwable#getMessage}</code> - * method of class <code>java.lang.Throwable</code>. - * - * @param s the detail message. - */ - public InvalidTypeException(String s) { - super(s); - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMap.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMap.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMap.java deleted file mode 100644 index 7a06e11..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMap.java +++ /dev/null @@ -1,197 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.cache.data; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.Serializable; -import java.util.AbstractMap; -import java.util.AbstractSet; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import com.gemstone.gemfire.DataSerializable; -import com.gemstone.gemfire.DataSerializer; - -/** - * An implementation of a Map that guarantees original order of keys as they - * are added to the Map. - */ -public class ListMap extends AbstractMap implements Cloneable, DataSerializable -{ - /** - * Version id for Serializable - */ - private static final long serialVersionUID = 1L; - - protected ListSet entrySet = new ListSet(); - - /** - * Internal class to implement a Set that uses an ArrayList to keep - * original order of keys - */ - static protected class ListSet extends AbstractSet implements Serializable - { - protected ArrayList entryList = new ArrayList(); - - public ListSet() - { - super(); - } - - public Iterator iterator() - { - return entryList.iterator(); - } - - public int size() - { - return entryList.size(); - } - - public boolean add(Object o) - { - boolean retVal = false; - if (!entryList.contains(o)) { - retVal = entryList.add(o); - } - return retVal; - } - - /** - * Internal method to put the entry by looking for existing entry and * - * returning it or add new entry. - */ - public Object putEntry(Object entry) - { - Object retVal = entry; - int index = entryList.indexOf(entry); - if (index >= 0) { - retVal = entryList.get(index); - } else { - entryList.add(entry); - } - return retVal; - } - } - - /** - * Internal class to implement the Map.Entry interface that holds the - * entry objects in the Map. - */ - static protected class ListEntry implements Entry, Serializable - { - protected Object key = null; - - protected Object value = null; - - public ListEntry(Object pKey) - { - key = pKey; - } - - public Object getKey() - { - return key; - } - - public Object getValue() - { - return value; - } - - public Object setValue(Object pValue) - { - Object prevValue = value; - value = pValue; - return prevValue; - } - - public boolean equals(Object o) - { - boolean retVal = false; - Object otherKey = o; - if (o instanceof ListEntry) { - otherKey = ((ListEntry) o).getKey(); - } - retVal = (key == null && otherKey == null) - || (key != null && key.equals(otherKey)); - return retVal; - } - - public int hashCode() - { - return (key != null) ? key.hashCode() : 0; - } - } - - /** - * Default constructor - */ - public ListMap() - { - super(); - } - - /** - * Implement put to allow this Map to be writable. If the key represents a - * new element in the Map, then it is added to the end of the Map. - * Otherwise, the existing entry is updated with the new value. - * - * @param key - * the key of the value to set. - * @param value - * the value to set. - * @return the previous value set at this key (null indicates new or - * previous value was null). - */ - public Object put(Object key, Object value) - { - Map.Entry entry = new ListEntry(key); - entry = (Map.Entry)entrySet.putEntry(entry); - return entry.setValue(value); - } - - /** - * Return the Set that contains a list of Map.Entry objects for this Map. - */ - public Set entrySet() - { - return entrySet; - } - - public Object clone() - { - ListMap result = null; - try { - result = (ListMap)super.clone(); - } catch (Exception e) { - // ignore - } - return result; - } - - public void fromData(DataInput dataInput) throws IOException, ClassNotFoundException - { - int size = dataInput.readInt(); - String key; - Object value; - for (int i = 0; i < size; i++) { - key = DataSerializer.readString(dataInput); - value = DataSerializer.readObject(dataInput); - put(key, value); - } - } - - public void toData(DataOutput dataOutput) throws IOException - { - dataOutput.writeInt(entrySet.size()); - Map.Entry entry; - for (Iterator iterator = entrySet.iterator(); iterator.hasNext(); ) { - entry = (Map.Entry)iterator.next(); - DataSerializer.writeObject(entry.getKey(), dataOutput); - DataSerializer.writeObject(entry.getValue(), dataOutput); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMapMessage.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMapMessage.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMapMessage.java deleted file mode 100644 index 5d7ee39..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMapMessage.java +++ /dev/null @@ -1,615 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.cache.data; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -import com.gemstone.gemfire.internal.InternalDataSerializer; - -/** - * ListMapMessage is a light weight map that guarantees the original order of - * keys as they are added to the map. It holds all primitive values and - * nested ListMapMessage objects. - * @author dpark - * - */ -public class ListMapMessage implements Mappable, Cloneable -{ - private static final long serialVersionUID = 1L; - - /** - * Used to dump messages. - */ - private final static StringBuffer spaces = new StringBuffer(" "); - - private ListMap map = new ListMap(); - - /** - * Creates an empty ListMapMessage object. - */ - public ListMapMessage() - { - } - - /** - * Puts a Mappable to the message. - * @param name The unique name identifying the value. - * @param mappable The value associated with the specified name. - */ - public void put(String name, Mappable mappable) - { - map.put(name, mappable); - } - - /** - * Puts a Listable to the message. - * @param name The unique name identifying the value. - * @param listable The value associated with the specified name. - */ - public void put(String name, Listable listable) - { - map.put(name, listable); - } - - - /** - * Puts a String to the message. - * @param name The unique name identifying the value. - * @param value The value associated with the specified name. - */ - public void put(String name, String value) - { - map.put(name, value); - } - - /** - * Appends a boolean value to the message. - * @param name The unique name identifying the value. - * @param value The value associated with the specified name. - */ - public void put(String name, boolean value) - { - map.put(name, Boolean.valueOf(value)); - } - - /** - * Puts a byte value to the message. - * @param name The unique name identifying the value. - * @param value The value associated with the specified name. - */ - public void put(String name, byte value) - { - map.put(name, Byte.valueOf(value)); - } - - /** - * Appends a short value to the message. - * @param name The unique name identifying the value. - * @param value The value associated with the specified name. - */ - public void put(String name, short value) - { - map.put(name, Short.valueOf(value)); - } - - /** - * Puts a int value to the message. - * @param name The unique name identifying the value. - * @param value The value associated with the specified name. - */ - public void put(String name, int value) - { - map.put(name, Integer.valueOf(value)); - } - - /** - * Appends a long value to the message. - * @param name The unique name identifying the value. - * @param value The value associated with the specified name. - */ - public void put(String name, long value) - { - map.put(name, Long.valueOf(value)); - } - - /** - * Puts a float value to the message. - * @param name The unique name identifying the value. - * @param value The value associated with the specified name. - */ - public void put(String name, float value) - { - map.put(name, new Float(value)); - } - - /** - * Puts a double value to the message. - ** @param name The unique name identifying the value. - * @param value The value associated with the specified name. - */ - public void put(String name, double value) - { - map.put(name, new Double(value)); - } - - /** - * Returns the object identified by the specified name found - * in the message. - */ - public Object getValue(String name) - { - return map.get(name); - } - - /** - * Returns the boolean value identified by the specified name found - * in the message. - * @param name The unique name identifying the value. - * @throws NoSuchFieldException Thrown if the mapping value is not found. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public boolean getBoolean(String name) throws NoSuchFieldException, InvalidTypeException - { - Object value = map.get(name); - if (value == null) { - throw new NoSuchFieldException("The field " + name + " is not found."); - } else { - if (value instanceof Boolean) { - return ((Boolean)value).booleanValue(); - } else { - throw new InvalidTypeException("The field " + name + " has the type " + value.getClass().getName()); - } - } - } - - /** - * Returns the byte value identified by the specified name found - * in the message. - * @param name The unique name identifying the value. - * @throws NoSuchFieldException Thrown if the mapping value is not found. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public byte getByte(String name) throws NoSuchFieldException, InvalidTypeException - { - Object value = map.get(name); - if (value == null) { - throw new NoSuchFieldException("The field " + name + " is not found."); - } else { - if (value instanceof Byte) { - return ((Byte)value).byteValue(); - } else { - throw new InvalidTypeException("The field " + name + " has the type " + value.getClass().getName()); - } - } - } - - /** - * Returns the char value identified by the specified name found - * in the message. - * @param name The unique name identifying the value. - * @throws NoSuchFieldException Thrown if the mapping value is not found. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public char getChar(String name) throws NoSuchFieldException, InvalidTypeException - { - Object value = map.get(name); - if (value == null) { - throw new NoSuchFieldException("The field " + name + " is not found."); - } else { - if (value instanceof Character) { - return ((Character)value).charValue(); - } else { - throw new InvalidTypeException("The field " + name + " has the type " + value.getClass().getName()); - } - } - } - - /** - * Returns the short value identified by the specified name found - * in the message. - * @param name The unique name identifying the value. - * @throws NoSuchFieldException Thrown if the mapping value is not found. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public short getShort(String name) throws NoSuchFieldException, InvalidTypeException - { - Object value = map.get(name); - if (value == null) { - throw new NoSuchFieldException("The field " + name + " is not found."); - } else { - if (value instanceof Short) { - return ((Short)value).shortValue(); - } else { - throw new InvalidTypeException("The field " + name + " has the type " + value.getClass().getName()); - } - } - } - - /** - * Returns the int value identified by the specified name found - * in the message. - * @param name The unique name identifying the value. - * @throws NoSuchFieldException Thrown if the mapping value is not found. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public int getInt(String name) throws NoSuchFieldException, InvalidTypeException - { - Object value = map.get(name); - if (value == null) { - throw new NoSuchFieldException("The field " + name + " is not found."); - } else { - if (value instanceof Integer) { - return ((Integer)value).intValue(); - } else { - throw new InvalidTypeException("The field " + name + " has the type " + value.getClass().getName()); - } - } - } - - /** - * Returns the long value identified by the specified name found - * in the message. - * @param name The unique name identifying the value. - * @throws NoSuchFieldException Thrown if the mapping value is not found. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public long getLong(String name) throws NoSuchFieldException, InvalidTypeException - { - Object value = map.get(name); - if (value == null) { - throw new NoSuchFieldException("The field " + name + " is not found."); - } else { - if (value instanceof Long) { - return ((Long)value).longValue(); - } else { - throw new InvalidTypeException("The field " + name + " has the type " + value.getClass().getName()); - } - } - } - - /** - * Returns the float value identified by the specified name found - * in the message. - * @param name The unique name identifying the value. - * @throws NoSuchFieldException Thrown if the mapping value is not found. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public float getFloat(String name) throws NoSuchFieldException, InvalidTypeException - { - Object value = map.get(name); - if (value == null) { - throw new NoSuchFieldException("The field " + name + " is not found."); - } else { - if (value instanceof Float) { - return ((Float)value).floatValue(); - } else { - throw new InvalidTypeException("The field " + name + " has the type " + value.getClass().getName()); - } - } - } - - /** - * Returns the double value identified by the specified name found - * in the message. - * @param name The unique name identifying the value. - * @throws NoSuchFieldException Thrown if the mapping value is not found. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public double getDouble(String name) throws NoSuchFieldException, InvalidTypeException - { - Object value = map.get(name); - if (value == null) { - throw new NoSuchFieldException("The field " + name + " is not found."); - } else { - if (value instanceof Double) { - return ((Double)value).doubleValue(); - } else { - throw new InvalidTypeException("The field " + name + " has the type " + value.getClass().getName()); - } - } - } - - /** - * Returns the String value identified by the specified name found - * in the message. - * @param name The unique name identifying the value. - * @throws NoSuchFieldException Thrown if the mapping value is not found. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public String getString(String name) throws NoSuchFieldException, InvalidTypeException - { - Object value = map.get(name); - if (value == null) { - throw new NoSuchFieldException("The field " + name + " is not found."); - } else { - if (value instanceof String) { - return (String)value; - } else { - throw new InvalidTypeException("The field " + name + " has the type " + value.getClass().getName()); - } - } - } - - /** - * Returns true if the message contains nested Mappable. - */ - public boolean hasMappable() - { - Map.Entry entries[] = getAllEntries(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Mappable) { - return true; - } - } - return false; - } - - /** - * Returns true if the message contains nested Listable. - */ - public boolean hasListable() - { - Map.Entry entries[] = getAllEntries(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Listable) { - return true; - } - } - return false; - } - - /** - * Removes the specified entry from the message. - */ - public Object remove(String name) - { - return map.remove(name); - } - - /** - * Returns the number of entries in this message. - */ - public int size() - { - return map.size(); - } - - public Collection values() - { - return map.values(); - } - - public Collection getValues() - { - return map.values(); - } - - public Set keys() - { - return map.keySet(); - } - - public Set getKeys() - { - return map.keySet(); - } - - public Set getEntries() - { - return map.entrySet(); - } - - /** - * Returns all of the entries in the form of array. - */ - public Map.Entry[] getAllEntries() - { - return (Map.Entry[])map.entrySet().toArray(new Map.Entry[0]); - } - - /** - * Returns all of the primitive entries in the message. - */ - public Map.Entry[] getAllPrimitives() - { - Map.Entry entries[] = getAllEntries(); - Map.Entry messages[] = new Map.Entry[entries.length]; - int count = 0; - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Mappable == false) { - messages[count++] = entries[i]; - } - } - Map.Entry m[] = new Map.Entry[count]; - System.arraycopy(messages, 0, m, 0, count); - return m; - } - - /** - * Returns the number primitive entries in this message. - */ - public int getPrimitiveCount() - { - Map.Entry entries[] = getAllEntries(); - int count = 0; - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Mappable == false) { - count++; - } - } - return count; - } - - /** - * Returns all of the entries that have the ListMapMessage type, i.e., nested - * messages. - */ - public Map.Entry[] getAllMappables() - { - Map.Entry entries[] = getAllEntries(); - Map.Entry messages[] = new Map.Entry[entries.length]; - int count = 0; - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Mappable) { - messages[count++] = entries[i]; - } - } - Map.Entry m[] = new Map.Entry[count]; - System.arraycopy(messages, 0, m, 0, count); - return m; - } - - /** - * Returns all of the entries that have the ListMapMessage type, i.e., nested - * messages. - */ - public Map.Entry[] getAllListables() - { - Map.Entry entries[] = getAllEntries(); - Map.Entry messages[] = new Map.Entry[entries.length]; - int count = 0; - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Listable) { - messages[count++] = entries[i]; - } - } - Map.Entry m[] = new Map.Entry[count]; - System.arraycopy(messages, 0, m, 0, count); - return m; - } - - /** - * Returns the number of Mappable entries in this message. - */ - public int getMappableCount() - { - Map.Entry entries[] = getAllEntries(); - int count = 0; - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Mappable) { - count++; - } - } - return count; - } - - /** - * Returns the number of Listable entries in this message. - */ - public int getListableCount() - { - Map.Entry entries[] = getAllEntries(); - int count = 0; - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Listable) { - count++; - } - } - return count; - } - - /** - * Clears the message. It removes all of the entries in the message. - * - */ - public void clear() - { - map.clear(); - } - - private void convertToString(StringBuffer buffer, Mappable message, int level) - { - Map.Entry entries[] = message.getAllEntries(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Mappable) { - buffer.append(spaces.substring(0, level*3) + entries[i].getKey() + "*****" + "\n"); - convertToString(buffer, (Mappable)entries[i].getValue(), level+1); - } else { - buffer.append(spaces.substring(0, level*3)+ entries[i].getKey() + " = " + entries[i].getValue() + "\n"); - } - } - } - -// public void convertToString(StringBuffer buffer) -// { -// if (buffer == null) { -// return; -// } -// convertToString(buffer); -// } - - public String toString() - { - StringBuffer buffer = new StringBuffer(100); - convertToString(buffer, this, 0); - return buffer.toString(); - } - - /** - * Recursively dumps the message contents to the specified writer. - */ - private void dump(PrintWriter writer, Mappable message, int level) - { - Map.Entry entries[] = message.getAllEntries(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Mappable) { - writer.println(spaces.substring(0, level*3) + entries[i].getKey() + "*****"); - dump(writer, (Mappable)entries[i].getValue(), level+1); - } else { - writer.println(spaces.substring(0, level*3)+ entries[i].getKey() + " = " + entries[i].getValue()); - } - } - } - - /** - * Dumps the message contents to the specified output stream. - * @param out The outputstream to which the contents are dumped. - */ - public void dump(OutputStream out) - { - if (out == null) { - return; - } - PrintWriter writer = new PrintWriter(out); - dump(writer, this, 0); - writer.flush(); - } - - /** - * Dumps the message contents to the standard output stream (System.out). - */ - public void dump() - { - PrintWriter writer = new PrintWriter(System.out); - dump(writer, this, 0); - writer.flush(); - } - - /** - * Returns a shallow copy of this <tt>ListMapMessage</tt> instance. (The - * elements themselves are not copied.) - * - * @return a clone of this <tt>ListMapMessage</tt> instance. - */ - public Object clone() - { - ListMapMessage dup = new ListMapMessage(); - dup.map = (ListMap)this.map.clone(); - return dup; - } - - public void fromData(DataInput dataInput) throws IOException, ClassNotFoundException - { - InternalDataSerializer.invokeFromData(map, dataInput); - } - - public void toData(DataOutput dataOutput) throws IOException - { - InternalDataSerializer.invokeToData(map, dataOutput); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMessage.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMessage.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMessage.java deleted file mode 100644 index ac31b16..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/ListMessage.java +++ /dev/null @@ -1,594 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.cache.data; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -import com.gemstone.gemfire.DataSerializer; - -/** - * ListMessage is a light weight message class for holding only values - * (no keys). It holds all primitive values and nested ListMessage objects. - * @author dpark - * - */ -public class ListMessage implements Listable, Cloneable -{ - private static final long serialVersionUID = 1L; - - /** - * Used to dump messages. - */ - private final static StringBuffer spaces = new StringBuffer(" "); - - private ArrayList entryList = new ArrayList(10); - - /** - * Creates an empty ListMessage object. - */ - public ListMessage() - { - } - - /** - * Puts a Listable to the message. - * @param listable The nested Listable value to append. - */ - public void add(Listable listable) - { - entryList.add(listable); - } - - /** - * Puts a Mappable to the message. - * @param mappable The nested Mappable value to append. - */ - public void add(Mappable mappable) - { - entryList.add(mappable); - } - - /** - * Puts a String to the message. - * @param value The String value to append. - */ - public void add(String value) - { - entryList.add(value); - } - - /** - * Appends a boolean value to the message. - * @param value The boolean value to append. - */ - public void add(boolean value) - { - entryList.add(Boolean.valueOf(value)); - } - - /** - * Appends a byte value to the message. - * @param value The byte value to append. - */ - public void add(byte value) - { - entryList.add(Byte.valueOf(value)); - } - - /** - * Appends a short value to the message. - * @param value The short value to append. - */ - public void add(short value) - { - entryList.add(Short.valueOf(value)); - } - - /** - * Appends a int value to the message. - * @param value The int value to append. - */ - public void add(int value) - { - entryList.add(Integer.valueOf(value)); - } - - /** - * Appends a long value to the message. - * @param value The long value to append. - */ - public void add(long value) - { - entryList.add(Long.valueOf(value)); - } - - /** - * Puts a float value to the message. - * @param value The float value to append. - */ - public void add(float value) - { - entryList.add(new Float(value)); - } - - /** - * Puts a double value to the message. - * @param value The double value to append. - */ - public void add(double value) - { - entryList.add(new Double(value)); - } - - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range <tt>(index - * < 0 || index >= size())</tt>. - */ - public Object getValue(int index) throws IndexOutOfBoundsException - { - return entryList.get(index); - } - - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range <tt>(index - * < 0 || index >= size())</tt>. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public boolean getBoolean(int index) throws IndexOutOfBoundsException, InvalidTypeException - { - Object value = getValue(index); - if (value instanceof Boolean) { - return ((Boolean)value).booleanValue(); - } else { - throw new InvalidTypeException("The value at index " + index + " has the type " + value.getClass().getName()); - } - } - - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range <tt>(index - * < 0 || index >= size())</tt>. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public byte getByte(int index) throws IndexOutOfBoundsException, InvalidTypeException - { - Object value = getValue(index); - if (value instanceof Byte) { - return ((Byte)value).byteValue(); - } else { - throw new InvalidTypeException("The value at index " + index + " has the type " + value.getClass().getName()); - } - } - - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range <tt>(index - * < 0 || index >= size())</tt>. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public char getChar(int index) throws IndexOutOfBoundsException, InvalidTypeException - { - Object value = getValue(index); - if (value instanceof Character) { - return ((Character)value).charValue(); - } else { - throw new InvalidTypeException("The value at index " + index + " has the type " + value.getClass().getName()); - } - } - - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range <tt>(index - * < 0 || index >= size())</tt>. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public short getShort(int index) throws IndexOutOfBoundsException, InvalidTypeException - { - Object value = getValue(index); - if (value instanceof Short) { - return ((Short)value).shortValue(); - } else { - throw new InvalidTypeException("The value at index " + index + " has the type " + value.getClass().getName()); - } - } - - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range <tt>(index - * < 0 || index >= size())</tt>. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public int getInt(int index) throws IndexOutOfBoundsException, InvalidTypeException - { - Object value = getValue(index); - if (value instanceof Integer) { - return ((Integer)value).intValue(); - } else { - throw new InvalidTypeException("The value at index " + index + " has the type " + value.getClass().getName()); - } - } - - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range <tt>(index - * < 0 || index >= size())</tt>. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public long getLong(int index) throws IndexOutOfBoundsException, InvalidTypeException - { - Object value = getValue(index); - if (value instanceof Long) { - return ((Long)value).intValue(); - } else { - throw new InvalidTypeException("The value at index " + index + " has the type " + value.getClass().getName()); - } - } - - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range <tt>(index - * < 0 || index >= size())</tt>. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public float getFloat(int index) throws IndexOutOfBoundsException, InvalidTypeException - { - Object value = getValue(index); - if (value instanceof Float) { - return ((Float)value).intValue(); - } else { - throw new InvalidTypeException("The value at index " + index + " has the type " + value.getClass().getName()); - } - } - - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range <tt>(index - * < 0 || index >= size())</tt>. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public double getDouble(int index) throws IndexOutOfBoundsException, InvalidTypeException - { - Object value = getValue(index); - if (value instanceof Double) { - return ((Double)value).intValue(); - } else { - throw new InvalidTypeException("The value at index " + index + " has the type " + value.getClass().getName()); - } - } - - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range <tt>(index - * < 0 || index >= size())</tt>. - * @throws InvalidTypeException Thrown if the value type is different. - */ - public String getString(int index) throws IndexOutOfBoundsException, InvalidTypeException - { - Object value = getValue(index); - if (value instanceof String) { - return (String)value; - } else { - throw new InvalidTypeException("The value at index " + index + " has the type " + value.getClass().getName()); - } - } - - /** - * Returns true if the message contains nested Listable. - */ - public boolean hasListable() - { - Iterator iterator = entryList.iterator(); - while (iterator.hasNext()) { - if (iterator.next() instanceof Listable) { - return true; - } - } - return false; - } - - /** - * Returns true if the message contains nested Mappable. - */ - public boolean hasMappable() - { - Iterator iterator = entryList.iterator(); - while (iterator.hasNext()) { - if (iterator.next() instanceof Mappable) { - return true; - } - } - return false; - } - - /** - * Removes the specified entry from the message. - */ - public Object remove(int index) - { - return entryList.remove(index); - } - - /** - * Returns the number of entries in this message. - */ - public int size() - { - return entryList.size(); - } - - public Collection values() - { - return entryList; - } - - public Collection getValues() - { - return entryList; - } - - /** - * Returns all of the values in the form of array. - */ - public Object[] getAllValues() - { - return entryList.toArray(); - } - - /** - * Returns all of the primitive entries in the message. - */ - public Object[] getAllPrimitives() - { - ArrayList primitiveList = new ArrayList(); - Iterator iterator = entryList.iterator(); - Object value; - while (iterator.hasNext()) { - value = iterator.next(); - if (value instanceof Listable == false) { - primitiveList.add(value); - } - } - return primitiveList.toArray(); - } - - /** - * Returns the number primitive entries in this message. - */ - public int getPrimitiveCount() - { - Iterator iterator = entryList.iterator(); - int count = 0; - while (iterator.hasNext()) { - if (iterator.next() instanceof Listable == false) { - count++; - } - } - return count; - } - - /** - * Returns all of the values that have the Listable type, i.e., nested - * messages. - */ - public Listable[] getAllListables() - { - ArrayList listMessageList = new ArrayList(); - Iterator iterator = entryList.iterator(); - Object value; - while (iterator.hasNext()) { - value = iterator.next(); - if (value instanceof Listable) { - listMessageList.add(value); - } - } - return (Listable[])listMessageList.toArray(new Listable[0]); - } - - /** - * Returns all of the values that have the Mappable type, i.e., nested - * messages. - */ - public Mappable[] getAllMappables() - { - ArrayList listMessageList = new ArrayList(); - Iterator iterator = entryList.iterator(); - Object value; - while (iterator.hasNext()) { - value = iterator.next(); - if (value instanceof Mappable) { - listMessageList.add(value); - } - } - return (Mappable[])listMessageList.toArray(new Mappable[0]); - } - - /** - * Returns the number of Listable entries in this message. - */ - public int getListableCount() - { - Iterator iterator = entryList.iterator(); - int count = 0; - while (iterator.hasNext()) { - if (iterator.next() instanceof Listable) { - count++; - } - } - return count; - } - - /** - * Returns the number of Mappable entries in this message. - */ - public int getMappableCount() - { - Iterator iterator = entryList.iterator(); - int count = 0; - while (iterator.hasNext()) { - if (iterator.next() instanceof Mappable) { - count++; - } - } - return count; - } - - /** - * Clears the message. It removes all of the values in the message. - * - */ - public void clear() - { - entryList.clear(); - } - - private void convertToString(StringBuffer buffer, Listable message, int level) - { - Object values[] = message.getAllValues(); - for (int i = 0; i < values.length; i++) { - if (values[i] instanceof Listable) { - buffer.append(spaces.substring(0, level*3) + values[i] + "*****" + "\n"); - convertToString(buffer, (Listable)values[i], level+1); - } else { - buffer.append(spaces.substring(0, level*3)+ values[i] + "\n"); - } - } - } - -// public void convertToString(StringBuffer buffer) -// { -// if (buffer == null) { -// return; -// } -// convertToString(buffer); -// } - - public String toString() - { - StringBuffer buffer = new StringBuffer(100); - convertToString(buffer, this, 0); - return buffer.toString(); - } - - /** - * Recursively dumps the message contents to the specified writer. - */ - private void dump(PrintWriter writer, Listable message, int level) - { - Object values[] = message.getAllValues(); - for (int i = 0; i < values.length; i++) { - if (values[i] instanceof Listable) { - writer.println(spaces.substring(0, level*3) + values[i] + "*****"); - dump(writer, (Listable)values[i], level+1); - } if (values[i] instanceof Listable) { - writer.println(spaces.substring(0, level*3) + values[i] + "*****"); - dump(writer, (Mappable)values[i], level+1); - } else { - writer.println(spaces.substring(0, level*3)+ values[i]); - } - } - } - - /** - * Recursively dumps the message contents to the specified writer. - */ - private void dump(PrintWriter writer, Mappable message, int level) - { - Map.Entry entries[] = message.getAllEntries(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getValue() instanceof Mappable) { - writer.println(spaces.substring(0, level*3) + entries[i].getKey() + "*****"); - dump(writer, (Mappable)entries[i].getValue(), level+1); - } else if (entries[i].getValue() instanceof Listable) { - writer.println(spaces.substring(0, level*3) + entries[i].getKey() + "*****"); - dump(writer, (Listable)entries[i].getValue(), level+1); - } else { - writer.println(spaces.substring(0, level*3)+ entries[i].getKey() + " = " + entries[i].getValue()); - } - } - } - - /** - * Dumps the message contents to the specified output stream. - * @param out The outputstream to which the contents are dumped. - */ - public void dump(OutputStream out) - { - if (out == null) { - return; - } - PrintWriter writer = new PrintWriter(out); - dump(writer, this, 0); - writer.flush(); - } - - /** - * Dumps the message contents to the standard output stream (System.out). - */ - public void dump() - { - PrintWriter writer = new PrintWriter(System.out); - dump(writer, this, 0); - writer.flush(); - } - - /** - * Returns a shallow copy of this <tt>ListMessage</tt> instance. (The - * elements themselves are not copied.) - * - * @return a clone of this <tt>ListMessage</tt> instance. - */ - public Object clone() - { - ListMessage dup = new ListMessage(); - dup.entryList = (ArrayList)this.entryList.clone(); - return dup; - } - - public void fromData(DataInput dataInput) throws IOException, ClassNotFoundException - { - entryList = DataSerializer.readArrayList(dataInput); - } - - public void toData(DataOutput dataOutput) throws IOException - { - DataSerializer.writeArrayList(entryList, dataOutput); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/Listable.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/Listable.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/Listable.java deleted file mode 100644 index 1095397..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/cache/data/Listable.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.cache.data; - -import java.io.OutputStream; -import java.util.Collection; - -import com.gemstone.gemfire.DataSerializable; - -public interface Listable extends DataSerializable -{ - public void add(Listable listable); - public void add(Mappable listable); - public void add(String value); - public void add(boolean value); - public void add(byte value); - public void add(short value); - public void add(int value); - public void add(long value); - public void add(float value); - public void add(double value); - public Object getValue(int index) throws IndexOutOfBoundsException; - public boolean getBoolean(int index) throws IndexOutOfBoundsException, InvalidTypeException; - public byte getByte(int index) throws IndexOutOfBoundsException, InvalidTypeException; - public char getChar(int index) throws IndexOutOfBoundsException, InvalidTypeException; - public short getShort(int index) throws IndexOutOfBoundsException, InvalidTypeException; - public int getInt(int index) throws IndexOutOfBoundsException, InvalidTypeException; - public long getLong(int index) throws IndexOutOfBoundsException, InvalidTypeException; - public float getFloat(int index) throws IndexOutOfBoundsException, InvalidTypeException; - public double getDouble(int index) throws IndexOutOfBoundsException, InvalidTypeException; - public String getString(int index) throws IndexOutOfBoundsException, InvalidTypeException; - public boolean hasListable(); - public boolean hasMappable(); - public Object remove(int index); - public int size(); - public Collection getValues(); - public Object[] getAllValues(); - public Object[] getAllPrimitives(); - public int getPrimitiveCount(); - public Listable[] getAllListables(); - public Mappable[] getAllMappables(); - public int getListableCount(); - public int getMappableCount(); - public void clear(); - public void dump(OutputStream out); - public Object clone(); -}
