< prev index next >
src/share/classes/javax/swing/LayoutComparator.java
Print this page
rev 1527 : 6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov
@@ -37,11 +37,11 @@
* position. Code adapted from original javax.swing.DefaultFocusManager
* implementation.
*
* @author David Mendenhall
*/
-final class LayoutComparator implements Comparator, java.io.Serializable {
+final class LayoutComparator implements Comparator<Component>, java.io.Serializable {
private static final int ROW_TOLERANCE = 10;
private boolean horizontal = true;
private boolean leftToRight = true;
@@ -49,60 +49,59 @@
void setComponentOrientation(ComponentOrientation orientation) {
horizontal = orientation.isHorizontal();
leftToRight = orientation.isLeftToRight();
}
- public int compare(Object o1, Object o2) {
- Component a = (Component)o1;
- Component b = (Component)o2;
-
+ public int compare(Component a, Component b) {
if (a == b) {
return 0;
}
// Row/Column algorithm only applies to siblings. If 'a' and 'b'
// aren't siblings, then we need to find their most inferior
// ancestors which share a parent. Compute the ancestory lists for
// each Component and then search from the Window down until the
// hierarchy branches.
if (a.getParent() != b.getParent()) {
- LinkedList aAncestory, bAncestory;
+ LinkedList<Component> aAncestory = new LinkedList<Component>();
- for(aAncestory = new LinkedList(); a != null; a = a.getParent()) {
+ for(; a != null; a = a.getParent()) {
aAncestory.add(a);
if (a instanceof Window) {
break;
}
}
if (a == null) {
// 'a' is not part of a Window hierarchy. Can't cope.
throw new ClassCastException();
}
- for(bAncestory = new LinkedList(); b != null; b = b.getParent()) {
+ LinkedList<Component> bAncestory = new LinkedList<Component>();
+
+ for(; b != null; b = b.getParent()) {
bAncestory.add(b);
if (b instanceof Window) {
break;
}
}
if (b == null) {
// 'b' is not part of a Window hierarchy. Can't cope.
throw new ClassCastException();
}
- for (ListIterator
+ for (ListIterator<Component>
aIter = aAncestory.listIterator(aAncestory.size()),
bIter = bAncestory.listIterator(bAncestory.size()); ;) {
if (aIter.hasPrevious()) {
- a = (Component)aIter.previous();
+ a = aIter.previous();
} else {
// a is an ancestor of b
return -1;
}
if (bIter.hasPrevious()) {
- b = (Component)bIter.previous();
+ b = bIter.previous();
} else {
// b is an ancestor of a
return 1;
}
< prev index next >