Author: maksimkaszynski
Date: 2008-03-19 14:20:07 -0400 (Wed, 19 Mar 2008)
New Revision: 6978
Modified:
trunk/framework/api/src/main/java/org/richfaces/model/ListRowKey.java
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModel.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeNode.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeNodeImpl.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeRowKey.java
Log:
Fixed generic
Modified: trunk/framework/api/src/main/java/org/richfaces/model/ListRowKey.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/ListRowKey.java 2008-03-19
18:20:02 UTC (rev 6977)
+++ trunk/framework/api/src/main/java/org/richfaces/model/ListRowKey.java 2008-03-19
18:20:07 UTC (rev 6978)
@@ -30,9 +30,9 @@
* @author Nick Belaevski - nbelaevski(a)exadel.com
* created 17.11.2006
*/
-public class ListRowKey extends TreeRowKey {
+public class ListRowKey<T> extends TreeRowKey<T> {
- private ArrayList<Object> path;
+ private ArrayList<T> path;
/**
*
@@ -48,19 +48,21 @@
*/
public ListRowKey() {
super();
- this.path = new ArrayList<Object>();
+ this.path = new ArrayList<T>();
}
/**
* Copy constructor
* @param parentRowKey row key to clone
*/
- public ListRowKey(ListRowKey parentRowKey) {
+
+ @SuppressWarnings("unchecked")
+ public ListRowKey(ListRowKey<T> parentRowKey) {
super();
if (parentRowKey != null) {
- this.path = (ArrayList<Object>) parentRowKey.path.clone();
+ this.path = (ArrayList<T>) parentRowKey.path.clone();
} else {
- this.path = new ArrayList<Object>();
+ this.path = new ArrayList<T>();
}
}
@@ -69,86 +71,37 @@
* @param parentRowKey base row key
* @param pathElement path segment to append to base row key
*/
- public ListRowKey(ListRowKey parentRowKey, Object pathElement) {
+ public ListRowKey(ListRowKey<T> parentRowKey, T pathElement) {
this(parentRowKey);
this.path.add(pathElement);
}
- private static ArrayList<Object> parsePath(String path) {
- ArrayList<Object> result = new ArrayList<Object>();
- String trimmedPath = path.trim();
-
- StringBuffer sb = new StringBuffer();
- boolean escapedState = false;
- int pathLength = trimmedPath.length();
-
- //unescape
- for (int i = 0; i < pathLength; i++) {
- char c = trimmedPath.charAt(i);
-
- if (SEPARATOR_ESCAPE_CHAR == c) {
- if (escapedState) {
- sb.append(c);
- }
- escapedState = !escapedState;
- } else {
- if (c == AbstractTreeDataModel.SEPARATOR) {
- if (escapedState) {
- sb.append(c);
- } else {
- result.add(sb.toString());
- sb = new StringBuffer();
- }
- } else {
- sb.append(c);
- }
-
- escapedState = false;
- }
- }
-
- if (sb.length() != 0) {
- result.add(sb.toString());
- }
-
- return result;
- }
-
/**
* List constructor
* @param list List of strings to create corresponding row key from
*/
- public ListRowKey(List<Object> list) {
+ public ListRowKey(List<T> list) {
super();
- this.path = new ArrayList<Object>(list);
+ this.path = new ArrayList<T>(list);
}
/**
* Path object constructor
* @param path first path segment
*/
- public ListRowKey(Object path) {
+ public ListRowKey(T path) {
super();
- this.path = new ArrayList<Object>(1);
+ this.path = new ArrayList<T>(1);
this.path.add(path);
}
- /**
- * Path string constructor
- * @param path path string to create corresponding row key from
- */
- public ListRowKey(String path) {
- super();
- this.path = parsePath(path);
- }
-
public int depth() {
return path.size();
}
- public Iterator<Object> iterator() {
+ public Iterator<T> iterator() {
return path.iterator();
}
@@ -166,7 +119,7 @@
return false;
if (getClass() != obj.getClass())
return false;
- final ListRowKey other = (ListRowKey) obj;
+ final ListRowKey<?> other = (ListRowKey<?>) obj;
if (path == null) {
if (other.path != null)
return false;
@@ -175,17 +128,19 @@
return true;
}
- public Iterator<Object> getSubPathIterator(int fromIndex) {
+ public Iterator<T> getSubPathIterator(int fromIndex) {
return path.listIterator(fromIndex);
}
- public ListRowKey getSubKey(int fromIndex) {
- return new ListRowKey(path.subList(fromIndex, path.size()));
+ public ListRowKey<T> getSubKey(int fromIndex) {
+ return new ListRowKey<T>(path.subList(fromIndex, path.size()));
}
- public boolean isSubKey(TreeRowKey rowKey) {
+
+ @SuppressWarnings("unchecked")
+ public boolean isSubKey(TreeRowKey<T> rowKey) {
if (rowKey instanceof ListRowKey) {
- ListRowKey listRowKey = (ListRowKey) rowKey;
+ ListRowKey<T> listRowKey = (ListRowKey<T>) rowKey;
return depth() == getCommonPathLength(listRowKey);
} else {
@@ -195,7 +150,7 @@
public String getPath() {
StringBuffer result = new StringBuffer();
- Iterator<Object> iterator = path.iterator();
+ Iterator<T> iterator = path.iterator();
boolean hasNext = iterator.hasNext();
while (hasNext) {
@@ -225,11 +180,11 @@
return result.toString();
}
- public int getCommonPathLength(TreeRowKey otherRowKey) {
+ public int getCommonPathLength(TreeRowKey<T> otherRowKey) {
if (otherRowKey == null)
return 0;
- Iterator<Object> iterator = this.iterator();
- Iterator<?> otherIterator = otherRowKey.iterator();
+ Iterator<T> iterator = this.iterator();
+ Iterator<T> otherIterator = otherRowKey.iterator();
int length = 0;
while (iterator.hasNext() && otherIterator.hasNext()
&& iterator.next().equals(otherIterator.next()))
@@ -237,7 +192,7 @@
return length;
}
- public Object get(int i) {
+ public T get(int i) {
return path.get(i);
}
}
Modified: trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
===================================================================
---
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java 2008-03-19
18:20:02 UTC (rev 6977)
+++
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java 2008-03-19
18:20:07 UTC (rev 6978)
@@ -34,7 +34,7 @@
//structural elements
private StackingTreeModel parent;
- private Map models = new LinkedHashMap();
+ private Map<String, StackingTreeModel> models = new LinkedHashMap<String,
StackingTreeModel>();
private Object rowKey;
@@ -52,7 +52,7 @@
private Object rowData;
// private StackingTreeModel stackingTreeModel;
- private LinkedList stackEntries = new LinkedList();
+ private LinkedList<StackEntry> stackEntries = new LinkedList<StackEntry>();
public ExtendedDataModel getDataModel() {
Object data = dataProvider.getData();
@@ -85,12 +85,12 @@
return getDataModel().getRowCount() == 0;
}
- private void leaveModel(Iterator iterator, StackEntry currentEntry, FacesContext
context) {
+ private void leaveModel(Iterator<StackEntry> iterator, StackEntry currentEntry,
FacesContext context) {
if (iterator == null) {
return ;
}
- LinkedList stack = new LinkedList();
+ LinkedList<StackEntry> stack = new LinkedList<StackEntry>();
StackingTreeModel lastModel = null;
if (currentEntry != null) {
@@ -110,13 +110,13 @@
iterator.remove();
}
- for (Iterator iterator2 = stack.iterator(); iterator2.hasNext();) {
+ for (Iterator<StackEntry> iterator2 = stack.iterator(); iterator2.hasNext();) {
StackEntry stackEntry = (StackEntry) iterator2.next();
stackEntry.model.setupVariable(stackEntry.varObject, context);
}
}
- protected StackingTreeModel doSetupKey(Iterator keyIterator, Iterator entriesIterator,
FacesContext context, Object modelKey) {
+ protected StackingTreeModel doSetupKey(Iterator<Key> keyIterator,
Iterator<StackEntry> entriesIterator, FacesContext context, Object modelKey) {
if (modelKey != null) {
if (!setupModel(modelKey, context)) {
//no key is available
@@ -126,13 +126,13 @@
}
if (keyIterator != null && keyIterator.hasNext()) {
- Key key = (Key) keyIterator.next();
+ Key key = keyIterator.next();
StackingTreeModel stackingTreeModel = this.getInternalModelById(key.modelId);
- Iterator nextEntriesIterator = null;
+ Iterator<StackEntry> nextEntriesIterator = null;
Object nextModelKey = key.modelKey;
if (entriesIterator != null && entriesIterator.hasNext()) {
- StackEntry entry = (StackEntry) entriesIterator.next();
+ StackEntry entry = entriesIterator.next();
if (!entry.model.equals(stackingTreeModel) || !entry.modelKey.equals(nextModelKey))
{
leaveModel(entriesIterator, entry, context);
} else {
@@ -156,12 +156,12 @@
if (stackEntries.isEmpty()) {
return this;
} else {
- return ((StackEntry) stackEntries.getLast()).model;
+ return (stackEntries.getLast()).model;
}
} else {
- Iterator keyIterator = null;
+ Iterator<Key> keyIterator = null;
if (key != null) {
- keyIterator = ((ListRowKey) key).iterator();
+ keyIterator = ((ListRowKey<Key>) key).iterator();
}
StackingTreeModel model = doSetupKey(keyIterator, stackEntries.iterator(), context,
null);
Modified: trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModel.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModel.java 2008-03-19
18:20:02 UTC (rev 6977)
+++ trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModel.java 2008-03-19
18:20:07 UTC (rev 6978)
@@ -308,7 +308,7 @@
return clazz.cast(wrappedData);
}
- public TreeNode getTreeNode() {
+ public TreeNode<T> getTreeNode() {
return null;
}
Modified:
trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java
===================================================================
---
trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java 2008-03-19
18:20:02 UTC (rev 6977)
+++
trunk/framework/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java 2008-03-19
18:20:07 UTC (rev 6978)
@@ -52,6 +52,7 @@
/**
* Instance of {@link TreeDataModelNodeAdaptor} for {@link org.richfaces.model.TreeNode}
nodes handling
*/
+ @SuppressWarnings("unchecked")
public static final TreeDataModelNodeAdaptor<org.richfaces.model.TreeNode>
classicTreeNodeAdaptor =
new TreeDataModelNodeAdaptor<org.richfaces.model.TreeNode>() {
Modified: trunk/framework/api/src/main/java/org/richfaces/model/TreeNode.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/TreeNode.java 2008-03-19
18:20:02 UTC (rev 6977)
+++ trunk/framework/api/src/main/java/org/richfaces/model/TreeNode.java 2008-03-19
18:20:07 UTC (rev 6978)
@@ -31,18 +31,18 @@
* @author Nick Belaevski - nbelaevski(a)exadel.com
* created 16.11.2006
*/
-public interface TreeNode extends Serializable{
+public interface TreeNode<T> extends Serializable{
/**
* getter for node attached data
* @return node attached data
*/
- public Object getData();
+ public T getData();
/**
* setter for node attached data
* @param data data to set as attached node data
*/
- public void setData(Object data);
+ public void setData(T data);
/**
* Returns whether this node is leaf
@@ -55,20 +55,20 @@
* @return {@link Iterator} of {@link Map.Entry} instances containing {@link TreeNode}
as values
* and their identifiers as keys
*/
- public Iterator<Map.Entry<Object, TreeNode>> getChildren();
+ public Iterator<Map.Entry<Object, TreeNode<T>>> getChildren();
/**
* find child by id
* @param id identifier of the child to find
* @return designated {@link TreeNode} instance or <code>null</code>
*/
- public TreeNode getChild(Object id);
+ public TreeNode<T> getChild(Object id);
/**
* adds child to children collection
* @param identifier child identifier
* @param child child
*/
- public void addChild(Object identifier, TreeNode child);
+ public void addChild(Object identifier, TreeNode<T> child);
/**
* removes child from children collection by child id
@@ -80,10 +80,10 @@
* getter for parent {@link TreeNode}
* @return parent {@link TreeNode} instance or <code>null</code> if this
node is root
*/
- public TreeNode getParent();
+ public TreeNode<T> getParent();
/**
* setter for parent {@link TreeNode}
* @param parent {@link TreeNode} to set as parent
*/
- public void setParent(TreeNode parent);
+ public void setParent(TreeNode<T> parent);
}
Modified: trunk/framework/api/src/main/java/org/richfaces/model/TreeNodeImpl.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/TreeNodeImpl.java 2008-03-19
18:20:02 UTC (rev 6977)
+++ trunk/framework/api/src/main/java/org/richfaces/model/TreeNodeImpl.java 2008-03-19
18:20:07 UTC (rev 6978)
@@ -32,47 +32,48 @@
* @author Nick Belaevski - nbelaevski(a)exadel.com
* created 16.11.2006
*/
-public class TreeNodeImpl implements TreeNode {
+public class TreeNodeImpl<T> implements TreeNode<T> {
private static final long serialVersionUID = -5498990493803705085L;
- private Object data;
- private TreeNode parent;
+ private T data;
+ private TreeNode<T> parent;
- private Map childrenMap = new LinkedHashMap();
+ private Map<Object, TreeNode<T>> childrenMap =
+ new LinkedHashMap<Object, TreeNode<T>>();
- public Object getData() {
+ public T getData() {
return data;
}
- public TreeNode getChild(Object identifier) {
- return (TreeNode) childrenMap.get(identifier);
+ public TreeNode<T> getChild(Object identifier) {
+ return (TreeNode<T>) childrenMap.get(identifier);
}
- public void addChild(Object identifier, TreeNode child) {
+ public void addChild(Object identifier, TreeNode<T> child) {
child.setParent(this);
childrenMap.put(identifier, child);
}
public void removeChild(Object identifier) {
- TreeNode treeNode = (TreeNode) childrenMap.remove(identifier);
+ TreeNode<T> treeNode = childrenMap.remove(identifier);
if (treeNode != null) {
treeNode.setParent(null);
}
}
- public void setData(Object data) {
+ public void setData(T data) {
this.data = data;
}
- public TreeNode getParent() {
+ public TreeNode<T> getParent() {
return parent;
}
- public void setParent(TreeNode parent) {
+ public void setParent(TreeNode<T> parent) {
this.parent = parent;
}
- public Iterator getChildren() {
+ public Iterator<Map.Entry<Object, TreeNode<T>>> getChildren() {
return childrenMap.entrySet().iterator();
}
Modified: trunk/framework/api/src/main/java/org/richfaces/model/TreeRowKey.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/TreeRowKey.java 2008-03-19
18:20:02 UTC (rev 6977)
+++ trunk/framework/api/src/main/java/org/richfaces/model/TreeRowKey.java 2008-03-19
18:20:07 UTC (rev 6978)
@@ -29,7 +29,7 @@
* @author Nick Belaevski - nbelaevski(a)exadel.com
* created 06.12.2006
*/
-public abstract class TreeRowKey implements Serializable {
+public abstract class TreeRowKey<T> implements Serializable {
/**
*
@@ -49,7 +49,7 @@
* @param fromIndex
* @return subpath segments iterator
*/
- public abstract Iterator<?> getSubPathIterator(int fromIndex);
+ public abstract Iterator<T> getSubPathIterator(int fromIndex);
/**
* getter for path string representation
@@ -66,7 +66,7 @@
* @param rowKey
* @return
*/
- public boolean isSubKey(TreeRowKey rowKey) {
+ public boolean isSubKey(TreeRowKey<T> rowKey) {
if (rowKey == null) {
return false;
}
@@ -78,13 +78,13 @@
* getter for path iterator
* @return path segments iterator
*/
- public abstract Iterator<?> iterator();
+ public abstract Iterator<T> iterator();
/**
* returns this row key and otherRowKey argument row key common path segments count
* @param otherRowKey {@link TreeRowKey} to count common path segments for
* @return common path segmments count
*/
- public abstract int getCommonPathLength(TreeRowKey otherRowKey);
+ public abstract int getCommonPathLength(TreeRowKey<T> otherRowKey);
}