All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anotheria.anosite.gen.anoaccessapplicationdata.data.UserDataDocument Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** UserDataDocument.java                                                    ***
 *** generated by AnoSiteGenerator (ASG), Version: 3.2.2                      ***
 *** Copyright (C) 2005 - 2023 Anotheria.net, www.anotheria.net               ***
 *** All Rights Reserved.                                                     ***
 ********************************************************************************
 *** Don't edit this code, if you aren't sure                                 ***
 *** that you do exactly know what you are doing!                             ***
 *** It's better to invest time in the generator, as into the generated code. ***
 ********************************************************************************
 */

package net.anotheria.anosite.gen.anoaccessapplicationdata.data;

import net.anotheria.asg.data.AbstractASGDocument;
import java.util.List;
import net.anotheria.anodoc.data.StringProperty;
import net.anotheria.util.crypt.MD5Util;
import net.anotheria.util.sorter.IComparable;
import net.anotheria.util.BasicComparable;

public class UserDataDocument extends AbstractASGDocument implements UserData, IComparable{

	public UserDataDocument() {
		super("");
	}

	public UserDataDocument(String id){
		super(id);
	}

	public UserDataDocument(UserDataDocument toClone){
		super(toClone);
	}

	UserDataDocument(UserDataBuilder builder){
		super("");
		setUserId(builder.userId);
		setRoles(builder.roles);
	}

	public String getUserId(){
		return getString(PROP_USER_ID);
	}

	public void setUserId(String value){
		setString(PROP_USER_ID, value);
	}

	public List getRoles(){
		return copyToStringList(getList(PROP_ROLES));
	}

	public void setRoles(List value){
		setList(PROP_ROLES, copyFromStringList(value));
	}


	public String toString(){
		String ret = "UserData ";
		ret += "["+getId()+"] ";
		ret += "userId: "+getUserId();
		ret += ", ";
		ret += "roles: "+getRoles();
		return ret;
	}

	public int getRolesSize(){
		return getList(PROP_ROLES).size();
	}

	public void addRolesElement(String role){
		getListPropertyAnyCase(PROP_ROLES).add(new StringProperty("" + role, role));
	} //method

	public void removeRolesElement(int index){
		getListProperty(PROP_ROLES).remove(index);
	} //method

	public void swapRolesElement(int index1, int index2){
		String tmp1, tmp2;
		tmp1 = ((StringProperty)getList(PROP_ROLES).get(index1)).getString();
		tmp2 = ((StringProperty)getList(PROP_ROLES).get(index2)).getString();
		((StringProperty)getList(PROP_ROLES).get(index1)).setString(tmp2);
		((StringProperty)getList(PROP_ROLES).get(index2)).setString(tmp1);
	} //method

	public String getRolesElement(int index){
		StringProperty p = (StringProperty)getList(PROP_ROLES).get(index);
		return p.getString();
	} //method


	public int compareTo(UserData comparable){
		return compareTo(comparable, UserDataSortType.SORT_BY_DEFAULT);
	}

	public int compareTo(IComparable anotherComparable, int method){
		UserDataDocument anotherDoc = (UserDataDocument) anotherComparable;
		switch(method){
			case UserDataSortType.SORT_BY_ID:
				return BasicComparable.compareString(getId(), anotherDoc.getId());
			case UserDataSortType.SORT_BY_USERID:
				return BasicComparable.compareString(getUserId(), anotherDoc.getUserId());
			default:
				throw new RuntimeException("Sort method "+method+" is not supported.");
		}
	}

	public String getDefinedName(){
		return "UserData";
	}

	public String getDefinedParentName(){
		return "AnoAccessApplicationData";
	}

	public String getFootprint(){
		StringBuilder footprint = new StringBuilder();
		footprint.append(getUserId());
		footprint.append(getRoles());
		return MD5Util.getMD5Hash(footprint);
	}

	public boolean equals(Object o){
		return o == this || ((o instanceof UserDataDocument) && ((UserDataDocument)o).getId().equals(getId()));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy