1 11 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints; 12 13 import java.util.Arrays ; 14 import java.util.Comparator ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.Assert; 18 19 20 public class CompositeOrTypeConstraint implements ITypeConstraint{ 21 22 private final ITypeConstraint[] fConstraints; 23 24 CompositeOrTypeConstraint(ITypeConstraint[] constraints){ 25 Assert.isNotNull(constraints); 26 fConstraints= sort(getCopy(constraints)); 27 } 28 29 private static ITypeConstraint[] getCopy(ITypeConstraint[] constraints) { 30 List l= Arrays.asList(constraints); 31 return (ITypeConstraint[]) l.toArray(new ITypeConstraint[l.size()]); 32 } 33 34 private static ITypeConstraint[] sort(ITypeConstraint[] constraints) { 35 Arrays.sort(constraints, new Comparator (){ 37 public int compare(Object o1, Object o2) { 38 return o2.toString().compareTo(o1.toString()); 39 } 40 }); 41 return constraints; 42 } 43 44 47 public String toResolvedString() { 48 StringBuffer buff= new StringBuffer (); 49 for (int i= 0; i < fConstraints.length; i++) { 50 ITypeConstraint constraint= fConstraints[i]; 51 if (i > 0) 52 buff.append(" or "); buff.append(constraint.toResolvedString()); 54 } 55 return buff.toString(); 56 } 57 58 61 public boolean isSimpleTypeConstraint() { 62 return false; 63 } 64 65 68 public String toString() { 69 StringBuffer buff= new StringBuffer (); 70 for (int i= 0; i < fConstraints.length; i++) { 71 ITypeConstraint constraint= fConstraints[i]; 72 if (i > 0) 73 buff.append(" or "); buff.append(constraint.toString()); 75 } 76 return buff.toString(); 77 } 78 79 public ITypeConstraint[] getConstraints() { 80 return fConstraints; 81 } 82 } 83 | Popular Tags |