1 4 package nl.justobjects.pushlet.core; 5 6 import nl.justobjects.pushlet.util.Rand; 7 8 9 15 public class Subscription { 16 public static final int ID_SIZE = 5; 17 public static final String SUBJECT_SEPARATOR = ","; 18 private String id = Rand.randomName(ID_SIZE); 19 private String subject; 20 private String [] subjects; 21 22 23 private String label; 24 25 public Subscription(String aSubject) { 26 this(aSubject, null); 27 } 28 29 public Subscription(String aSubject, String aLabel) { 30 if (aSubject == null || aSubject.length() == 0) { 31 throw new IllegalArgumentException ("Null or emtpy subject"); 32 } 33 34 subject = aSubject; 35 36 subjects = aSubject.split(SUBJECT_SEPARATOR); 39 40 label = aLabel; 41 } 42 43 public String getId() { 44 return id; 45 } 46 47 public String getLabel() { 48 return label; 49 } 50 51 public String getSubject() { 52 return subject; 53 } 54 55 56 public boolean match(Event event) { 57 String eventSubject = event.getSubject(); 58 59 if (eventSubject == null || eventSubject.length() == 0) { 61 return false; 62 } 63 64 for (int i = 0; i < subjects.length; i++) { 66 if (eventSubject.startsWith(subjects[i])) { 67 return true; 68 } 69 } 70 71 return false; 73 } 74 } 75 76 89 | Popular Tags |