src/main/java/de/uapcore/lightpit/entities/User.java

Thu, 14 May 2020 22:48:01 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 14 May 2020 22:48:01 +0200
changeset 47
57cfb94ab99f
parent 37
fecda0f466e6
child 51
dd0a45ae25d7
permissions
-rw-r--r--

projects can now be added and updated

universe@21 1 /*
universe@21 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@33 3 *
universe@24 4 * Copyright 2018 Mike Becker. All rights reserved.
universe@33 5 *
universe@21 6 * Redistribution and use in source and binary forms, with or without
universe@21 7 * modification, are permitted provided that the following conditions are met:
universe@21 8 *
universe@21 9 * 1. Redistributions of source code must retain the above copyright
universe@21 10 * notice, this list of conditions and the following disclaimer.
universe@21 11 *
universe@21 12 * 2. Redistributions in binary form must reproduce the above copyright
universe@21 13 * notice, this list of conditions and the following disclaimer in the
universe@21 14 * documentation and/or other materials provided with the distribution.
universe@21 15 *
universe@21 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@21 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@21 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@21 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@21 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@21 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@21 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@21 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@21 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@21 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@21 26 * POSSIBILITY OF SUCH DAMAGE.
universe@33 27 *
universe@21 28 */
universe@21 29 package de.uapcore.lightpit.entities;
universe@21 30
universe@37 31 import java.util.Objects;
universe@37 32
universe@33 33 public final class User {
universe@21 34
universe@26 35 public static final int ANONYMOUS_USERID = -1;
universe@33 36
universe@37 37 private final int userID;
universe@26 38 private String username;
universe@37 39 private String mail;
universe@33 40 private String givenname;
universe@33 41 private String lastname;
universe@21 42
universe@37 43 public User(int userID) {
universe@37 44 this.userID = userID;
universe@37 45 }
universe@37 46
universe@26 47 public int getUserID() {
universe@26 48 return userID;
universe@21 49 }
universe@21 50
universe@26 51 public String getUsername() {
universe@26 52 return username;
universe@21 53 }
universe@21 54
universe@26 55 public void setUsername(String username) {
universe@26 56 this.username = username;
universe@21 57 }
universe@21 58
universe@37 59 public String getMail() {
universe@37 60 return mail;
universe@37 61 }
universe@37 62
universe@37 63 public void setMail(String mail) {
universe@37 64 this.mail = mail;
universe@37 65 }
universe@37 66
universe@33 67 public String getGivenname() {
universe@26 68 return givenname;
universe@21 69 }
universe@21 70
universe@33 71 public void setGivenname(String givenname) {
universe@26 72 this.givenname = givenname;
universe@21 73 }
universe@21 74
universe@33 75 public String getLastname() {
universe@26 76 return lastname;
universe@21 77 }
universe@21 78
universe@33 79 public void setLastname(String lastname) {
universe@26 80 this.lastname = lastname;
universe@21 81 }
universe@21 82
universe@47 83 public String getDisplayname() {
universe@47 84 StringBuilder dn = new StringBuilder();
universe@47 85 dn.append(givenname);
universe@47 86 dn.append(' ');
universe@47 87 dn.append(lastname);
universe@47 88 dn.append(' ');
universe@47 89 if (mail != null && !mail.isBlank()) {
universe@47 90 dn.append("<"+mail+">");
universe@47 91 }
universe@47 92 final var str = dn.toString().trim();
universe@47 93 return str.isBlank() ? username : str;
universe@47 94 }
universe@47 95
universe@21 96 @Override
universe@37 97 public boolean equals(Object o) {
universe@37 98 if (this == o) return true;
universe@37 99 if (o == null || getClass() != o.getClass()) return false;
universe@37 100 User user = (User) o;
universe@37 101 return userID == user.userID;
universe@21 102 }
universe@21 103
universe@21 104 @Override
universe@37 105 public int hashCode() {
universe@37 106 return Objects.hash(userID);
universe@33 107 }
universe@21 108 }

mercurial