1 9 package org.ozoneDB.core; 10 11 import org.ozoneDB.DxLib.*; 12 import java.io.*; 13 14 15 25 public final class Group extends DxObject implements Externalizable { 26 27 protected final static long serialVersionUID = 2; 28 protected final static byte subSerialVersionUID = 1; 29 30 protected String name; 31 32 protected int id; 33 34 protected DxSet users; 35 36 37 public Group() { 38 users = new DxHashSet(); 39 } 40 41 42 public Group( String _name, int _id ) { 43 name = _name; 44 id = _id; 45 users = new DxHashSet(); 46 } 47 48 49 public String name() { 50 return name; 51 } 52 53 54 public Integer id() { 55 return new Integer ( id ); 56 } 57 58 59 public DxCollection userIDs() { 60 return users; 61 } 62 63 64 public boolean addUser( User user ) { 65 return users.add( new Integer ( user.id ) ); 66 } 67 68 69 public boolean containsUser( User user ) { 70 return users.contains( new Integer ( user.id ) ); 71 } 72 73 74 public boolean removeUser( User user ) { 75 return users.remove( new Integer ( user.id ) ); 76 } 77 78 79 public boolean isEmpty() { 80 return users.isEmpty(); 81 } 82 83 84 public int usersCount() { 85 return users.count(); 86 } 87 88 89 public boolean equals( Object obj ) { 90 if (this == obj) { 91 return true; 92 } 93 if (obj instanceof Group && obj != null) { 94 return id == ((Group)obj).id; 95 } 96 return false; 97 } 98 99 100 public Object clone() { 101 Group group = (Group)super.clone(); 102 group.name = name; 103 group.id = -1; 104 return group; 105 } 106 107 108 public String toString() { 109 return new String ( "Group '" + name.toString() + "'" ); 110 } 111 112 113 public void writeExternal( ObjectOutput out ) throws IOException { 114 out.writeByte( subSerialVersionUID ); 115 out.writeObject( name ); 116 out.writeInt( id ); 117 out.writeObject( users ); 118 } 119 120 121 public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { 122 byte streamVersionUID = in.readByte(); 123 name = (String )in.readObject(); 124 id = in.readInt(); 125 users = (DxSet)in.readObject(); 126 } 127 128 } 129 | Popular Tags |