20
20
import com .datastax .oss .driver .api .core .data .GettableById ;
21
21
import com .datastax .oss .driver .api .core .data .GettableByName ;
22
22
import com .datastax .oss .driver .internal .core .util .Strings ;
23
+ import com .datastax .oss .driver .shaded .guava .common .collect .ArrayListMultimap ;
24
+ import com .datastax .oss .driver .shaded .guava .common .collect .ImmutableListMultimap ;
23
25
import com .datastax .oss .driver .shaded .guava .common .collect .LinkedListMultimap ;
24
26
import com .datastax .oss .driver .shaded .guava .common .collect .ListMultimap ;
27
+ import java .util .Iterator ;
25
28
import java .util .List ;
26
29
import java .util .Locale ;
27
30
import net .jcip .annotations .Immutable ;
@@ -40,9 +43,9 @@ public class IdentifierIndex {
40
43
private final ListMultimap <String , Integer > byCaseInsensitiveName ;
41
44
42
45
public IdentifierIndex (List <CqlIdentifier > ids ) {
43
- this . byId = LinkedListMultimap . create ( ids . size () );
44
- this . byCaseSensitiveName = LinkedListMultimap . create ( ids . size () );
45
- this . byCaseInsensitiveName = LinkedListMultimap . create ( ids . size () );
46
+ ImmutableListMultimap . Builder < CqlIdentifier , Integer > byId = ImmutableListMultimap . builder ( );
47
+ ImmutableListMultimap . Builder < String , Integer > byCaseSensitiveName = ImmutableListMultimap . builder ( );
48
+ ImmutableListMultimap . Builder < String , Integer > byCaseInsensitiveName = ImmutableListMultimap . builder ( );
46
49
47
50
int i = 0 ;
48
51
for (CqlIdentifier id : ids ) {
@@ -51,6 +54,10 @@ public IdentifierIndex(List<CqlIdentifier> ids) {
51
54
byCaseInsensitiveName .put (id .asInternal ().toLowerCase (Locale .ROOT ), i );
52
55
i += 1 ;
53
56
}
57
+
58
+ this .byId = byId .build ();
59
+ this .byCaseSensitiveName = byCaseSensitiveName .build ();
60
+ this .byCaseInsensitiveName = byCaseInsensitiveName .build ();
54
61
}
55
62
56
63
/**
@@ -68,8 +75,8 @@ public List<Integer> allIndicesOf(String name) {
68
75
* AccessibleByName}, or -1 if it's not in the list.
69
76
*/
70
77
public int firstIndexOf (String name ) {
71
- List <Integer > indices = allIndicesOf (name );
72
- return indices .isEmpty () ? -1 : indices .get ( 0 );
78
+ Iterator <Integer > indices = allIndicesOf (name ). iterator ( );
79
+ return indices .hasNext () ? -1 : indices .next ( );
73
80
}
74
81
75
82
/** Returns all occurrences of a given identifier. */
@@ -79,7 +86,7 @@ public List<Integer> allIndicesOf(CqlIdentifier id) {
79
86
80
87
/** Returns the first occurrence of a given identifier, or -1 if it's not in the list. */
81
88
public int firstIndexOf (CqlIdentifier id ) {
82
- List <Integer > indices = allIndicesOf (id );
83
- return indices .isEmpty () ? -1 : indices .get ( 0 );
89
+ Iterator <Integer > indices = allIndicesOf (id ). iterator ( );
90
+ return indices .hasNext () ? -1 : indices .next ( );
84
91
}
85
92
}
0 commit comments