1 17 package org.alfresco.service.cmr.repository; 18 19 import java.io.Serializable ; 20 21 import org.alfresco.service.namespace.QName; 22 import org.alfresco.util.EqualsHelper; 23 24 38 public class ChildAssociationRef 39 implements EntityRef, Comparable <ChildAssociationRef>, Serializable 40 { 41 private static final long serialVersionUID = 4051322336257127729L; 42 43 private QName assocTypeQName; 44 private NodeRef parentRef; 45 private QName childQName; 46 private NodeRef childRef; 47 private boolean isPrimary; 48 private int nthSibling; 49 50 51 68 public ChildAssociationRef( 69 QName assocTypeQName, 70 NodeRef parentRef, 71 QName childQName, 72 NodeRef childRef, 73 boolean isPrimary, 74 int nthSibling) 75 { 76 this.assocTypeQName = assocTypeQName; 77 this.parentRef = parentRef; 78 this.childQName = childQName; 79 this.childRef = childRef; 80 this.isPrimary = isPrimary; 81 this.nthSibling = nthSibling; 82 83 if (childRef == null) 85 { 86 throw new IllegalArgumentException ("Child reference may not be null"); 87 } 88 } 89 90 96 public ChildAssociationRef(QName assocTypeQName, NodeRef parentRef, QName childQName, NodeRef childRef) 97 { 98 this(assocTypeQName, parentRef, childQName, childRef, false, -1); 99 } 100 101 110 public boolean equals(Object o) 111 { 112 if (this == o) 113 { 114 return true; 115 } 116 if (!(o instanceof ChildAssociationRef)) 117 { 118 return false; 119 } 120 ChildAssociationRef other = (ChildAssociationRef) o; 121 122 return (EqualsHelper.nullSafeEquals(this.assocTypeQName, other.assocTypeQName) 123 && EqualsHelper.nullSafeEquals(this.parentRef, other.parentRef) 124 && EqualsHelper.nullSafeEquals(this.childQName, other.childQName) 125 && EqualsHelper.nullSafeEquals(this.childRef, other.childRef)); 126 } 127 128 public int hashCode() 129 { 130 int hashCode = ((getTypeQName() == null) ? 0 : getTypeQName().hashCode()); 131 hashCode = 37 * hashCode + ((getParentRef() == null) ? 0 : getParentRef().hashCode()); 132 hashCode = 37 * hashCode + ((getQName() == null) ? 0 : getQName().hashCode()); 133 hashCode = 37 * hashCode + getChildRef().hashCode(); 134 return hashCode; 135 } 136 137 140 public int compareTo(ChildAssociationRef another) 141 { 142 int thisVal = this.nthSibling; 143 int anotherVal = another.nthSibling; 144 return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1)); 145 } 146 147 public String toString() 148 { 149 StringBuffer sb = new StringBuffer (); 150 sb.append("[").append(getTypeQName()).append("]"); 151 sb.append(getParentRef()); 152 sb.append(" --- ").append(getQName()).append(" ---> "); 153 sb.append(getChildRef()); 154 return sb.toString(); 155 } 156 157 164 public QName getTypeQName() 165 { 166 return assocTypeQName; 167 } 168 169 175 public QName getQName() 176 { 177 return childQName; 178 } 179 180 183 public NodeRef getChildRef() 184 { 185 return childRef; 186 } 187 188 192 public NodeRef getParentRef() 193 { 194 return parentRef; 195 } 196 197 200 public boolean isPrimary() 201 { 202 return isPrimary; 203 } 204 205 208 public int getNthSibling() 209 { 210 return nthSibling; 211 } 212 213 224 public void setNthSibling(int nthSibling) 225 { 226 this.nthSibling = nthSibling; 227 } 228 } 229 | Popular Tags |