View Javadoc
1   package com.puppycrawl.tools.checkstyle.checks.indentation.indentation; //indent:0 exp:0
2   
3   import java.util.AbstractMap; //indent:0 exp:0
4   import java.util.List; //indent:0 exp:0
5   import java.util.Set; //indent:0 exp:0
6   import java.util.concurrent.ConcurrentMap; //indent:0 exp:0
7   
8   import javax.xml.bind.annotation.XmlElement; //indent:0 exp:0
9   
10  
11  /**                                                                           //indent:0 exp:0
12   * This test-input is intended to be checked using following configuration:   //indent:1 exp:1
13   *                                                                            //indent:1 exp:1
14   * arrayInitIndent = 4                                                        //indent:1 exp:1
15   * basicOffset = 2                                                            //indent:1 exp:1
16   * braceAdjustment = 0                                                        //indent:1 exp:1
17   * caseIndent = 4                                                             //indent:1 exp:1
18   * forceStrictCondition = false                                               //indent:1 exp:1
19   * lineWrappingIndentation = 4                                                //indent:1 exp:1
20   * tabWidth = 4                                                               //indent:1 exp:1
21   * throwsIndent = 4                                                           //indent:1 exp:1
22   *                                                                            //indent:1 exp:1
23   *                                                                            //indent:1 exp:1
24   */                                                                           //indent:1 exp:1
25  class LocalCache<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K, V> { //indent:0 exp:0
26  
27    enum Strength { //indent:2 exp:2
28      /*                                                                                            //indent:4 exp:4
29       *     (kevinb): If we strongly reference the value and aren't loading, we needn't wrap the   //indent:5 exp:5
30       * value. This could save ~8 bytes per entry.                                                 //indent:5 exp:5
31       */                                                                                           //indent:5 exp:5
32  
33      STRONG { //indent:4 exp:4
34        <K, V> Object referenceValue( //indent:6 exp:6
35            Segment<K, V> segment, ReferenceEntry<K, V> entry, int value, int weight) { //indent:10 exp:>=10
36          return (weight == 1) //indent:8 exp:8
37              ? new StrongValueReference<K, V>(value) //indent:12 exp:>=12
38              : new WeightedStrongValueReference<K, V>(value, weight); //indent:12 exp:>=12
39        } //indent:6 exp:6
40  
41        @Override //indent:6 exp:6
42        List<Object> defaultEquivalence() { //indent:6 exp:6
43          return new java.util.ArrayList<>(); //indent:8 exp:8
44        } //indent:6 exp:6
45  
46        @Override //indent:6 exp:6
47       <K, V> ValueReference<K, V> referenceValue(Segment<K, V> segment, //indent:5 exp:5
48      		    ReferenceEntry<K, V> entry, V value, int weight) { //indent:16 exp:>=10
49  
50          return null; //indent:8 exp:8
51        } //indent:6 exp:6
52      }, //indent:4 exp:4
53  
54      SOFT { //indent:4 exp:4
55        <K, V> Object referenceValue1( //indent:6 exp:6
56            Segment<K, V> segment, ReferenceEntry<Integer, Integer> entry, int value, int weight) { //indent:10 exp:>=10
57          return (weight == 1) //indent:8 exp:8
58              ? new SoftValueReference<K, V>(segment.valueReferenceQueue, value, entry) //indent:12 exp:>=12
59              : new WeightedSoftValueReference<K, V>(); //indent:12 exp:>=12
60        } //indent:6 exp:6
61  
62        @Override //indent:6 exp:6
63        List<Object> defaultEquivalence() { //indent:6 exp:6
64          return new java.util.ArrayList<>(); //indent:8 exp:8
65        } //indent:6 exp:6
66  
67        @Override <K, V> Object referenceValue(Segment<K, V> segment, ReferenceEntry<K, V> entry, //indent:6 exp:6
68      		    V value, int weight) //indent:16 exp:>=10
69        { //indent:6 exp:6
70          return null; //indent:8 exp:8
71        } //indent:6 exp:6
72      }, //indent:4 exp:4
73  
74      WEAK { //indent:4 exp:4
75        @Override //indent:6 exp:6
76        <K, V> Object referenceValue( //indent:6 exp:6
77            Segment<K, V> segment, ReferenceEntry<K, V> entry, V value, int weight) { //indent:10 exp:>=10
78          return (weight == 1) //indent:8 exp:8
79              ? new WeakValueReference<K, V>() //indent:12 exp:>=12
80              : new WeightedWeakValueReference<K, V>(); //indent:12 exp:>=12
81        } //indent:6 exp:6
82  
83        @Override //indent:6 exp:6
84        List<Object> defaultEquivalence() { //indent:6 exp:6
85          return new java.util.ArrayList<>(); //indent:8 exp:8
86        } //indent:6 exp:6
87      }; //indent:4 exp:4
88  
89      /**                                                                          //indent:4 exp:4
90       * Creates a reference for the given value according to this value strength. //indent:5 exp:5
91       */                                                                          //indent:5 exp:5
92      abstract <K, V> Object referenceValue( //indent:4 exp:4
93          Segment<K, V> segment, ReferenceEntry<K, V> entry, V value, int weight); //indent:8 exp:>=8
94  
95      /**                                                                                            //indent:4 exp:4
96       * Returns the default equivalence strategy used to compare and hash keys or values referenced //indent:5 exp:5
97       * at this strength. This strategy will be used unless the user explicitly specifies an        //indent:5 exp:5
98       * alternate strategy.                                                                         //indent:5 exp:5
99       */                                                                                            //indent:5 exp:5
100     abstract List<Object> defaultEquivalence(); //indent:4 exp:4
101   } //indent:2 exp:2
102 
103   /**                        //indent:2 exp:2
104    * Creates new entries.    //indent:3 exp:3
105    */                        //indent:3 exp:3
106   enum EntryFactory { //indent:2 exp:2
107     STRONG { //indent:4 exp:4
108       <K, V> StrongEntry<K, V> newEntry( //indent:6 exp:6
109           Segment<K, V> segment, K key, int hash, @XmlElement ReferenceEntry<K, V> next) { //indent:10 exp:>=10
110         return new StrongEntry<K, V>(); //indent:8 exp:8
111       } //indent:6 exp:6
112     }, //indent:4 exp:4
113     STRONG_ACCESS { //indent:4 exp:4
114       <K, V> StrongAccessEntry<K, V> newEntry( //indent:6 exp:6
115           Segment<K, V> segment, K key, int hash, @XmlElement ReferenceEntry<K, V> next) { //indent:10 exp:>=10
116         return new StrongAccessEntry<K, V>(key, hash, next); //indent:8 exp:8
117       } //indent:6 exp:6
118 
119       <K, V> ReferenceEntry<K, V> copyEntry( //indent:6 exp:6
120           Segment<K, V> segment, ReferenceEntry<K, V> original, ReferenceEntry<K, V> newNext) { //indent:10 exp:>=10
121         return newNext; //indent:8 exp:8
122       } //indent:6 exp:6
123       {; //indent:6 exp:6
124       } //indent:6 exp:6
125      }, //indent:5 exp:5
126     STRONG_WRITE { //indent:4 exp:4
127       <K, V> StrongEntry<K, V> newEntry( //indent:6 exp:6
128           Segment<K, V> segment, K key, int hash, @XmlElement ReferenceEntry<K, V> next) { //indent:10 exp:>=10
129         return new StrongEntry<K, V>(); //indent:8 exp:8
130       } //indent:6 exp:6
131 
132       <K, V> ReferenceEntry<K, V> copyEntry( //indent:6 exp:6
133           Segment<K, V> segment, ReferenceEntry<K, V> original, ReferenceEntry<K, V> newNext) { //indent:10 exp:>=10
134         return newNext; //indent:8 exp:8
135       } //indent:6 exp:6
136     }, //indent:4 exp:4
137     STRONG_ACCESS_WRITE { //indent:4 exp:4
138       <K, V> StrongEntry<K, V> newEntry( //indent:6 exp:6
139           Segment<K, V> segment, K key, int hash, @XmlElement ReferenceEntry<K, V> next) { //indent:10 exp:>=10
140         return new StrongEntry<K, V>(); //indent:8 exp:8
141       } //indent:6 exp:6
142 
143       <K, V> ReferenceEntry<K, V> copyEntry( //indent:6 exp:6
144           Segment<K, V> segment, ReferenceEntry<K, V> original, ReferenceEntry<K, V> newNext) { //indent:10 exp:>=10
145         return newNext; //indent:8 exp:8
146       } //indent:6 exp:6
147     }, //indent:4 exp:4
148 
149     WEAK { //indent:4 exp:4
150       <K, V> StrongEntry<K, V> newEntry( //indent:6 exp:6
151           Segment<K, V> segment, K key, int hash, @XmlElement ReferenceEntry<K, V> next) { //indent:10 exp:>=10
152         return new StrongEntry<K, V>(); //indent:8 exp:8
153       } //indent:6 exp:6
154     }, //indent:4 exp:4
155     WEAK_ACCESS { //indent:4 exp:4
156       <K, V> StrongEntry<K, V> newEntry( //indent:6 exp:6
157           Segment<K, V> segment, K key, int hash, @XmlElement ReferenceEntry<K, V> next) { //indent:10 exp:>=10
158         return new StrongEntry<K, V>(); //indent:8 exp:8
159       } //indent:6 exp:6
160 
161       <K, V> ReferenceEntry<K, V> copyEntry( //indent:6 exp:6
162           Segment<K, V> segment, ReferenceEntry<K, V> original, ReferenceEntry<K, V> newNext) { //indent:10 exp:>=10
163         return newNext; //indent:8 exp:8
164       } //indent:6 exp:6
165     }, //indent:4 exp:4
166     WEAK_WRITE { //indent:4 exp:4
167       <K, V> StrongEntry<K, V> newEntry( //indent:6 exp:6
168           Segment<K, V> segment, K key, int hash, @XmlElement ReferenceEntry<K, V> next) { //indent:10 exp:>=10
169         return new StrongEntry<K, V>(); //indent:8 exp:8
170       } //indent:6 exp:6
171 
172       <K, V> ReferenceEntry<K, V> copyEntry( //indent:6 exp:6
173           Segment<K, V> segment, ReferenceEntry<K, V> original, ReferenceEntry<K, V> newNext) { //indent:10 exp:>=10
174         return newNext; //indent:8 exp:8
175       } //indent:6 exp:6
176     }, //indent:4 exp:4
177     WEAK_ACCESS_WRITE { //indent:4 exp:4
178       <K, V> StrongEntry<K, V> newEntry( //indent:6 exp:6
179           Segment<K, V> segment, K key, int hash, @XmlElement ReferenceEntry<K, V> next) { //indent:10 exp:>=10
180         return new StrongEntry<K, V>(); //indent:8 exp:8
181       } //indent:6 exp:6
182 
183       <K, V> ReferenceEntry<K, V> copyEntry( //indent:6 exp:6
184           Segment<K, V> segment, ReferenceEntry<K, V> original, ReferenceEntry<K, V> newNext) { //indent:10 exp:>=10
185         return newNext; //indent:8 exp:8
186       } //indent:6 exp:6
187     }; //indent:4 exp:4
188   } //indent:2 exp:2
189 
190   @Override //indent:2 exp:2
191   public Set<java.util.Map.Entry<K, V>> entrySet() //indent:2 exp:2
192   { //indent:2 exp:2
193     return null; //indent:4 exp:4
194   } //indent:2 exp:2
195 
196   @Override //indent:2 exp:2
197   public V putIfAbsent(K key, V value) //indent:2 exp:2
198   { //indent:2 exp:2
199     return null; //indent:4 exp:4
200   } //indent:2 exp:2
201 
202   @Override //indent:2 exp:2
203   public boolean remove(Object key, Object value) //indent:2 exp:2
204   { //indent:2 exp:2
205     return false; //indent:4 exp:4
206   } //indent:2 exp:2
207 
208   @Override //indent:2 exp:2
209   public boolean replace(K key, V oldValue, V newValue) //indent:2 exp:2
210   { //indent:2 exp:2
211     return false; //indent:4 exp:4
212   } //indent:2 exp:2
213 
214   @Override //indent:2 exp:2
215   public V replace(K key, V value) //indent:2 exp:2
216   {  //indent:2 exp:2
217     return null; //indent:4 exp:4
218   } //indent:2 exp:2
219 
220   private static class ValueReference<T1, T2> { //indent:2 exp:2
221 
222   } //indent:2 exp:2
223 
224   private static class ReferenceEntry<T1, T2> { //indent:2 exp:2
225 
226   } //indent:2 exp:2
227 
228   private static class Segment<T1, T2> { //indent:2 exp:2
229 
230     protected Object valueReferenceQueue; //indent:4 exp:4
231 
232   } //indent:2 exp:2
233 
234   private static class StrongAccessEntry<T1, T2> { //indent:2 exp:2
235 
236     public StrongAccessEntry(T1 key, int hash, ReferenceEntry<T1, T2> next) //indent:4 exp:4
237     { //indent:4 exp:4
238 
239     } //indent:4 exp:4
240 
241   } //indent:2 exp:2
242 
243   private static class StrongValueReference<T1, T2> { //indent:2 exp:2
244 
245     public StrongValueReference(int value) //indent:4 exp:4
246     { //indent:4 exp:4
247 
248     } //indent:4 exp:4
249 
250   } //indent:2 exp:2
251 
252   private static class WeightedStrongValueReference<T1, T2> { //indent:2 exp:2
253 
254     public WeightedStrongValueReference(int value, int weight) //indent:4 exp:4
255     { //indent:4 exp:4
256 
257     } //indent:4 exp:4
258 
259   } //indent:2 exp:2
260 
261   private static class SoftValueReference<T1, T2> { //indent:2 exp:2
262 
263     public SoftValueReference(Object valueReferenceQueue, int value, //indent:4 exp:4
264               ReferenceEntry<Integer, Integer> entry) //indent:14 exp:>=8
265     { //indent:4 exp:4
266 
267     } //indent:4 exp:4
268 
269   } //indent:2 exp:2
270 
271   private static class WeightedSoftValueReference<T1, T2> { //indent:2 exp:2
272 
273   } //indent:2 exp:2
274 
275   private static class WeakValueReference<T1, T2> { //indent:2 exp:2
276 
277   } //indent:2 exp:2
278 
279   private static class WeightedWeakValueReference<T1, T2> { //indent:2 exp:2
280 
281   } //indent:2 exp:2
282 
283   private static class StrongEntry<T1, T2> { //indent:2 exp:2
284 
285   } //indent:2 exp:2
286 } //indent:0 exp:0