Methods Summary |
---|
public static void | containsNested(java.util.List list, java.lang.Object target)Demo of unnecessary if evaluation.
Iterator iter = list.iterator();
for (Set inner = null; iter.hasNext(); inner = (Set)iter.next()) {
if (inner != null) {
if (inner.contains(target)) {
// do code.
}
}
}
|
public static void | containsNested2(java.util.List list, java.lang.Object target)Demo of abbreviated if evaluation.
Iterator iter = list.iterator();
for (Set inner = null; iter.hasNext(); inner = (Set)iter.next()) {
if ((inner != null) && (inner.contains(target))) {
// do code.
}
}
|
public static void | containsNested3(java.util.List list, java.lang.Object target)Demo of abbreviated if evaluation.
boolean flag = false;
Iterator iter = list.iterator();
for (Set inner = null; iter.hasNext(); inner = (Set)iter.next()) {
if ((inner != null) && (flag = iter.hasNext())) {
// do code.
target.hashCode(); // used just to supress warnings.
if (flag) {
// do some extra code.
}
}
}
|
public static void | continueFunc()__UNDOCUMENTED__
for (int idx = 0; idx < 1000; idx++) {
// ... do some complex code.
if (idx == 555) {
break;
}
// ... processing code
}
for (int idx = 0; idx < 1000; idx++) {
// ... do some complex code.
if (idx == 555) {
continue;
}
// ... processing code
}
|
public static java.lang.String | decode(int input)__UNDOCUMENTED__
String decoded = null;
switch (input) {
case 1:
decoded = "Option 2";
break;
case 2:
case 3:
decoded = "Option 2";
break;
case 4:
decoded = "Option 2";
break;
default:
return "Option 3";
}
return decoded;
|
public static int[] | extractXCoords(java.util.List points)Extract x coordinates from a list of Point s.
int[] results = new int[points.size()];
Point element = null;
int idx = 0;
Iterator iter = points.iterator();
while (iter.hasNext()) {
element = (Point)iter.next();
results[idx] = element.x;
idx++;
}
return results;
|
public static int[] | extractXCoords2(java.util.List points)Extract x coordinates from a list of Point s.
int[] results = new int[points.size()];
Point element = null;
Iterator iter = points.iterator();
for (int idx = 0; iter.hasNext(); idx++) {
element = (Point)iter.next();
results[idx] = element.x;
}
return results;
|
public static final void | main(java.lang.String[] args)Main method.
// -- Test the extract points methods.
List points = new LinkedList();
points.add(new Point(22, 1));
points.add(new Point(38, 34));
points.add(new Point(27, 22));
points.add(new Point(12, 103));
points.add(new Point(9, 5));
int[] intPts = extractXCoords(points);
for (int idx = 0; idx < intPts.length; idx++) {
System.out.print(intPts[idx] + ", ");
}
System.out.println();
int[] intPts2 = extractXCoords2(points);
for (int idx = 0; idx < intPts2.length; idx++) {
System.out.print(intPts2[idx] + ", ");
}
System.out.println();
// -- Test ternary
System.out.println(someMethod(new Point(5, 9)));
System.out.println(someElegantMethod(new Point(5, 9)));
|
public static void | matrixMeth(java.awt.Point[][] values)__UNDOCUMENTED__
for (int x = 0; x < values[0].length; x++) {
for (int y = 0; y < values.length; y++) {
if ((values[x][y].x < 0) || (values[x][y].y < 0)) {
break; // exit to error logging line.
}
// do something with the value
}
}
System.err.println("Invalid Point in Matrix");
// continue processing
|
public static void | matrixMeth2(java.awt.Point[][] values)__UNDOCUMENTED__
RESTART: {
for (int x = 0; x < values[0].length; x++) {
for (int y = 0; y < values.length; y++) {
if ((values[x][y].x < 0) || (values[x][y].y < 0)) {
values[x][y].x = Math.max(values[x][y].x, 0);
values[x][y].y = Math.max(values[x][y].y, 0);
break RESTART; // Try to process again!
}
// do something with the value
}
}
}
// continue processing
|
public static void | matrixMeth3(java.awt.Point[][] values)__UNDOCUMENTED__
LINE:
for (int x = 0; x < values[0].length; x++) {
COLUMN:
for (int y = 0; y < values.length; y++) {
if ((values[x][y].x < 0) || (values[x][y].y < 0)) {
continue LINE; // skip the rest of the line;
}
// do something with the value
}
}
LOGLINE:
System.err.println("Invalid Point in Matrix");
// continue processing
PASS_TWO:
for (int x = 0; x < values[0].length; x++) {
// do some code.
}
|
public static int | someElegantMethod(java.awt.Point p)__UNDOCUMENTED__
return (p == null) ? 0 : (p.x + p.y);
|
protected java.lang.Object | someHelperMethod()__UNDOCUMENTED__
Object result = null;
// ... do some code that sets result.
assert (result != null); // check post condition.
return result;
|
protected void | someLoop(java.util.Set set)__UNDOCUMENTED__
Iterator iter = set.iterator();
while (iter.hasNext()) {
String element = (String)iter.next();
System.out.println(element.length());
}
|
public static int | someMethod(java.awt.Point p)__UNDOCUMENTED__
if (p == null) {
return 0;
} else {
return p.x + p.y;
}
|