[8780cbec] | 1 | /* |
---|
| 2 | * LinkedRole.java |
---|
| 3 | */ |
---|
| 4 | |
---|
| 5 | package edu.stanford.peer.rbtm.credential; |
---|
| 6 | |
---|
| 7 | import java.util.*; |
---|
| 8 | |
---|
| 9 | /** |
---|
| 10 | * Represent a LinkedRole. |
---|
| 11 | */ |
---|
| 12 | public class LinkedRole implements EntityExpression |
---|
| 13 | { |
---|
| 14 | private Role firstRole; |
---|
| 15 | private RoleName secondName; |
---|
| 16 | |
---|
| 17 | public LinkedRole(Role r, RoleName n) { firstRole = r; secondName = n; } |
---|
| 18 | |
---|
| 19 | public LinkedRole(Role r, String n) { |
---|
| 20 | firstRole = r; |
---|
| 21 | secondName = new SimpleRoleName(n); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | public LinkedRole(Entity issuer, String n1, String n2) { |
---|
| 25 | firstRole = new Role(issuer, n1); |
---|
| 26 | secondName = new SimpleRoleName(n2); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | public LinkedRole(String issuer, String n1, String n2) { |
---|
| 30 | firstRole = new Role(issuer, n1); |
---|
| 31 | secondName = new SimpleRoleName(n2); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | public int hashCode() { |
---|
| 35 | return firstRole.hashCode() * 2 + secondName.hashCode(); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | public boolean equals(Object o) { |
---|
| 39 | return (o instanceof LinkedRole) |
---|
| 40 | && firstRole.equals(((LinkedRole)o).firstRole) |
---|
| 41 | && secondName.equals(((LinkedRole)o).secondName); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | public String toString() { |
---|
| 45 | return firstRole.toString() + "." + secondName.toString(); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | public Role getFirstRole() { |
---|
| 49 | return firstRole; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | public RoleName getSecondRoleName() { |
---|
| 53 | return secondName; |
---|
| 54 | } |
---|
| 55 | //public Entity getIssuer() { return (Entity)_names.get(0); } |
---|
| 56 | |
---|
| 57 | /* |
---|
| 58 | public LinkedRole(String[] strs) { |
---|
| 59 | _names = new ArrayList(); |
---|
| 60 | _names.add(new Entity(strs[0])); |
---|
| 61 | for (int i=1; i<strs.length; i++) { |
---|
| 62 | _names.add(new SimpleRoleName(strs[i])); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | public LinkedRole(ArrayList strs) { |
---|
| 67 | _names = new ArrayList(); |
---|
| 68 | _names.add(new Entity((String)strs.get(0))); |
---|
| 69 | for (int i=1; i<strs.size(); i++) { |
---|
| 70 | _names.add(new SimpleRoleName((String) strs.get(i))); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | public int hashCode() { |
---|
| 74 | long value = 0; |
---|
| 75 | for (int i=0; i<_names.size(); i++) { |
---|
| 76 | value *= 2; |
---|
| 77 | value += _names.get(i).hashCode(); |
---|
| 78 | } |
---|
| 79 | return (int)value; |
---|
| 80 | } |
---|
| 81 | public boolean equals(Object o) |
---|
| 82 | { |
---|
| 83 | return (o instanceof LinkedRole) && |
---|
| 84 | _names.equals(((LinkedRole)o)._names); |
---|
| 85 | } |
---|
| 86 | public String toString() { |
---|
| 87 | StringBuffer buf = new StringBuffer(); |
---|
| 88 | buf.append("(").append(_names.get(0)); |
---|
| 89 | for (int i=1; i<_names.size(); i++) { |
---|
| 90 | buf.append("'s ").append(_names.get(i)); |
---|
| 91 | } |
---|
| 92 | buf.append(")"); |
---|
| 93 | return buf.toString(); |
---|
| 94 | } |
---|
| 95 | public RoleName getIthRoleName(int i) { return (RoleName)_names.get(i); } |
---|
| 96 | |
---|
| 97 | public RoleName getLastRoleName() { |
---|
| 98 | return (RoleName)_names.get(_names.size()-1); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | */ |
---|
| 102 | |
---|
| 103 | } |
---|