source: fedd/abac-src/rbtm/util/ResultEvidenceMap.java @ df783c1

axis_examplecompt_changesinfo-opsversion-2.00version-3.01version-3.02
Last change on this file since df783c1 was 8780cbec, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

ABAC sources from Cobham

  • Property mode set to 100644
File size: 2.1 KB
Line 
1package edu.stanford.peer.rbtm.util;
2
3import java.util.*;
4
5import edu.stanford.peer.rbtm.RBTMConstants;
6//import edu.stanford.peer.rbtm.util.*;
7
8/** Stores results and their evidences. */
9public class ResultEvidenceMap implements RBTMConstants
10{
11        static final public int DEFAULT_CAPACITY = 23;
12
13    //private int       _type = TRACK_NONE;
14    private int         _type = TRACK_ALL;
15    private HashMap _map;
16
17    public ResultEvidenceMap(int trackType, int capacity) {
18        _type = trackType; 
19        _map = new HashMap(capacity);
20    }
21
22    public ResultEvidenceMap() { 
23                this(TRACK_ALL, DEFAULT_CAPACITY);
24    }
25
26    public ResultEvidenceMap(int trackType) { 
27            this(trackType, DEFAULT_CAPACITY);
28        }
29
30    /**
31     * Retrieve a Result-to-Evidence mapping. If constructed with trackType
32     * TRACK_NONE, the evidence will be null.
33     * @return the evidence, if any, bound to the result.
34     */
35    public Object getResultEvidence(Object result) {
36        return _map.get(result);
37    }
38
39        /**
40         * Add a Result-to-Evidence mapping. 
41         * @return true if this is a new Result, false if it is not
42         */
43    public boolean putResultEvidence(Object result, Object evidence) {
44        if (! _map.containsKey(result)) {  // New result
45                        switch (_type) {
46                        case TRACK_NONE:
47                    _map.put(result, null);
48                                break;
49                        case TRACK_ANY:
50                                _map.put(result, evidence);
51                                break;
52                        case TRACK_ALL:
53                                HashSet eviSet = new HashSet(7);
54                                eviSet.add(evidence);
55                                System.out.println("###Adding " + result + ","
56                                                   + evidence);
57                                _map.put(result, eviSet);
58                                break;
59                        }
60            return true;
61        } else {  // Result already exist
62            if (_type == TRACK_ALL) {
63                ((Set)_map.get(result)).add(evidence);
64            }
65            return false;
66        }
67    }
68   
69    public boolean containsResult(Object result) {
70        return _map.containsKey(result);
71    }
72
73        public Set resultSet() {
74                return _map.keySet();
75        }
76
77        public String toString() {
78            return  "["+ _type + "]" + _map.toString();
79            //return _map.toString();
80        }
81}
Note: See TracBrowser for help on using the repository browser.