Parent: [r3] (diff)

Child: [r24] (diff)

Download this file

Person.java    178 lines (150 with data), 5.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* SPDXVersion: SPDX-1.1
* Person: Person: Nuno Brito (nuno.brito@triplecheck.de)
* Person: Organization: TripleCheck (contact@triplecheck.de)
* Created: 2013-08-29T00:00:00Z
* LicenseName: NOASSERTION
* FileName: Person.java
* FileType: SOURCE
* FileCopyrightText: <text> Copyright 2013 Nuno Brito, TripleCheck </text>
* FileComment: <text> Class defining the identity of a given person </text>
*/
package spdxlib;
public class Person {
private String
person = "", // mandatory field
personEmail = "", // optional field
organization = "", // mandatory field
organizationEmail = "", // optional field
tool = "", // mandatory field
toolVersion = "" // mandatory field
;
private TagValue
tagOrganization,
tagPerson,
tagTool;
/**
* Provides a distinctive identifier title
* @return
*/
public String getTitle(){
// if there is a name, use it
if(tagPerson != null){
return tagPerson.toString();
}
// or use the organization name if available
if(tagOrganization != null){
return tagOrganization.toString();
}
// or even use the tool name if available
if(tagTool != null){
return tagTool.toString();
}
// nothing good here, just return null..
return null;
}
public TagValue getTagPerson() {
return tagPerson;
}
public void setTagPerson(TagValue tagPerson) {
// do the basic handling
person = tagPerson.toString();
this.tagPerson = tagPerson;
// now do the more refined processing, try to extract values
String temp = tagPerson.toString();
// do we have an email address like: "(nuno.brito@triplecheck.de)"?
if(temp.contains(" (")&&temp.contains(")")){
int start = temp.indexOf("(");
int end = temp.lastIndexOf(")");
// something is wrong, just leave
if(start +1 > end){
return;
}
// get the email address
String thisMail = temp.substring(start +1, end);
this.personEmail = thisMail;
this.person = temp.substring(0, start -1);
}
}
public TagValue getTagOrganization() {
return tagOrganization;
}
public void setTagOrganization(TagValue tagOrganization) {
// do the basic handling
organization = tagOrganization.toString();
this.tagOrganization = tagOrganization;
// now do the more refined processing, try to extract values
String temp = tagOrganization.toString();
// do we have an email address like: "(nuno.brito@triplecheck.de)"?
if(temp.contains(" (")&&temp.contains(")")){
int start = temp.indexOf("(");
int end = temp.lastIndexOf(")");
// something is wrong, just leave
if(start +1 > end){
return;
}
// get the email address
String thisMail = temp.substring(start +1, end);
this.organizationEmail = thisMail;
this.organization = temp.substring(0, start -1);
}
}
public TagValue getTagTool() {
return tagTool;
}
public void setTagTool(TagValue tagTool) {
// basic handling
this.tagTool = tagTool;
tool = tagTool.toString();
// more refined search for the version number
int pos = tool.indexOf("-");
if(pos < 1){
return;
}
// hopefully we get a nicely formatted string
toolVersion = tool.substring(pos+1);
tool = tool.substring(0, pos);
}
@Override
public String toString(){
return getTitle();
}
public String getPerson() {
return person;
}
public String getPersonEmail() {
return personEmail;
}
public String getOrganization() {
return organization;
}
public String getOrganizationEmail() {
return organizationEmail;
}
public String getTool() {
return tool;
}
public String getToolVersion() {
return toolVersion;
}
/**
* Calculates what is the best place to add a new tag related to a Person
* @return the line number inside the SPDX document that should be used
*/
public int getAnchor() {
// if there is a name, use it
if(tagPerson != null){
return tagPerson.linePosition;
}
// or use the organization name if available
if(tagOrganization != null){
return tagOrganization.linePosition;
}
// or even use the tool name if available
if(tagTool != null){
return tagTool.linePosition;
}
// nothing good here, just return 0 but this is not a goot thing..
return 0;
}
}