/
FieldList.java
97 lines (80 loc) · 2.71 KB
/
FieldList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package net.bytebuddy.description.field;
import net.bytebuddy.matcher.FilterableList;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
/**
* Implementations represent a list of field descriptions.
*/
public interface FieldList extends FilterableList<FieldDescription, FieldList> {
abstract class AbstractBase extends FilterableList.AbstractBase<FieldDescription, FieldList> implements FieldList {
@Override
protected FieldList wrap(List<FieldDescription> values) {
return new Explicit(values);
}
}
/**
* An implementation of a field list for an array of loaded fields.
*/
class ForLoadedField extends AbstractBase {
/**
* The loaded fields this field list represents.
*/
private final List<? extends Field> fields;
/**
* Creates a new immutable field list that represents an array of loaded field.
*
* @param field An array of fields to be represented by this field list.
*/
public ForLoadedField(Field... field) {
this(Arrays.asList(field));
}
/**
* Creates a new immutable field list that represents an array of loaded field.
*
* @param fields An array of fields to be represented by this field list.
*/
public ForLoadedField(List<? extends Field> fields) {
this.fields = fields;
}
@Override
public FieldDescription get(int index) {
return new FieldDescription.ForLoadedField(fields.get(index));
}
@Override
public int size() {
return fields.size();
}
}
/**
* A wrapper implementation of a field list for a given list of field descriptions.
*/
class Explicit extends AbstractBase {
/**
* The list of field descriptions this list represents.
*/
private final List<? extends FieldDescription> fieldDescriptions;
/**
* Creates a new immutable wrapper field list.
*
* @param fieldDescriptions The list of fields to be represented by this field list.
*/
public Explicit(List<? extends FieldDescription> fieldDescriptions) {
this.fieldDescriptions = fieldDescriptions;
}
@Override
public FieldDescription get(int index) {
return fieldDescriptions.get(index);
}
@Override
public int size() {
return fieldDescriptions.size();
}
}
/**
* An implementation of an empty field list.
*/
class Empty extends FilterableList.Empty<FieldDescription, FieldList> implements FieldList {
/* empty */
}
}