001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017package com.echothree.util.common.string; 018 019public class NameResult { 020 021 private String personalTitleChoice; 022 private String firstName; 023 private String middleName; 024 private String lastName; 025 private String nameSuffixChoice; 026 027 public NameResult(final String personalTitleChoice, final String firstName, final String middleName, 028 final String lastName, final String nameSuffixChoice) { 029 this.personalTitleChoice = personalTitleChoice; 030 this.firstName = firstName; 031 this.middleName = middleName; 032 this.lastName = lastName; 033 this.nameSuffixChoice = nameSuffixChoice; 034 } 035 036 /** 037 * Returns the personalTitleChoice. 038 * @return the personalTitleChoice 039 */ 040 public String getPersonalTitleChoice() { 041 return personalTitleChoice; 042 } 043 044 /** 045 * Returns the firstName. 046 * @return the firstName 047 */ 048 public String getFirstName() { 049 return firstName; 050 } 051 052 /** 053 * Returns the middleName. 054 * @return the middleName 055 */ 056 public String getMiddleName() { 057 return middleName; 058 } 059 060 /** 061 * Returns the lastName. 062 * @return the lastName 063 */ 064 public String getLastName() { 065 return lastName; 066 } 067 068 /** 069 * Returns the nameSuffixChoice. 070 * @return the nameSuffixChoice 071 */ 072 public String getNameSuffixChoice() { 073 return nameSuffixChoice; 074 } 075 076 public void print() { 077 System.out.println("personalTitleChoice.: " + personalTitleChoice); 078 System.out.println("firstName...........: " + firstName); 079 System.out.println("middleName..........: " + middleName); 080 System.out.println("lastName............: " + lastName); 081 System.out.println("nameSuffixChoice....: " + nameSuffixChoice); 082 } 083 084 public String getFormattedName() { 085 var formattedName = new StringBuilder(); 086 087 if(firstName != null) { 088 formattedName.append(firstName); 089 } 090 091 if(middleName != null) { 092 if(formattedName.length() > 0) { 093 formattedName.append(' '); 094 } 095 096 formattedName.append(middleName); 097 098 if(middleName.length() == 1) { 099 formattedName.append('.'); 100 } 101 } 102 103 if(lastName != null) { 104 if(formattedName.length() > 0) { 105 formattedName.append(' '); 106 } 107 108 formattedName.append(lastName); 109 } 110 111 return formattedName.toString(); 112 } 113 114}