publicinterfaceOn.Function<T> {
/* * Type (1) */T _();
}
Synopsis of Interface On.Action
publicinterfaceOn.Action {
/* * Type (1) */void _();
}
Code
// SSDLPediapackageil.ac.technion.cs.ssdl.utils;
importil.ac.technion.cs.ssdl.stereotypes.Utility;
/** * A utility class, providing functions realizing lazy three-way branching, * depending on the sign of a given integer * * Author: Yossi Gil, the Technion. * See: 24/07/2008 */@UtilitypublicenumOn {
;
/** * A non-lazy selection between three values depending on the sign of a * given integer * * <T> type of values from which to select a return value * selector an integer whose sign determines the returned value * onNegative value to return if selector is negative * onZero value to return if selector is zero * onPositive value to return if selector is positive * Return: one of onNegative, onZero or * onPositive, depending on the sign of * selector */publicstatic <T> Tsign(finalintselector, finalTonNegative, finalTonZero, finalTonPositive) {
if (selector == 0)
returnonZero;
returnselector < 0 ? onNegative : onPositive;
}
/** * A lazy selection between three expressions depending on the sign of a * given integer. Each expression is given as an instance of a class * implementing the Function<T> * interface. * * <T> type of values from which to select a return value * selector an integer whose sign determines the returned value * onNegative expression to evaluate and return if * selector is negative * onZero expression to evaluate and return if selector * is zero * onPositive expression to evaluate and return if * selector is positive * Return: one of onNegative._(), onZero._() or * onPositive._(), depending on the sign of * selector */publicstatic <T> Tsign(finalintselector, finalFunction<T> onNegative, finalFunction<T> onZero,
finalFunction<T> onPositive) {
if (selector == 0)
returnonZero._();
returnselector < 0 ? onNegative._() : onPositive._();
}
/** * Select between one of three actions to carry out, depending on the sign * of a given integer. Each action is given as an instance of a class * implementing the Action<T> * interface. * * selector an integer whose sign determines the returned value * onNegative what to do in case selector is negative * onZero what to do in case selector is zero * onPositive what to do in case selector is positive */publicstaticvoidsign(finalintselector, finalActiononNegative, finalActiononZero, finalActiononPositive) {
sign(selector, asFunction(onNegative), asFunction(onZero), asFunction(onPositive));
}
/** * Select between one of three actions to carry out, depending on the sign * of a given integer. Each action is given as an instance of a class * implementing the Action<T> * interface. * * selector an integer whose sign determines the returned value * onNegative what to do in case selector is negative * onZero what to do in case selector is zero * onPositive what to do in case selector is positive */publicstaticvoidsign(finalIntegerselector, finalActiononNegative, finalActiononZero, finalActiononPositive) {
sign(selector.intValue(), asFunction(onNegative), asFunction(onZero), asFunction(onPositive));
}
publicinterfaceFunction<T> {
T _();
}
publicinterfaceAction {
void _();
}
privatestaticFunction<Void> asFunction(finalActiona) {
returnnewFunction<Void>() {
@OverridepublicVoid _() {
a._();
returnnull;
}
};
}
publicstaticvoidmain(finalString[] args) {
for (finalStringarg : args) {
System.out.print("Argument " + arg + " is ");
On.sign(Integer.valueOf(arg), newAction() {
publicvoid _() {
System.out.println("negative!");
}
}, newAction() {
publicvoid _() {
System.out.println("zero!");
}
}, newAction() {
publicvoid _() {
System.out.println("positive!");
}
});
}
}
}
Metrics
Metric
Value
Acronym
Explanation
LOC
125
Lines Of Code
Total number of lines in the code
SCC
19
SemiColons Count
Total number of semicolon tokens found in the code.
NOT
416
Number Of Tokens
Comments, whitespace and text which cannot be made into a token not included.
VCC
3597
Visible Characters Count
The total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters.
CCC
1337
Code Characters Count
Total number of non-white characters in tokens. White space characters in string and character literals are not counted.
UIC
32
Unique Identifiers Count
The number of different identifiers found in the code