44import com .google .common .collect .ImmutableList ;
55import graphql .Internal ;
66import graphql .PublicApi ;
7+ import graphql .collect .ImmutableKit ;
78import graphql .util .TraversalControl ;
89import graphql .util .TraverserContext ;
910
10- import java .util .ArrayList ;
1111import java .util .LinkedHashMap ;
1212import java .util .List ;
1313import java .util .Map ;
2121@ PublicApi
2222public class ArrayValue extends AbstractNode <ArrayValue > implements Value <ArrayValue > {
2323
24- private final ImmutableList <Value > values ;
25-
2624 public static final String CHILD_VALUES = "values" ;
25+ private final ImmutableList <Value > values ;
2726
2827 @ Internal
2928 protected ArrayValue (List <Value > values , SourceLocation sourceLocation , List <Comment > comments , IgnoredChars ignoredChars , Map <String , String > additionalData ) {
@@ -40,6 +39,10 @@ public ArrayValue(List<Value> values) {
4039 this (values , null , emptyList (), IgnoredChars .EMPTY , emptyMap ());
4140 }
4241
42+ public static Builder newArrayValue () {
43+ return new Builder ();
44+ }
45+
4346 public List <Value > getValues () {
4447 return values ;
4548 }
@@ -92,10 +95,6 @@ public TraversalControl accept(TraverserContext<Node> context, NodeVisitor visit
9295 return visitor .visitArrayValue (this , context );
9396 }
9497
95- public static Builder newArrayValue () {
96- return new Builder ();
97- }
98-
9998 public ArrayValue transform (Consumer <Builder > builderConsumer ) {
10099 Builder builder = new Builder (this );
101100 builderConsumer .accept (builder );
@@ -104,8 +103,8 @@ public ArrayValue transform(Consumer<Builder> builderConsumer) {
104103
105104 public static final class Builder implements NodeBuilder {
106105 private SourceLocation sourceLocation ;
107- private List <Value > values = new ArrayList <> ();
108- private List <Comment > comments = new ArrayList <> ();
106+ private ImmutableList <Value > values = emptyList ();
107+ private ImmutableList <Comment > comments = emptyList ();
109108 private IgnoredChars ignoredChars = IgnoredChars .EMPTY ;
110109 private Map <String , String > additionalData = new LinkedHashMap <>();
111110
@@ -114,8 +113,8 @@ private Builder() {
114113
115114 private Builder (ArrayValue existing ) {
116115 this .sourceLocation = existing .getSourceLocation ();
117- this .comments = existing .getComments ();
118- this .values = existing .getValues ();
116+ this .comments = ImmutableList . copyOf ( existing .getComments () );
117+ this .values = ImmutableList . copyOf ( existing .getValues () );
119118 this .ignoredChars = existing .getIgnoredChars ();
120119 this .additionalData = new LinkedHashMap <>(existing .getAdditionalData ());
121120 }
@@ -126,17 +125,17 @@ public Builder sourceLocation(SourceLocation sourceLocation) {
126125 }
127126
128127 public Builder values (List <Value > values ) {
129- this .values = values ;
128+ this .values = ImmutableList . copyOf ( values ) ;
130129 return this ;
131130 }
132131
133132 public Builder value (Value value ) {
134- this .values . add ( value );
133+ this .values = ImmutableKit . addToList ( this . values , value );
135134 return this ;
136135 }
137136
138137 public Builder comments (List <Comment > comments ) {
139- this .comments = comments ;
138+ this .comments = ImmutableList . copyOf ( comments ) ;
140139 return this ;
141140 }
142141
0 commit comments