| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.query; |
| 9 |
|
| 10 |
import net.sf.saxon.lib.NamespaceConstant; |
| 11 |
import net.sf.saxon.om.StructuredQName; |
| 12 |
import net.sf.saxon.value.AtomicValue; |
| 13 |
import net.sf.saxon.value.NumericValue; |
| 14 |
import net.sf.saxon.value.StringValue; |
| 15 |
|
| 16 |
import java.util.ArrayList; |
| 17 |
import java.util.List; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public class Annotation { |
| 23 |
|
| 24 |
public static final StructuredQName UPDATING = new StructuredQName("", NamespaceConstant.XQUERY, "updating"); |
| 25 |
public static final StructuredQName SIMPLE = new StructuredQName("", NamespaceConstant.XQUERY, "simple"); |
| 26 |
public static final StructuredQName PRIVATE = new StructuredQName("", NamespaceConstant.XQUERY, "private"); |
| 27 |
public static final StructuredQName PUBLIC = new StructuredQName("", NamespaceConstant.XQUERY, "public"); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
private StructuredQName qName = null; |
| 32 |
|
| 33 |
|
| 34 |
private List<AtomicValue> annotationParameters = null; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public Annotation(StructuredQName name) { |
| 43 |
this.qName = name; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public StructuredQName getAnnotationQName() { |
| 53 |
return qName; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public void addAnnotationParameter(AtomicValue value) { |
| 64 |
if (annotationParameters == null) { |
| 65 |
annotationParameters = new ArrayList<>(); |
| 66 |
} |
| 67 |
annotationParameters.add(value); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public List<AtomicValue> getAnnotationParameters() { |
| 77 |
if (annotationParameters == null) { |
| 78 |
annotationParameters = new ArrayList<>(); |
| 79 |
} |
| 80 |
return annotationParameters; |
| 81 |
} |
| 82 |
|
| 83 |
public boolean equals(Object other) { |
| 84 |
if (!(other instanceof Annotation && |
| 85 |
qName.equals(((Annotation) other).qName) && |
| 86 |
getAnnotationParameters().size() == ((Annotation) other).getAnnotationParameters().size())) { |
| 87 |
return false; |
| 88 |
} |
| 89 |
for (int i = 0; i < annotationParameters.size(); i++) { |
| 90 |
if (!annotationParamEqual(annotationParameters.get(i), ((Annotation) other).annotationParameters.get(i))) { |
| 91 |
return false; |
| 92 |
} |
| 93 |
} |
| 94 |
return true; |
| 95 |
} |
| 96 |
|
| 97 |
private static boolean annotationParamEqual(AtomicValue a, AtomicValue b) { |
| 98 |
if (a instanceof StringValue && b instanceof StringValue) { |
| 99 |
return a.getStringValue().equals(b.getStringValue()); |
| 100 |
} else if (a instanceof NumericValue && b instanceof NumericValue) { |
| 101 |
return ((NumericValue) a).getDoubleValue() == ((NumericValue) b).getDoubleValue(); |
| 102 |
} else { |
| 103 |
return false; |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
public int hashCode() { |
| 109 |
return qName.hashCode() ^ annotationParameters.hashCode(); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
} |
| 114 |
|