source: trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java@ 8630

Last change on this file since 8630 was 8630, checked in by schweer, 19 years ago

restructured servlet to use velocity

  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1/*
2 * Created on Oct 27, 2004
3 * Copyright (C) Andrea Schweer, 2004
4 *
5 * This file is part of the Greenstone Alerting Service.
6 * Refer to the COPYING file in the base directory of this package
7 * for licensing information.
8 */
9package org.greenstone.gsdlas.profiles;
10
11import java.util.*;
12import java.util.Map;
13import java.util.TreeMap;
14
15/**
16 * @author schweer
17 *
18 * TODO To change the template for this generated type comment go to Window -
19 * Preferences - Java - Code Style - Code Templates
20 */
21public class Subscription implements Comparable {
22 private Map map;
23 private int id;
24 private int numOfNonEqualsPredicates;
25
26 private static int highestId = 0;
27
28 public Subscription(Map valueMap) throws ParseException {
29 map = new TreeMap();
30 for (Iterator iter = valueMap.keySet().iterator(); iter.hasNext();) {
31 String key = (String) iter.next();
32 String value = (String) valueMap.get(key);
33 Predicate predicate = PredicateFactory.createPredicate(key, value);
34 map.put(key, predicate);
35
36 if (predicate != null && !(predicate instanceof IdEqualsPredicate)) {
37 numOfNonEqualsPredicates++;
38 }
39 }
40 id = highestId++;
41 }
42
43 public boolean containsKey(Object key) {
44 return map.containsKey(key);
45 }
46
47 public boolean containsValue(Object value) {
48 return map.containsValue(value);
49 }
50
51 public Predicate getPredicate(String field) {
52 return (Predicate) map.get(field);
53 }
54
55 public Set keySet() {
56 return map.keySet();
57 }
58
59 public Collection getPredicates() {
60 return Collections.unmodifiableCollection(map.values());
61 }
62
63 /**
64 * @return
65 */
66 public int getId() {
67 return id;
68 }
69
70 public int getNumOfNonEqualsPredicates() {
71 return numOfNonEqualsPredicates;
72 }
73
74 public String toString() {
75 return "Subscription id " + id + ": " + map;
76 }
77
78 public boolean equals(Object other) {
79 if (other == null || !(other instanceof Subscription)) return false;
80 return id == ((Subscription)other).id;
81 }
82
83 /* (non-Javadoc)
84 * @see java.lang.Comparable#compareTo(java.lang.Object)
85 */
86 public int compareTo(Object arg0) {
87 Subscription other = (Subscription) arg0;
88 return new Integer(id).compareTo(new Integer(other.id));
89 }
90}
Note: See TracBrowser for help on using the repository browser.