/** * Get the children of this node. */ public List getChildren() { if(children==null) { children = new ArrayList(); Iterator it = fields.iterator(); while(it.hasNext()) { Field f = (Field) it.next(); try { children.add(new ObjectInspectorAttributeNode(this, f, null)); } catch (IllegalAccessException e) { // Field not accessible - ignore for children ? children.add("-ERROR- Exception occurred: " +e); } } } return children; }
&& ((ObjectInspectorAttributeNode)children.get(i)).equals(child, false))
/** * Get the given child of a node. */ public Object getChild(Object parent, int index) { // System.out.println("getChild: "+parent+", "+index); Object ret; // Node for an ObjectInspector object. if(parent instanceof ObjectInspectorNode) { ret = ((ObjectInspectorNode)parent).getChildren().get(index); } // Node for an ObjectAttributeInspector object. else if(parent instanceof ObjectInspectorAttributeNode) { ret = ((ObjectInspectorAttributeNode)parent).getChildren().get(index); } // Value node has no children. else { throw new IllegalArgumentException("Node has no children: "+parent); } return ret; }
List newchildren = node.getChildren(); node.children = oldchildren; if (node.isArrayNode()) fireTreeStructureChanged(node.getPath()); event = new TreeModelEvent(this, node.getPath(), indexes, childs); for(int i=0; i<alisteners.length; i++) event = new TreeModelEvent(this, node.getPath(), insertedIndexes, insertedChilds); for(int i=0; i<alisteners.length; i++) fireTreeStructureChanged((Object[]) SUtil.joinArrays(node.getPath(), new Object[]{oldchildren.get(0)})); event = new TreeModelEvent(this, node.getPath(), new int[]{0}, new Object[]{oldchildren.get(0)});
if(isArrayNode()) attributeValue = getFieldValue(); this.attributeValue = getFieldValue();
/** * Get a string representation of this node */ public String toString() { String len = ""; try { //if (type.isArray()) if (isArrayNode()) { Object arrayValue = getFieldValue(); len = (arrayValue !=null ? ""+ Array.getLength(arrayValue) : "null"); } } catch (Exception e) { e.printStackTrace(); len = "-ERROR-"; } return (name != null ? name : "?? INVALID NODE NAME ??") //+ (type.isArray() ? "["+len+"]" : "") + (isArrayNode() ? "["+len+"]" : "") //+ (attributeValue!=null? " = "+attributeValue: " (null)") ; }
/** * Get the number of children of the given node. */ public int getChildCount(Object parent) { // System.out.println("getChildCount: "+parent); int count; // Node for an ObjectInspector object. if(parent instanceof ObjectInspectorNode) { count = ((ObjectInspectorNode)parent).getChildren().size(); } // Node for an ObjectAttributeInspector object. else if(parent instanceof ObjectInspectorAttributeNode) { count = ((ObjectInspectorAttributeNode)parent).getChildren().size(); } // Node is value. else { count = 0; } return count; }
/** * Get the path of this node (inclusive) starting from the root node. */ public Object[] getPath() { if(path==null) { if (parent != null) { if(parent instanceof ObjectInspectorAttributeNode) { path = (Object[])SUtil.joinArrays(((ObjectInspectorAttributeNode)parent).getPath(), new Object[]{this}); } else { path = new Object[]{parent, this}; } } else { path = new Object[]{this}; } } return path; }
/** * Returns the value for the represented field from the parent object inspector node * If this field is an array, the value from the array index represented * by this node is returned. When access to the array is needed, e.g. to * create the the node children, use getFieldValue() instead. * @return */ protected Object getArrayValue() { try { if (isArrayNode()) { return Array.get(field.get(((ObjectInspectorNode)parent).getNodeObject()), ((ObjectInspectorNode)parent).getChildren().indexOf(this)/*-1*/); } else return "-ERROR- getArrayValue called on a non array type"; } catch (Exception e) { //e.printStackTrace(); return "-ERROR- Exception occurred: " + e; } }
public boolean equals(Object obj) { return equals(obj, true); }
protected boolean isArrayNode() { attributeValue = getFieldValue(); return type.isArray() || (attributeValue != null && attributeValue.getClass().isArray()); }