Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
30   164   17   2.31
6   69   0.57   13
13     1.31  
1    
 
  VersionSet       Line # 28 30 17 100% 1.0
 
  (1)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.base.io;
17   
18    import java.util.Iterator;
19    import java.util.Set;
20    import java.util.TreeSet;
21   
22   
23    /**
24    * A set of version numbers.
25    *
26    * @author Michael Meyling
27    */
 
28    public final class VersionSet {
29   
30    /** Set that contains our versions. */
31    private final Set set;
32   
33    /**
34    * Constructs version set object. You must give a version string in a form like
35    * <em>a</em>.<em>b</em>.<em>c</em> where a, b and c are non negative integers.
36    * These numbers are called <em>Major</em> <em>Minor</em> and <em>Patch</em>.
37    *
38    * @param version Version string.
39    * @throws IllegalArgumentException Version string has wrong format.
40    * @throws NullPointerException No null pointer as argument accepted.
41    */
 
42  14 toggle public VersionSet(final String version) {
43  14 set = new TreeSet();
44  14 add(version);
45    }
46   
47    /**
48    * Constructs version set object.
49    */
 
50  100 toggle public VersionSet() {
51  100 set = new TreeSet();
52    }
53   
54    /**
55    * Does the set contain given version number.
56    *
57    * @param version Version string. If it has not the correct form, false is returned.
58    * @return Is given version in set?
59    */
 
60  458 toggle public boolean contains(final String version) {
61  458 Version v = null;
62  458 try {
63  458 v = new Version(version);
64    } catch (RuntimeException e) {
65  1 return false;
66    }
67  457 return set.contains(v);
68    }
69   
70    /**
71    * Does the set contain given version number.
72    *
73    * @param version Version to check for.
74    * @return Is given version in set?
75    */
 
76  13 toggle public boolean contains(final Version version) {
77  13 return set.contains(version);
78    }
79   
80    /**
81    * Add version number.
82    *
83    * @param version Version string.
84    * @throws IllegalArgumentException Version string has wrong format.
85    * @throws NullPointerException No null pointer as argument accepted.
86    */
 
87  204 toggle public void add(final String version) {
88  204 add(new Version(version));
89    }
90   
91    /**
92    * Add version number.
93    *
94    * @param version Version string.
95    */
 
96  204 toggle public void add(final Version version) {
97  204 set.add(version);
98    }
99   
100    /**
101    * Add contents of another version set.
102    *
103    * @param versions Other version set.
104    * @return Did current set change?
105    */
 
106  1 toggle public boolean addAll(final VersionSet versions) {
107  1 return set.addAll(versions.set);
108    }
109   
110    /**
111    * Is this set empty?
112    *
113    * @return Is set empty?
114    */
 
115  4 toggle public boolean isEmpty() {
116  4 return set.isEmpty();
117    }
118   
119    /**
120    * Removes all of the elements from this set.
121    */
 
122  1 toggle public void clear() {
123  1 set.clear();
124    }
125   
126    /**
127    * Returns an iterator over the elements in this set. The elements are
128    * returned in ascending order.
129    *
130    * @return Iterator.
131    */
 
132  1 toggle public Iterator iterator() {
133  1 return set.iterator();
134    }
135   
 
136  4 toggle public int hashCode() {
137  4 return set.hashCode();
138    }
139   
 
140  18 toggle public boolean equals(final Object o) {
141  18 if (!(o instanceof VersionSet)) {
142  3 return false;
143    }
144  15 return set.equals(((VersionSet) o).set);
145    }
146   
 
147  5 toggle public String toString() {
148  5 final StringBuffer buffer = new StringBuffer(30);
149  5 buffer.append("{");
150  5 Iterator e = set.iterator();
151  5 boolean notFirst = false;
152  10 while (e.hasNext()) {
153  5 if (notFirst) {
154  1 buffer.append(", ");
155    } else {
156  4 notFirst = true;
157    }
158  5 buffer.append(String.valueOf(e.next()));
159    }
160  5 buffer.append("}");
161  5 return buffer.toString();
162    }
163   
164    }