source: trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/SequenceInstanceOf.java @ 541

Last change on this file since 541 was 541, checked in by sherbold, 12 years ago
  • beginning of the complete rewriting of the event core. The string representations for the event type and event target are replaced by interfaces IEventType and IEventTarget which have to be implemented by platform level implementations accordingly. Note, that this is just the first commit of this major refactoring of QUEST and it will break a lot of the source code.
  • Property svn:mime-type set to text/plain
File size: 1.9 KB
Line 
1package de.ugoe.cs.quest;
2
3import java.util.Collection;
4import java.util.List;
5import java.util.NoSuchElementException;
6
7import de.ugoe.cs.quest.eventcore.Event;
8
9/**
10 * <p>
11 * Helper class that can be used to determine if an object is a sequence or a
12 * collection of sequences. {@code instanceof} does not work, because of
13 * the type erasure of generics.
14 * </p>
15 *
16 * @author Steffen Herbold
17 * @version 1.0
18 */
19public class SequenceInstanceOf {
20       
21        /**
22         * <p>
23         * Private constructor to prevent initializing of the class.
24         * </p>
25         */
26        private SequenceInstanceOf() {
27               
28        }
29
30        /**
31         * <p>
32         * Checks if an object is of type {@link Collection}&lt;{@link List}&lt;
33         * {@link Event}&lt;?&gt;&gt;&gt;.
34         * </p>
35         *
36         * @param obj
37         *            object that is checked
38         * @return true, if the obj is of type {@link Collection}&lt;{@link List}
39         *         &lt; {@link Event}&lt;?&gt;&gt;&gt;; false otherwise
40         */
41        public static boolean isCollectionOfSequences(Object obj) {
42                try {
43                        if (obj instanceof Collection<?>) {
44                                Object listObj = ((Collection<?>) obj).iterator().next();
45                                if (listObj instanceof List<?>) {
46                                        if (((List<?>) listObj).iterator().next() instanceof Event) {
47                                                return true;
48                                        }
49                                }
50                        }
51                } catch (NoSuchElementException e) {
52                }
53                return false;
54        }
55
56        /**
57         * <p>
58         * Checks if an object is of type {@link List}&lt;{@link Event}
59         * &lt;?&gt;&gt;.
60         * </p>
61         *
62         * @param obj
63         *            object that is checked
64         * @return true, if obj is of type {@link List}&lt;{@link Event}
65         *         &lt;?&gt;&gt;; false otherwise
66         */
67        public static boolean isEventSequence(Object obj) {
68                try {
69                        if (obj instanceof List<?>) {
70                                if (((List<?>) obj).iterator().next() instanceof Event) {
71                                        return true;
72                                }
73                        }
74                } catch (NoSuchElementException e) {
75                }
76                return false;
77        }
78
79}
Note: See TracBrowser for help on using the repository browser.