KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > Group


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: Group.java,v 1.2 2002/08/27 08:32:25 per_nyfelt Exp $
8

9 package org.ozoneDB.core;
10
11 import org.ozoneDB.DxLib.*;
12 import java.io.*;
13
14
15 /**
16  * This class represent an ozone user group. A group can be identified by
17  * its name.
18  *
19  *
20  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
21  * @version $Revision: 1.2 $Date: 2002/08/27 08:32:25 $
22  * @see User
23  * @see UserManager
24  */

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 JavaDoc 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 JavaDoc _name, int _id ) {
43         name = _name;
44         id = _id;
45         users = new DxHashSet();
46     }
47
48
49     public String JavaDoc name() {
50         return name;
51     }
52
53
54     public Integer JavaDoc id() {
55         return new Integer JavaDoc( 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 JavaDoc( user.id ) );
66     }
67
68
69     public boolean containsUser( User user ) {
70         return users.contains( new Integer JavaDoc( user.id ) );
71     }
72
73
74     public boolean removeUser( User user ) {
75         return users.remove( new Integer JavaDoc( 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 JavaDoc 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 JavaDoc clone() {
101         Group group = (Group)super.clone();
102         group.name = name;
103         group.id = -1;
104         return group;
105     }
106
107
108     public String JavaDoc toString() {
109         return new String JavaDoc( "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 JavaDoc {
122         byte streamVersionUID = in.readByte();
123         name = (String JavaDoc)in.readObject();
124         id = in.readInt();
125         users = (DxSet)in.readObject();
126     }
127
128 }
129
Popular Tags