Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
53   180   24   8.83
30   107   0.45   6
6     4  
1    
 
 
  Convert       Line # 34 53 24 0% 0.0
 
No Tests
 
1    /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10    * the Free Software Foundation; either version 2 of the License, or
11    * (at your option) any later version.
12    *
13    * This program is distributed in the hope that it will be useful,
14    * but WITHOUT ANY WARRANTY; without even the implied warranty of
15    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16    * GNU General Public License for more details.
17    */
18   
19    package org.itracker.services.util;
20   
21    import java.util.ArrayList;
22    import java.util.Arrays;
23    import java.util.List;
24    import java.util.Locale;
25    import java.util.NoSuchElementException;
26    import java.util.StringTokenizer;
27   
28    import org.itracker.model.Component;
29    import org.itracker.model.CustomFieldValue;
30    import org.itracker.model.NameValuePair;
31    import org.itracker.model.User;
32    import org.itracker.model.Version;
33   
 
34    public class Convert {
35    /**
36    * Converts an array of CustomFieldValueModels to NameValuePairs
37    *
38    * @param options
39    * the array of CustomFieldValueModels to convert
40    * @return the new NameValuePair array
41    */
 
42  0 toggle public static List<NameValuePair> customFieldOptionsToNameValuePairs(
43    List<CustomFieldValue> options) {
44  0 return customFieldOptionsToNameValuePairs(options, null);
45   
46    }
47    /**
48    * Converts an array of CustomFieldValueModels to NameValuePairs
49    *
50    * @param options
51    * the array of CustomFieldValueModels to convert
52    * @return the new NameValuePair array
53    */
 
54  0 toggle public static List<NameValuePair> customFieldOptionsToNameValuePairs(
55    List<CustomFieldValue> options, Locale locale) {
56  0 List<NameValuePair> returnValues = new ArrayList<NameValuePair>();
57  0 String name;
58  0 if (options != null) {
59  0 returnValues = new ArrayList<NameValuePair>();
60  0 for (int i = 0; i < options.size(); i++) {
61  0 name = CustomFieldUtilities.getCustomFieldOptionName(options.get(i), locale);
62  0 returnValues
63    .add(new NameValuePair(name, options.get(i).getValue()));
64    }
65    }
66   
67  0 return returnValues;
68    }
69    /**
70    * Converts an array of UserModels to NameValuePairs
71    *
72    * @param options
73    * the array of UserModels to convert
74    * @return the new NameValuePair array
75    */
 
76  0 toggle public static List<NameValuePair> usersToNameValuePairs(List<User> users) {
77  0 List<NameValuePair> returnValues = new ArrayList<NameValuePair>();
78   
79  0 if (users != null) {
80  0 returnValues = new ArrayList<NameValuePair>();
81  0 for (int i = 0; i < users.size(); i++) {
82  0 returnValues.add(new NameValuePair(users.get(i).getFirstName()
83    + " " + users.get(i).getLastName(), users.get(i)
84    .getId().toString()));
85    }
86    }
87   
88  0 return returnValues;
89    }
90   
91    /**
92    * Converts an array of ComponentModels to NameValuePairs
93    *
94    * @param options
95    * the array of ComponentModels to convert
96    * @return the new NameValuePair array
97    */
 
98  0 toggle public static List<NameValuePair> componentsToNameValuePairs(
99    List<Component> components) {
100  0 NameValuePair[] returnValues = new NameValuePair[0];
101   
102  0 if (components != null) {
103  0 returnValues = new NameValuePair[components.size()];
104  0 for (int i = 0; i < components.size(); i++) {
105  0 returnValues[i] = new NameValuePair(
106    components.get(i).getName(), components.get(i).getId()
107    .toString());
108    }
109    }
110   
111  0 return Arrays.asList(returnValues);
112    }
113   
114    /**
115    * Converts an array of VersionModels to NameValuePairs
116    *
117    * @param options
118    * the array of VersionModels to convert
119    * @return the new NameValuePair array
120    */
 
121  0 toggle public static List<NameValuePair> versionsToNameValuePairs(
122    List<Version> versions) {
123  0 NameValuePair[] returnValues = new NameValuePair[0];
124   
125  0 if (versions != null) {
126  0 returnValues = new NameValuePair[versions.size()];
127  0 for (int i = 0; i < versions.size(); i++) {
128  0 returnValues[i] = new NameValuePair(
129    versions.get(i).getNumber(), versions.get(i).getId()
130    .toString());
131    }
132    }
133   
134  0 return Arrays.asList(returnValues);
135    }
136   
 
137  0 toggle public static String[] stringToArray(String input) {
138  0 if (input == null || "".equals(input)) {
139  0 return new String[0];
140    }
141   
142  0 List<String> tokenList = new ArrayList<String>();
143  0 StringTokenizer tokenizer = new StringTokenizer(input, " ");
144  0 while (tokenizer.hasMoreElements()) {
145  0 boolean quotedToken = false;
146  0 String tokenString = tokenizer.nextToken();
147  0 if (tokenString.startsWith("\"")) {
148  0 quotedToken = true;
149  0 tokenString = tokenString.substring(1);
150  0 if (tokenString.endsWith("\"") && !tokenString.endsWith("\\\"")) {
151  0 quotedToken = false;
152  0 tokenString = tokenString.substring(0, tokenString.length() - 1);
153    }
154    }
155   
156  0 if (quotedToken) {
157  0 boolean getNext = true;
158   
159  0 StringBuffer token = new StringBuffer(tokenString);
160  0 while (getNext) {
161  0 try {
162  0 token.append(tokenizer.nextToken("\""));
163  0 if (!token.toString().endsWith("\\\"")) {
164  0 getNext = false;
165    }
166    } catch (NoSuchElementException e) {
167  0 break;
168    }
169    }
170  0 tokenString = token.toString();
171    }
172   
173  0 tokenList.add(tokenString);
174    }
175   
176  0 String[] stringArray = (String[]) tokenList.toArray(new String[] {});
177   
178  0 return stringArray;
179    }
180    }