[208] | 1 | package de.ugoe.cs.eventbench;
|
---|
| 2 |
|
---|
| 3 | import java.util.Collection;
|
---|
| 4 | import java.util.List;
|
---|
| 5 | import java.util.NoSuchElementException;
|
---|
| 6 |
|
---|
| 7 | import de.ugoe.cs.eventbench.data.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 | */
|
---|
| 19 | public class SequenceInstanceOf {
|
---|
| 20 |
|
---|
| 21 | /**
|
---|
| 22 | * <p>
|
---|
| 23 | * Checks if an object is of type {@link Collection}<{@link List}<
|
---|
| 24 | * {@link Event}<?>>>.
|
---|
| 25 | * </p>
|
---|
| 26 | *
|
---|
| 27 | * @param obj
|
---|
| 28 | * object that is checked
|
---|
| 29 | * @return true, if the obj is of type {@link Collection}<{@link List}
|
---|
| 30 | * < {@link Event}<?>>>; false otherwise
|
---|
| 31 | */
|
---|
| 32 | public static boolean isCollectionOfSequences(Object obj) {
|
---|
| 33 | try {
|
---|
| 34 | if (obj instanceof Collection<?>) {
|
---|
| 35 | Object listObj = ((Collection<?>) obj).iterator().next();
|
---|
| 36 | if (listObj instanceof List<?>) {
|
---|
| 37 | if (((List<?>) listObj).iterator().next() instanceof Event<?>) {
|
---|
| 38 | return true;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | } catch (NoSuchElementException e) {
|
---|
| 43 | }
|
---|
| 44 | return false;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * <p>
|
---|
| 49 | * Checks if an object is of type {@link List}<{@link Event}
|
---|
| 50 | * <?>>.
|
---|
| 51 | * </p>
|
---|
| 52 | *
|
---|
| 53 | * @param obj
|
---|
| 54 | * object that is checked
|
---|
| 55 | * @return true, if obj is of type {@link List}<{@link Event}
|
---|
| 56 | * <?>>; false otherwise
|
---|
| 57 | */
|
---|
| 58 | public static boolean isEventSequence(Object obj) {
|
---|
| 59 | try {
|
---|
| 60 | if (obj instanceof List<?>) {
|
---|
| 61 | if (((List<?>) obj).iterator().next() instanceof Event<?>) {
|
---|
| 62 | return true;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | } catch (NoSuchElementException e) {
|
---|
| 66 | }
|
---|
| 67 | return false;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | }
|
---|