universe@21: /* universe@21: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. universe@33: * universe@24: * Copyright 2018 Mike Becker. All rights reserved. universe@33: * universe@21: * Redistribution and use in source and binary forms, with or without universe@21: * modification, are permitted provided that the following conditions are met: universe@21: * universe@21: * 1. Redistributions of source code must retain the above copyright universe@21: * notice, this list of conditions and the following disclaimer. universe@21: * universe@21: * 2. Redistributions in binary form must reproduce the above copyright universe@21: * notice, this list of conditions and the following disclaimer in the universe@21: * documentation and/or other materials provided with the distribution. universe@21: * universe@21: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@21: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@21: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE universe@21: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE universe@21: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR universe@21: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF universe@21: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS universe@21: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN universe@21: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) universe@21: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE universe@21: * POSSIBILITY OF SUCH DAMAGE. universe@33: * universe@21: */ universe@21: package de.uapcore.lightpit.entities; universe@21: universe@37: import java.util.Objects; universe@37: universe@33: public final class User { universe@21: universe@26: public static final int ANONYMOUS_USERID = -1; universe@33: universe@51: private final int id; universe@26: private String username; universe@37: private String mail; universe@33: private String givenname; universe@33: private String lastname; universe@21: universe@51: public User(int id) { universe@51: this.id = id; universe@37: } universe@37: universe@51: public int getId() { universe@51: return id; universe@21: } universe@21: universe@26: public String getUsername() { universe@26: return username; universe@21: } universe@21: universe@26: public void setUsername(String username) { universe@26: this.username = username; universe@21: } universe@21: universe@37: public String getMail() { universe@37: return mail; universe@37: } universe@37: universe@37: public void setMail(String mail) { universe@37: this.mail = mail; universe@37: } universe@37: universe@33: public String getGivenname() { universe@26: return givenname; universe@21: } universe@21: universe@33: public void setGivenname(String givenname) { universe@26: this.givenname = givenname; universe@21: } universe@21: universe@33: public String getLastname() { universe@26: return lastname; universe@21: } universe@21: universe@33: public void setLastname(String lastname) { universe@26: this.lastname = lastname; universe@21: } universe@21: universe@47: public String getDisplayname() { universe@47: StringBuilder dn = new StringBuilder(); universe@51: if (givenname != null) universe@51: dn.append(givenname); universe@47: dn.append(' '); universe@51: if (lastname != null) universe@51: dn.append(lastname); universe@47: dn.append(' '); universe@47: if (mail != null && !mail.isBlank()) { universe@47: dn.append("<"+mail+">"); universe@47: } universe@47: final var str = dn.toString().trim(); universe@47: return str.isBlank() ? username : str; universe@47: } universe@47: universe@21: @Override universe@37: public boolean equals(Object o) { universe@37: if (this == o) return true; universe@37: if (o == null || getClass() != o.getClass()) return false; universe@37: User user = (User) o; universe@51: return id == user.id; universe@21: } universe@21: universe@21: @Override universe@37: public int hashCode() { universe@51: return Objects.hash(id); universe@33: } universe@21: }