001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Core License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: Group.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
008:
009: package org.ozoneDB.core;
010:
011: import org.ozoneDB.DxLib.*;
012: import java.io.*;
013:
014: /**
015: * This class represent an ozone user group. A group can be identified by
016: * its name.
017: *
018: *
019: * @author <a href="http://www.softwarebuero.de/">SMB</a>
020: * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $
021: * @see User
022: * @see UserManager
023: */
024: public final class Group extends DxObject implements Externalizable {
025:
026: protected final static long serialVersionUID = 2;
027: protected final static byte subSerialVersionUID = 1;
028:
029: protected String name;
030:
031: protected int id;
032:
033: protected DxSet users;
034:
035: public Group() {
036: users = new DxHashSet();
037: }
038:
039: public Group(String _name, int _id) {
040: name = _name;
041: id = _id;
042: users = new DxHashSet();
043: }
044:
045: public String name() {
046: return name;
047: }
048:
049: public Integer id() {
050: return new Integer(id);
051: }
052:
053: public DxCollection userIDs() {
054: return users;
055: }
056:
057: public boolean addUser(User user) {
058: return users.add(new Integer(user.id));
059: }
060:
061: public boolean containsUser(User user) {
062: return users.contains(new Integer(user.id));
063: }
064:
065: public boolean removeUser(User user) {
066: return users.remove(new Integer(user.id));
067: }
068:
069: public boolean isEmpty() {
070: return users.isEmpty();
071: }
072:
073: public int usersCount() {
074: return users.count();
075: }
076:
077: public boolean equals(Object obj) {
078: if (this == obj) {
079: return true;
080: }
081: if (obj instanceof Group && obj != null) {
082: return id == ((Group) obj).id;
083: }
084: return false;
085: }
086:
087: public Object clone() {
088: Group group = (Group) super .clone();
089: group.name = name;
090: group.id = -1;
091: return group;
092: }
093:
094: public String toString() {
095: return new String("Group '" + name.toString() + "'");
096: }
097:
098: public void writeExternal(ObjectOutput out) throws IOException {
099: out.writeByte(subSerialVersionUID);
100: out.writeObject(name);
101: out.writeInt(id);
102: out.writeObject(users);
103: }
104:
105: public synchronized void readExternal(ObjectInput in)
106: throws IOException, ClassNotFoundException {
107: byte streamVersionUID = in.readByte();
108: name = (String) in.readObject();
109: id = in.readInt();
110: users = (DxSet) in.readObject();
111: }
112:
113: }
|