BrightSide Workbench Full Report + Source Code
Version.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.vcard.properties;
19 
20 import java.util.List;
21 import org.turro.string.Strings;
22 
27 public enum Version {
28 
29  V21(21), V30(30);
30 
31  public static Version getInstance(List<String> lines) {
32  for(String l : lines) {
33  if(l.equalsIgnoreCase("VERSION:3.0")) {
34  return V30;
35  }
36  }
37  return V21;
38  }
39 
40  private int version;
41 
42  private Version(int version) {
43  this.version = version;
44  }
45 
46  public void renderTypes(StringBuilder sb, List<String> types) {
47  if(types.isEmpty()) return;
48  if(version == 21) {
49  for(String t : types) {
50  sb.append(";" + t);
51  }
52  } else if(version == 30) {
53  sb.append("TYPE=");
54  for(String t : types) {
55  sb.append("," + t);
56  }
57  }
58  }
59 
60  public void renderVersion(StringBuilder sb) {
61  sb.append("VERSION:");
62  if(version == 21) {
63  sb.append("2.1");
64  } else if(version == 30) {
65  sb.append("3.0");
66  }
67  sb.append("\n");
68  }
69 
70  public void readTypes(String s, List<String> types) {
71  if(Strings.isBlank(s)) return;
72  if(s.startsWith(";")) s = s.substring(1);
73  if(version == 21) {
74  for(String t : s.split(";")) {
75  if(!Strings.isBlank(t)) types.add(t);
76  }
77  } else if(version == 30) {
78  if(s.toUpperCase().startsWith("TYPE=")) {
79  s = s.substring(5);
80  for(String t : s.split(",")) {
81  if(!Strings.isBlank(t)) types.add(t);
82  }
83  }
84  }
85  }
86 }
static Version getInstance(List< String > lines)
Definition: Version.java:31
void renderVersion(StringBuilder sb)
Definition: Version.java:60
void renderTypes(StringBuilder sb, List< String > types)
Definition: Version.java:46
void readTypes(String s, List< String > types)
Definition: Version.java:70