]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/annotations/ArgumentImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / annotations / ArgumentImpl.java
1 package org.simantics.databoard.annotations;
2
3 import java.lang.annotation.Annotation;
4 import java.lang.reflect.Array;
5 import java.util.Arrays;
6
7 public class ArgumentImpl implements Arguments {
8
9         int hash;
10         Class<?>[] args;
11         
12         public ArgumentImpl(Class<?>...args) {
13         hash = Arrays.hashCode(args);
14                 this.args = args;
15         }
16
17         
18         /**
19          * Drop first arguments from an argument list. 
20          * If all were dropped, null is returned.
21          *
22          * @param src source argument or null
23          * @param count argument count
24          * @return Argument or null.
25          */
26         public static Arguments dropArguments(Arguments src, int count) {
27                 if (src==null) return null;
28                 int newLen = src.value().length - count;
29                 if (newLen<=0) return null;
30                 Class<?>[] newList = (Class<?>[]) Array.newInstance(Class.class, newLen);
31                 System.arraycopy(src.value(), count, newList, 0, newLen);
32                 return new ArgumentImpl(newList);
33         }       
34         
35         @Override
36         public Class<? extends Annotation> annotationType() {
37                 return Arguments.class;
38         }
39
40         @Override
41         public Class<?>[] value() {
42                 return args;
43         }
44         
45         @Override
46         public int hashCode() {         
47                 return hash;
48         }
49         
50         @Override
51         public boolean equals(Object obj) {
52                 if ( obj instanceof Arguments == false ) return false;
53                 Arguments other = (Arguments) obj;
54                 Class<?>[] classArray1 = args;
55                 Class<?>[] classArray2 = other.value();
56                 
57                 return Arrays.deepEquals(classArray1, classArray2);
58         }
59
60 }