BrightSide Workbench Full Report + Source Code
RelationAdapter.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.contacts.util;
20 
21 import org.turro.string.Strings;
22 import org.turro.contacts.Contact;
23 import org.turro.i18n.I_;
24 import org.turro.util.Chars;
25 import org.turro.util.PhraseBuilder;
26 
31 public class RelationAdapter {
32 
33  private final Contact self, related;
34  private final String description, relationType;
35  private final boolean preferential;
36 
37  public RelationAdapter(Contact self, Contact related, String description, String relationType, boolean preferential) {
38  this.self = self;
39  this.related = related;
40  this.description = description;
41  this.relationType = relationType;
42  this.preferential = preferential;
43  }
44 
45  public Contact getSelf() {
46  return self;
47  }
48 
49  public Contact getRelated() {
50  return related;
51  }
52 
53  public String getDescription() {
54  return description;
55  }
56 
57  public String getRelationType() {
58  return relationType;
59  }
60 
61  public boolean isPreferential() {
62  return preferential;
63  }
64 
65  public String getFullRelationString() {
66  String result = "", formated = getRelationString();
67  if(formated != null) result += formated + Chars.forward().spaced();
68  if(related != null) result += " " + related.getName();
69  return result;
70  }
71 
72  public String getRelationString() {
73  PhraseBuilder pb = new PhraseBuilder();
74  if(!Strings.isBlank(relationType)) {
75  pb.addWord(I_.byKey(relationType.substring(1)));
76  }
77  pb.addWord(description);
78  if(!pb.isBlank()) {
79  return pb.toString();
80  } else {
81  return "**";
82  }
83  }
84 
85 }
RelationAdapter(Contact self, Contact related, String description, String relationType, boolean preferential)
static String byKey(String key)
Definition: I_.java:83