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

Thu, 15 Oct 2020 18:36:05 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 15 Oct 2020 18:36:05 +0200
changeset 130
7ef369744fd1
parent 75
33b6843fdf8a
permissions
-rw-r--r--

adds the possibility to specify path parameters to RequestMapping

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@51 37 private final int id;
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@51 43 public User(int id) {
universe@51 44 this.id = id;
universe@37 45 }
universe@37 46
universe@51 47 public int getId() {
universe@51 48 return id;
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@75 83 public String getShortDisplayname() {
universe@47 84 StringBuilder dn = new StringBuilder();
universe@51 85 if (givenname != null)
universe@51 86 dn.append(givenname);
universe@47 87 dn.append(' ');
universe@51 88 if (lastname != null)
universe@51 89 dn.append(lastname);
universe@47 90 final var str = dn.toString().trim();
universe@47 91 return str.isBlank() ? username : str;
universe@47 92 }
universe@47 93
universe@75 94 public String getDisplayname() {
universe@75 95 final String sdn = getShortDisplayname();
universe@75 96 if (mail != null && !mail.isBlank()) {
universe@75 97 return sdn + " <" + mail + ">";
universe@75 98 } else {
universe@75 99 return sdn;
universe@75 100 }
universe@75 101 }
universe@75 102
universe@21 103 @Override
universe@37 104 public boolean equals(Object o) {
universe@37 105 if (this == o) return true;
universe@37 106 if (o == null || getClass() != o.getClass()) return false;
universe@37 107 User user = (User) o;
universe@51 108 return id == user.id;
universe@21 109 }
universe@21 110
universe@21 111 @Override
universe@37 112 public int hashCode() {
universe@51 113 return Objects.hash(id);
universe@33 114 }
universe@21 115 }

mercurial