source: fedd/abac-src/rbtm/credential/Intersection.java @ 4ea1e22

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

ABAC sources from Cobham

  • Property mode set to 100644
File size: 2.2 KB
Line 
1package edu.stanford.peer.rbtm.credential;
2
3import java.util.*;
4
5public class Intersection implements EntityExpression
6{
7    /**
8     * The parts of the intersection
9     */
10    protected LinkedList parts;
11
12    /**
13     * Default constructor. Expressions to be intersected may be added using
14     * the and() method.
15     */
16    public Intersection() {  parts = new LinkedList(); }
17
18    /**
19     * Default copy constructor. All part references are duplicated, so the
20     * new copy is not relying on the old ones parts list.
21     */
22    public Intersection(Intersection i) {
23        this();
24        Iterator it = i.getParts();
25        while(it.hasNext())
26            parts.add(it.next());
27    }
28   
29    /**
30     * Adds a new expression to this intersection. And() calls may be
31     * concatenated similar to appending with a StringBuffer instance.
32     * @param expr An expression to be added (a role or linked role)
33     * @return The updated intersection expression
34     */
35    public Intersection and(EntityExpression expr) {
36        parts.add(expr);
37        return this;
38    }
39
40    /**
41     * Public accessor method for accessing each expression in the
42     * intersection.
43     */
44    public Iterator getParts() { return parts.iterator(); }
45
46    /**
47     * Public access method for determining the number of subexpressions
48     * contained in this intersection.
49     */
50    public int getPartsCount() { return parts.size(); }
51
52    /**
53     * Compare the parts of two intersections.
54     * @return a boolean result for equivalence
55     */
56    public boolean equals(Object o) {
57        return (o instanceof Intersection)
58            &&  parts.equals(((Intersection)o).parts);
59    }
60
61    /**
62     *
63     * @return a unique hashcode base on the parts of the intersection.
64     */
65    public int hashCode() { return parts.hashCode(); }
66
67    /**
68     * Converts the intersection into a human readable form. Expressions
69     * are separated using a '^' symbol to represent an intersection.
70     *
71     * @return formatted string representation of an intersection
72     */
73    public String toString() {
74        Iterator i = getParts();
75        StringBuffer buff = new StringBuffer();
76
77        while(i.hasNext()) {
78            buff.append(i.next().toString());
79            if(i.hasNext())buff.append(" ^ ");
80        }
81        return buff.toString();
82    }
83     
84           
85
86}
87
88
89
90
Note: See TracBrowser for help on using the repository browser.