|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
SetUtil.java | 0% | 0% | 0% | 0% |
|
1 | /* | |
2 | wsmo4j - a WSMO API and Reference Implementation | |
3 | Copyright (c) 2005, University of Innsbruck, Austria | |
4 | This library is free software; you can redistribute it and/or modify it under | |
5 | the terms of the GNU Lesser General Public License as published by the Free | |
6 | Software Foundation; either version 2.1 of the License, or (at your option) | |
7 | any later version. | |
8 | This library is distributed in the hope that it will be useful, but WITHOUT | |
9 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
10 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
11 | details. | |
12 | You should have received a copy of the GNU Lesser General Public License along | |
13 | with this library; if not, write to the Free Software Foundation, Inc., | |
14 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
15 | */ | |
16 | package org.deri.wsmo4j.logicalexpression.util; | |
17 | ||
18 | ||
19 | import java.util.*; | |
20 | ||
21 | ||
22 | /** | |
23 | * Utility to check typing of sets | |
24 | * | |
25 | * <pre> | |
26 | * Created on Jul 24, 2005 | |
27 | * Committed by $Author: marin_dimitrov $ | |
28 | * $Source$, | |
29 | * </pre> | |
30 | * | |
31 | * @author Holger Lausen | |
32 | * | |
33 | * @version $Revision: 896 $ $Date: 2005-09-09 18:51:42 +0300 (Fri, 09 Sep 2005) $ | |
34 | */ | |
35 | public class SetUtil { | |
36 | ||
37 | /** | |
38 | * Checks if all object in a collection are of specfic type. | |
39 | * @param collection collection to be checked | |
40 | * @param type the Type that the objects have to be an instance of | |
41 | * @return true if all objects in Collection are of specified type | |
42 | */ | |
43 | 0 | public static boolean allOfType(Collection collection, Class type) { |
44 | 0 | if (collection == null) { |
45 | 0 | return true; |
46 | } | |
47 | 0 | Iterator i1 = collection.iterator(); |
48 | 0 | boolean ok = true; |
49 | 0 | while (i1.hasNext()) { |
50 | 0 | Object o = i1.next(); |
51 | 0 | if (!type.isInstance(o)) { |
52 | 0 | ok = false; |
53 | } | |
54 | } | |
55 | 0 | return ok; |
56 | } | |
57 | ||
58 | /** | |
59 | * Create an HashSet, add an Object to it and return the Set | |
60 | * @param o Object to be added to the HashSet | |
61 | * @return HashSet containing the Object o | |
62 | */ | |
63 | 0 | public static Set createSet(Object o) { |
64 | 0 | HashSet s = new HashSet(); |
65 | 0 | s.add(o); |
66 | 0 | return s; |
67 | } | |
68 | ||
69 | /** | |
70 | * Create an HashSet, add two Objects to it and return the Set | |
71 | * @param o1 Object 1 to be added to the HashSet | |
72 | * @param o2 Object 2 to be added to the HashSet | |
73 | * @return HashSet containing the Objects o1 and o2 | |
74 | */ | |
75 | 0 | public static Set createSet(Object o1, Object o2) { |
76 | 0 | HashSet s = new HashSet(); |
77 | 0 | s.add(o1); |
78 | 0 | s.add(o2); |
79 | 0 | return s; |
80 | } | |
81 | ||
82 | /** | |
83 | * Create an HashSet, add three Objects to it and return the Set | |
84 | * @param o1 Object 1 to be added to the HashSet | |
85 | * @param o2 Object 2 to be added to the HashSet | |
86 | * @param o3 Object 3 to be added to the HashSet | |
87 | * @return HashSet containing the Objects o1, o2 and o3 | |
88 | */ | |
89 | 0 | public static Set createSet(Object o1, Object o2, Object o3) { |
90 | 0 | HashSet s = new HashSet(); |
91 | 0 | s.add(o1); |
92 | 0 | s.add(o2); |
93 | 0 | s.add(o3); |
94 | 0 | return s; |
95 | } | |
96 | ||
97 | /** | |
98 | * Create an HashSet, add four Objects to it and return the Set | |
99 | * @param o1 Object 1 to be added to the HashSet | |
100 | * @param o2 Object 2 to be added to the HashSet | |
101 | * @param o3 Object 3 to be added to the HashSet | |
102 | * @param o4 Object 4 to be added to the HashSet | |
103 | * @return HashSet containing the Objects o1, o2, o3 and o4 | |
104 | */ | |
105 | 0 | public static Set createSet(Object o1, Object o2, Object o3, Object o4) { |
106 | 0 | HashSet s = new HashSet(); |
107 | 0 | s.add(o1); |
108 | 0 | s.add(o2); |
109 | 0 | s.add(o3); |
110 | 0 | s.add(o4); |
111 | 0 | return s; |
112 | } | |
113 | } |
|