package de.ugoe.cs.quest; import java.util.Collection; import java.util.List; import java.util.NoSuchElementException; import de.ugoe.cs.quest.eventcore.Event; /** *
* Helper class that can be used to determine if an object is a sequence or a * collection of sequences. {@code instanceof} does not work, because of * the type erasure of generics. *
* * @author Steffen Herbold * @version 1.0 */ public class SequenceInstanceOf { /** ** Private constructor to prevent initializing of the class. *
*/ private SequenceInstanceOf() { } /** ** Checks if an object is of type {@link Collection}<{@link List}< * {@link Event}<?>>>. *
* * @param obj * object that is checked * @return true, if the obj is of type {@link Collection}<{@link List} * < {@link Event}<?>>>; false otherwise */ public static boolean isCollectionOfSequences(Object obj) { try { if (obj instanceof Collection>) { Object listObj = ((Collection>) obj).iterator().next(); if (listObj instanceof List>) { if (((List>) listObj).iterator().next() instanceof Event) { return true; } } } } catch (NoSuchElementException e) { } return false; } /** ** Checks if an object is of type {@link List}<{@link Event} * <?>>. *
* * @param obj * object that is checked * @return true, if obj is of type {@link List}<{@link Event} * <?>>; false otherwise */ public static boolean isEventSequence(Object obj) { try { if (obj instanceof List>) { if (((List>) obj).iterator().next() instanceof Event) { return true; } } } catch (NoSuchElementException e) { } return false; } }