1 /*
 2  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 package nsk.share.gc.gp;
25 
26 import java.util.List;
27 import java.util.ArrayList;
28 import nsk.share.gc.gp.array.*;
29 import nsk.share.gc.gp.string.*;
30 
31 /**
32  * Factory for garbage producers
33  */
34 public class GarbageProducers {
35         private List<GarbageProducer> primitiveArrayProducers;
36         private List<GarbageProducer> arrayProducers;
37         private List<GarbageProducer<String>> stringProducers;
38         private List<GarbageProducer> allProducers;
39 
40         /**
41          * Get all primitive array producers.
42          */
43         public List<GarbageProducer> getPrimitiveArrayProducers() {
44                 if (primitiveArrayProducers == null) {
45                         primitiveArrayProducers = new ArrayList<GarbageProducer>();
46                         primitiveArrayProducers.add(new ByteArrayProducer());
47                         primitiveArrayProducers.add(new BooleanArrayProducer());
48                         primitiveArrayProducers.add(new ShortArrayProducer());
49                         primitiveArrayProducers.add(new CharArrayProducer());
50                         primitiveArrayProducers.add(new IntArrayProducer());
51                         primitiveArrayProducers.add(new LongArrayProducer());
52                         primitiveArrayProducers.add(new FloatArrayProducer());
53                         primitiveArrayProducers.add(new DoubleArrayProducer());
54                 }
55                 return primitiveArrayProducers;
56         }
57 
58         /**
59          * Get all array producers.
60          */
61         public List<GarbageProducer> getArrayProducers() {
62                 if (arrayProducers == null) {
63                         arrayProducers = new ArrayList<GarbageProducer>();
64                         arrayProducers.addAll(getPrimitiveArrayProducers());
65                         arrayProducers.add(new ObjectArrayProducer());
66                 }
67                 return arrayProducers;
68         }
69 
70         /**
71          * Get all string producers.
72          */
73         public List<GarbageProducer<String>> getStringProducers() {
74                 if (stringProducers == null) {
75                         stringProducers = new ArrayList<GarbageProducer<String>>();
76                         stringProducers.add(new RandomStringProducer());
77                         stringProducers.add(new InternedStringProducer());
78                 }
79                 return stringProducers;
80         }
81 
82         public List<GarbageProducer> getAllProducers() {
83                 if (allProducers == null) {
84                         allProducers = new ArrayList<GarbageProducer>();
85                         allProducers.addAll(getArrayProducers());
86                         allProducers.addAll(getStringProducers());
87                 }
88                 return allProducers;
89         }
90 }