// SSDLPediapackageil.ac.technion.cs.ssdl.csv;
importstaticil.ac.technion.cs.ssdl.utils.DBC.nonnull;
importil.ac.technion.cs.ssdl.stereotypes.Canopy;
importil.ac.technion.cs.ssdl.stereotypes.Instantiable;
importil.ac.technion.cs.ssdl.utils.Separate;
importjava.util.*;
/** * Create a line in an "Comma Separated Values" format from a sequence of named * values. * * Author: Yossi Gil */@InstantiablepublicabstractclassCSVLine {
/** * Wraps values in a CSV line. Occurrences of this character in field * content are escaped by typing it twice. */publicstaticfinalcharQUOTE = '\"';
/** * Separates values in a CSV line */publicstaticfinalcharDELIMETER = ',';
/** * Separator of multi-values, i.e., array elements stored in a single field */publicstaticfinalStringARRAY_SEPARATOR = ";";
/** * A total inspector * * Return: the content of the CSV line as per all recorded values. */publicabstractStringline();
/** * A total inspector * * Return: the header of the CSV line */publicabstractStringheader();
/** * A mutator to add a key and a general String value to the CSV line * * key the key to be added * value The value associated with the key */publicabstractvoidput(finalStringkey, finalStringvalue);
/** * Add a key without a value to the current CSV line. * * key The key to be inserted */publicfinalvoidput(finalStringkey) {
nonnull(key);
put(key, "");
}
/** * Add a key and a general Object value to the CSV line * * key The key to be added * value The value associated with the key */publicfinalvoidput(finalStringkey, finalObjectvalue) {
nonnull(key);
if (value == null)
put(key);
elseput(key, value.toString());
}
/** * Add a key and a general float<tt> value to the CSV line</font> * * key The key to be added * value The value associated with the key */publicfinalvoidput(finalStringkey, finalfloatvalue) {
nonnull(key);
put(key, "" + value);
}
/** * Add a key and a <tt>double<tt> value to the CSV line * * key The key to be added * value The value associated with the key */publicfinalvoidput(finalStringkey, finaldoublevalue) {
nonnull(key);
put(key, "" + value);
}
/** * Add a key and an <tt>int</tt> value to the CSV line * * key The key to be added * value The value associated with the key */publicfinalvoidput(finalStringkey, finalintvalue) {
nonnull(key);
put(key, "" + value);
}
/** * Add a key and a <tt>long</tt> value to the CSV line * * key The key to be added * value The value associated with the key */publicfinalvoidput(finalStringkey, finallongvalue) {
nonnull(key);
put(key, "" + value);
}
/** * Add a key and a <tt>short</tt> value to the CSV line * * key The key to be added * value The value associated with the key */publicfinalvoidput(finalStringkey, finalshortvalue) {
nonnull(key);
put(key, "" + value);
}
/** * Add a key and a <tt>char</tt> value to the CSV line * * key The key to be added * value The value associated with the key */publicfinalvoidput(finalStringkey, finalcharvalue) {
nonnull(key);
put(key, "" + value);
}
/** * Add a key and a <tt>boolean</tt> value to the CSV line * * key The key to be added * value The value associated with the key */publicfinalvoidput(finalStringkey, finalbooleanvalue) {
nonnull(key);
put(key, "" + value);
}
publicfinalvoidput(finalStringkey, finalObjecta[], finalinti) {
nonnull(key);
put(key, a == null || i < 0 || i >= a.length ? null : a[i]);
}
publicfinalvoidput(finalStringkey, finalObject[] os) {
nonnull(key);
put(key, os == null ? null : Separate.by(os, ARRAY_SEPARATOR));
}
/** * Return: the QUOTE */publicstaticStringQUOTE() {
return"" + QUOTE;
}
publicstaticStringquote(finalStrings) {
returnQUOTE() + //
(s == null ? "" : s.replaceAll(QUOTE(), QUOTE() + QUOTE())) //
+ QUOTE();
}
staticpublicStringmakeLine(finalIterable<String> ss) {
returnSeparate.by(newSeparate.F<String>() {
publicfinalString _(finalStringo) {
returnquote(o);
}
}, ss, DELIMETER);
}
staticpublicStringmakeLine(finalString... ss) {
returnSeparate.by(newSeparate.F<String>() {
publicfinalString _(finalStringo) {
returnquote(o);
}
}, ss, DELIMETER);
}
staticpublicStringmakeLine(finalObject... ss) {
returnSeparate.by(newSeparate.F<Object>() {
publicfinalString _(finalObjecto) {
returnquote(o.toString());
}
}, ss, DELIMETER);
}
@CanopypublicstaticfinalclassSorterdextendsCSVLine {
privatefinalMap<String, String> map = newTreeMap<String, String>();
@OverridepublicStringheader() {
returnmakeLine(map.keySet());
}
@OverridepublicStringline() {
returnmakeLine(map.values());
}
@Overridepublicfinalvoidput(finalStringkey, finalStringvalue) {
map.put(key, value);
}
}
@CanopypublicstaticfinalclassOrderedextendsCSVLine {
privatefinalstaticclassRecord {
publicfinalStringkey;
publicStringvalue;
publicRecord(finalStringkey, finalStringvalue) {
this.key = key;
this.value = value;
}
}
privatefinalList<Record> map = newArrayList<Record>();
@OverridepublicfinalStringheader() {
returnSeparate.by(newSeparate.F<Record>() {
@OverridepublicString _(finalRecordr) {
returnquote(r.key);
}
}, map, DELIMETER);
}
@OverridepublicfinalStringline() {
returnSeparate.by(newSeparate.F<Record>() {
@OverridepublicString _(finalRecordr) {
returnquote(r.value);
}
}, map, DELIMETER);
}
@Overridepublicfinalvoidput(finalStringkey, finalStringvalue) {
for (finalRecordr : map)
if (key.equals(r.key)) {
r.value = value;
return;
}
map.add(newRecord(key, value));
}
}
}
Metrics
Metric
Value
Acronym
Explanation
LOC
257
Lines Of Code
Total number of lines in the code
SCC
59
SemiColons Count
Total number of semicolon tokens found in the code.
NOT
1042
Number Of Tokens
Comments, whitespace and text which cannot be made into a token not included.
VCC
4885
Visible Characters Count
The total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters.
CCC
3168
Code Characters Count
Total number of non-white characters in tokens. White space characters in string and character literals are not counted.
UIC
54
Unique Identifiers Count
The number of different identifiers found in the code