⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userimpl.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
字号:
/*--------------------------------------------------------------------------*
 | Copyright (C) 2006 Christopher Kohlhaas                                  |
 |                                                                          |
 | This program is free software; you can redistribute it and/or modify     |
 | it under the terms of the GNU General Public License as published by the |
 | Free Software Foundation. A copy of the license has been included with   |
 | these distribution in the COPYING file, if not go to www.fsf.org         |
 |                                                                          |
 | As a special exception, you are granted the permissions to link this     |
 | program with every library, which license fulfills the Open Source       |
 | Definition as published by the Open Source Initiative (OSI).             |
 *--------------------------------------------------------------------------*/
package org.rapla.entities.internal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;

import org.rapla.entities.Category;
import org.rapla.entities.RaplaType;
import org.rapla.entities.User;
import org.rapla.entities.storage.Mementable;
import org.rapla.entities.storage.RefEntity;
import org.rapla.entities.storage.internal.SimpleEntity;

public class UserImpl extends SimpleEntity implements User,Mementable,java.io.Serializable
{
    // Don't forget to increase the serialVersionUID when you change the fields
    private static final long serialVersionUID = 1;

    private String username = "";
    private String email = "";
    private String name = "";
    private boolean bAdmin = false;

    transient private boolean groupArrayUpToDate = false;
    // The resolved references
    transient private Category[] groups;

    final public RaplaType getRaplaType() {return TYPE;}

    public boolean isAdmin() {return bAdmin;}
    public String getName() {return name;}
    public String getEmail() {return email;}
    public String getUsername()  { return username; }
    public String toString()  { return getUsername(); }

    public void setName(String name)  {
        checkWritable();
        this.name =  name;
    }

    public void setEmail(String email)  {
        checkWritable();
        this.email =  email;
    }

    public void setUsername(String username)  {
        checkWritable();
        this.username =  username;
    }

    public void setAdmin(boolean bAdmin)  {
        checkWritable();
        this.bAdmin=bAdmin;
    }

    public String getName(Locale locale) {
        return getUsername();
    }

    public void addGroup(Category group) {
        checkWritable();
        if (getReferenceHandler().isRefering((RefEntity)group))
            return;
        groupArrayUpToDate = false;
        getReferenceHandler().add(group);
    }

    public boolean removeGroup(Category group)   {
        checkWritable();
        if (!getReferenceHandler().isRefering((RefEntity)group))
            return false;
        groupArrayUpToDate = false;
        return getReferenceHandler().remove(group);
    }

    public Category[] getGroups()  {
        updateGroupArray();
        return groups;
    }

    public boolean belongsTo( Category group ) {
        return getReferenceHandler().isRefering( (RefEntity)group );
    }

    private void updateGroupArray() {
        if (groupArrayUpToDate)
            return;
        Collection groupList = new ArrayList();
        Iterator it = super.getReferences();
        while (it.hasNext()) {
            RefEntity o = (RefEntity) it.next();
            if (o.getRaplaType().equals(Category.TYPE)) {
                groupList.add(o);
            }
        }
        groups = (Category[]) groupList.toArray(Category.CATEGORY_ARRAY);
        groupArrayUpToDate = true;
    }

    static private void copy(UserImpl source,UserImpl dest) {
        dest.groupArrayUpToDate = false;

        dest.username = source.username;
        dest.name = source.name;
        dest.email = source.email;
        dest.bAdmin = source.bAdmin;
    }

    public void copy(Object obj) {
        super.copy((UserImpl)obj);
        copy((UserImpl) obj,this);
    }

    public Object deepClone() {
        UserImpl clone = new UserImpl();
        super.deepClone(clone);
        copy(this,clone);
        return clone;
    }

    public Object clone() {
        UserImpl clone = new UserImpl();
        super.clone(clone);
        copy(this,clone);
        return clone;
    }


}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -