001package org.intellimate.izou.sdk.frameworks.presence.events; 002 003import org.intellimate.izou.identification.Identification; 004import org.intellimate.izou.sdk.events.CommonEvents; 005import org.intellimate.izou.sdk.events.Event; 006import org.intellimate.izou.sdk.frameworks.presence.resources.LastEncountered; 007 008import java.util.List; 009import java.util.Optional; 010 011/** 012 * this event indicates presence 013 * @author LeanderK 014 * @version 1.0 015 */ 016public class PresenceEvent extends Event { 017 /** 018 * this event does not mean the user is able to notice anything (can be used for warm-up), it indicates 019 * he might be 020 */ 021 public static final String GENERAL_DESCRIPTOR = "izou.presence.general"; 022 /** 023 * it means that the addon can guarantee that the user entered an area near izou 024 */ 025 public static final String STRICT_DESCRIPTOR = "izou.presence.strict"; 026 /** 027 * it means that someone entered an area near izou, but it is not clear if it is the user, 028 */ 029 public static final String UNKNOWN_DESCRIPTOR = "izou.presence.unkownuser"; 030 /** 031 * it means that the user entered an area near izou 032 */ 033 public static final String KNOWN_DESCRIPTOR = "izou.presence.knownuser"; 034 /** 035 * Means that the Addon encountered the user the first time IN THE SPECIFIED MODE (Strict/General) since he left. 036 */ 037 public static final String FIRST_ENCOUNTER_DESCRIPTOR = "izou.presence.firstencounter"; 038 /** 039 * it means that the addon can guarantee that the user entered an area near izou 040 */ 041 public static final String ID = "izou.presence"; 042 043 044 /** 045 * Creates a new Event Object 046 * 047 * @param source the source of the Event, most likely a this reference. 048 * @param descriptors the descriptors to initialize the Event with 049 * @throws IllegalArgumentException if one of the Arguments is null or empty 050 */ 051 protected PresenceEvent(Identification source, List<String> descriptors) throws IllegalArgumentException { 052 super(CommonEvents.Type.RESPONSE_TYPE, source, descriptors); 053 } 054 055 /** 056 * creates a new PresenceEvent 057 * @param source the caller 058 * @param strict whether the addon can guarantee that the user is around 059 * @param known true if the addon knows if the person encountered is the (main) user 060 * @param firstEncounter if the user was first encountered in the specified mode 061 * @param descriptors the descriptors 062 * @return the optional PresenceEvent 063 */ 064 public static Optional<PresenceEvent> createPresenceEvent(Identification source, boolean strict, boolean known, 065 boolean firstEncounter, List<String> descriptors) { 066 try { 067 if (strict) { 068 descriptors.add(STRICT_DESCRIPTOR); 069 } else { 070 descriptors.add(GENERAL_DESCRIPTOR); 071 } 072 if (known) { 073 descriptors.add(KNOWN_DESCRIPTOR); 074 } else { 075 descriptors.add(UNKNOWN_DESCRIPTOR); 076 } 077 if (firstEncounter) 078 descriptors.add(FIRST_ENCOUNTER_DESCRIPTOR); 079 descriptors.add(ID); 080 PresenceEvent stopRequest = new PresenceEvent(source, descriptors); 081 return Optional.of(stopRequest); 082 } catch (IllegalArgumentException e) { 083 return Optional.empty(); 084 } 085 } 086 087 /** 088 * creates a new PresenceEvent 089 * @param source the caller 090 * @param strict whether the addon can guarantee that the user is around 091 * @param known true if the addon knows if the person encountered is the (main) user 092 * @param firstEncounter if the user was first encountered in the specified mode 093 * @param descriptors the descriptors 094 * @param timePassed the time passed in seconds since the user was last encountered 095 * @return the optional PresenceEvent 096 */ 097 public static Optional<PresenceEvent> createPresenceEvent(Identification source, boolean strict, boolean known, 098 boolean firstEncounter, List<String> descriptors, Long timePassed) { 099 try { 100 if (strict) { 101 descriptors.add(STRICT_DESCRIPTOR); 102 } else { 103 descriptors.add(GENERAL_DESCRIPTOR); 104 } 105 if (known) { 106 descriptors.add(KNOWN_DESCRIPTOR); 107 } else { 108 descriptors.add(UNKNOWN_DESCRIPTOR); 109 } 110 if (firstEncounter) 111 descriptors.add(FIRST_ENCOUNTER_DESCRIPTOR); 112 descriptors.add(ID); 113 PresenceEvent presenceEvent = new PresenceEvent(source, descriptors); 114 presenceEvent.addResource(new LastEncountered(source, timePassed)); 115 return Optional.of(presenceEvent); 116 } catch (IllegalArgumentException e) { 117 return Optional.empty(); 118 } 119 } 120}