File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\matrix\AxisList.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.matrix;
25
26 import com.google.common.base.Function;
27 import com.google.common.collect.Iterables;
28 import com.google.common.collect.Lists;
29 import com.google.common.collect.Sets;
30 import com.thoughtworks.xstream.XStream;
31 import hudson.Util;
32 import hudson.util.RobustCollectionConverter;
33
34 import javax.annotation.Nullable;
35 import java.util.*;
36
37 /**
38 * List of {@link Axis}.
39 *
40 * @author Kohsuke Kawaguchi
41 */
42 public class AxisList extends ArrayList<Axis> {
43 public AxisList() {
44 }
45
46 public AxisList(Collection<? extends Axis> c) {
47 super(c);
48 }
49
50 public AxisList(Axis... c) {
51 this(Arrays.asList(c));
52 }
53
54 public Axis find(String name) {
55 for (Axis a : this) {
56 if(a.name.equals(name))
57 return a;
58 }
59 return null;
60 }
61
62 /**
63 * Creates a subset of the list that only contains the type assignable to the specified type.
64 */
65 public AxisList subList(Class<? extends Axis> subType) {
66 return new AxisList(Util.filter(this,subType));
67 }
68
69 @Override
70 public boolean add(Axis axis) {
71 return axis!=null && super.add(axis);
72 }
73
74 /**
75 * List up all the possible combinations of this list.
76 */
77 public Iterable<Combination> list() {
78 List<Set<String>> axesList = Lists.newArrayList();
79 for (Axis axis : this)
80 axesList.add(new LinkedHashSet<String>(axis.getValues()));
81
82 return Iterables.transform(Sets.cartesianProduct(axesList), new Function<List<String>, Combination>() {
83 public Combination apply(@Nullable List<String> strings) {
84 assert strings != null;
85 return new Combination(AxisList.this, (String[]) strings.toArray(new String[0]));
86 }
87 });
88 }
89
90 /**
91 * {@link Converter} implementation for XStream.
92 */
93 public static final class ConverterImpl extends RobustCollectionConverter {
94 public ConverterImpl(XStream xs) {
95 super(xs);
96 }
97
98 @Override
99 public boolean canConvert(Class type) {
100 return type==AxisList.class;
101 }
102
103 @Override
104 protected Object createCollection(Class type) {
105 return new AxisList();
106 }
107 }
108 }
109