[8609] | 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 | */
|
---|
| 9 | package org.greenstone.gsdlas.profiles;
|
---|
| 10 |
|
---|
| 11 | import java.util.*;
|
---|
| 12 | import java.util.Map;
|
---|
| 13 | import 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 | */
|
---|
| 21 | public 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 |
|
---|
[8719] | 59 | public Set getPredicates() {
|
---|
| 60 | Set result = new HashSet();
|
---|
| 61 | for (Iterator iter = map.values().iterator(); iter.hasNext();) {
|
---|
| 62 | Predicate pred = (Predicate) iter.next();
|
---|
| 63 | if (pred != null) {
|
---|
| 64 | result.add(pred);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | return result;
|
---|
[8609] | 68 | }
|
---|
| 69 |
|
---|
| 70 | /**
|
---|
| 71 | * @return
|
---|
| 72 | */
|
---|
| 73 | public int getId() {
|
---|
| 74 | return id;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | public int getNumOfNonEqualsPredicates() {
|
---|
| 78 | return numOfNonEqualsPredicates;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public String toString() {
|
---|
| 82 | return "Subscription id " + id + ": " + map;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | public boolean equals(Object other) {
|
---|
| 86 | if (other == null || !(other instanceof Subscription)) return false;
|
---|
| 87 | return id == ((Subscription)other).id;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | /* (non-Javadoc)
|
---|
| 91 | * @see java.lang.Comparable#compareTo(java.lang.Object)
|
---|
| 92 | */
|
---|
| 93 | public int compareTo(Object arg0) {
|
---|
| 94 | Subscription other = (Subscription) arg0;
|
---|
| 95 | return new Integer(id).compareTo(new Integer(other.id));
|
---|
| 96 | }
|
---|
| 97 | } |
---|