Enum Defaults - SpartanRefactoring/Main GitHub Wiki
Synopsis of Enum Defaults
public enum Defaults {
/*
* Utilities (3)
*/
static int to(Integer v, int defaultValue);
static int to(Integer v, Integer defaultValue);
static T to(T v, T defaultValue);
}
Code
// SSDLPedia
package il.ac.technion.cs.ssdl.utils;
import il.ac.technion.cs.ssdl.stereotypes.Utility;
/**
* A bunch of static functions to manage the frequent
* conditional of replacing a null value with some default.
* Writing
final String guess = Defaults.to(answer,"A")
* will assign the String "A" to variable
* guess in the case that answer is
* null. If however, answer is not
* null then guess's value will be that of
* answer.
*
* Author: Yossi Gil, 2008/06/20
*/
@Utility public enum Defaults {
;
/**
* Return a default value for an Integer type.
*
* v a possibly null value
* defaultValue a value to be used in case v is
* null
* Return: v if it is not null, otherwise
* defaultValue
*/
public static int to(final Integer v, final int defaultValue) {
return v != null ? v.intValue() : defaultValue;
}
/**
* Return a default value for an Integer type.
*
* v a possibly null value
* defaultValue a value to be used in case v is
* null
* Return: v if it is not null, otherwise
* defaultValue
*/
public static int to(final Integer v, final Integer defaultValue) {
return v != null ? v.intValue() : defaultValue.intValue();
}
/**
* Return a default value for an arbitrary type.
*
* <T> type of parameter to receive a default value
* v a possibly null value
* defaultValue a value to be used in case v is
* null
* Return: v if it is not null, otherwise
* defaultValue
*/
public static <T> T to(final T v, final T defaultValue) {
return v != null ? v : defaultValue;
}
}
Metrics
| Metric |
Value |
Acronym |
Explanation |
| LOC |
65 |
Lines Of Code |
Total number of lines in the code |
| SCC |
6 |
SemiColons Count |
Total number of semicolon tokens found in the code. |
| NOT |
122 |
Number Of Tokens |
Comments, whitespace and text which cannot be made into a token not included. |
| VCC |
1804 |
Visible Characters Count |
The total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters. |
| CCC |
396 |
Code Characters Count |
Total number of non-white characters in tokens. White space characters in string and character literals are not counted. |
| UIC |
15 |
Unique Identifiers Count |
The number of different identifiers found in the code |
| WHC |
2 |
Weighted Horizontal Complexity |
A heuritistic on horizontal complexity |
Statistics
| Statitic |
Value |
| Average token length |
3.2 |
| Tokens/line |
1.9 |
| Visible characters/line |
28 |
| Code characters/line |
6.1 |
| Semicolons/tokens |
4% |
| Comment text percentage |
78% |
Tokens by Kind
| Token Kind |
Occurrences |
| KEYWORD |
25 |
| OPERATOR |
8 |
| LITERAL |
0 |
| ID |
43 |
| PUNCTUATION |
46 |
| COMMENT |
5 |
| OTHER |
73 |