[seam-commits] Seam SVN: r10067 - trunk/src/main/org/jboss/seam/util.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Fri Feb 20 15:33:10 EST 2009


Author: norman.richards at jboss.com
Date: 2009-02-20 15:33:10 -0500 (Fri, 20 Feb 2009)
New Revision: 10067

Modified:
   trunk/src/main/org/jboss/seam/util/SortItem.java
   trunk/src/main/org/jboss/seam/util/Sorter.java
Log:
JBSEAM-3950

Modified: trunk/src/main/org/jboss/seam/util/SortItem.java
===================================================================
--- trunk/src/main/org/jboss/seam/util/SortItem.java	2009-02-20 17:44:10 UTC (rev 10066)
+++ trunk/src/main/org/jboss/seam/util/SortItem.java	2009-02-20 20:33:10 UTC (rev 10067)
@@ -3,31 +3,38 @@
 import java.util.ArrayList;
 import java.util.List;
 
-public class SortItem<T> 
-{
-   
-	private T obj;
-	private List<SortItem> around = new ArrayList<SortItem>();
-	private List<SortItem> within = new ArrayList<SortItem>();
-	
-	public SortItem(T obj)
-   {
-		this.obj = obj;
-	}
-   
-	public T getObj()
-   {
-		return obj;
-	}
+public class SortItem<T> {
 
-	public List<SortItem> getAround()
-   {
-		return around;
-	}
-   
-	public List<SortItem> getWithin()
-   {
-		return within;
-	}
-   
+    private T obj;
+    private List<SortItem> around = new ArrayList<SortItem>();
+    private List<SortItem> within = new ArrayList<SortItem>();
+
+    public SortItem(T obj) {
+        this.obj = obj;
+    }
+
+    public T getObj() {
+        return obj;
+    }
+
+    public void addAround(SortItem item) {
+        if (item != null) {
+            around.add(item);
+        }
+    }
+    
+    public void addWithin(SortItem item) {
+        if (item != null) {
+            within.add(item);
+        }
+    }
+    
+    public List<SortItem> getAround() {
+        return around;
+    }
+
+    public List<SortItem> getWithin() {
+        return within;
+    }
+
 }

Modified: trunk/src/main/org/jboss/seam/util/Sorter.java
===================================================================
--- trunk/src/main/org/jboss/seam/util/Sorter.java	2009-02-20 17:44:10 UTC (rev 10066)
+++ trunk/src/main/org/jboss/seam/util/Sorter.java	2009-02-20 20:33:10 UTC (rev 10067)
@@ -3,72 +3,58 @@
 import java.util.ArrayList;
 import java.util.List;
 
-public class Sorter<T> 
-{
-   
-	private List<SortItem<T>> list = null; //new ArrayList();
+public class Sorter<T> {
 
-	public List<SortItem<T>> sort(List<SortItem<T>> lst)
-   {
-		
-      this.list = lst;
-		List<SortItem<T>> res = new ArrayList<SortItem<T>>();
-		SortItem<T> inmost = null;
-		
-      do 
-      {	
-			inmost = getInmost();
-			if (inmost!=null)
-         {
-				res.add(inmost);
-				remove(inmost);
-			}
-		}
-      while ( !list.isEmpty() && inmost!=null );
-		
-      if ( !list.isEmpty() )
-      {
-			throw new IllegalArgumentException("Can not sort list:"+list);
-		}
-		
-      return res;		
-	}
-   
-	private void remove(SortItem<T> item)
-   {
-		list.remove(item);
-		for (SortItem<T> o: list)
-      {
-			o.getWithin().remove(item);
-		}
-	}
-   
-	private SortItem<T> getInmost() 
-   {
-		SortItem<T> res=null;
-		for (SortItem<T> o: list)
-      {
-			if ( o.getWithin().isEmpty() && nobodyWantsAround(o) )
-         {
-				res = o;
-				break;
-			}
-		}
-		return res;
-	}
-   
-	private boolean nobodyWantsAround(SortItem<T> item)
-   {
-		boolean res = true;
-		for (SortItem<T> o: list)
-      {
-			if ( o.getAround().contains(item) )
-         {
-				res = false;
-				break;
-			}
-		}
-		return res;
-	}
-   
+    private List<SortItem<T>> list = null; // new ArrayList();
+
+    public List<SortItem<T>> sort(List<SortItem<T>> lst) {
+
+        this.list = lst;
+        List<SortItem<T>> res = new ArrayList<SortItem<T>>();
+        SortItem<T> inmost = null;
+
+        do {
+            inmost = getInmost();
+            if (inmost != null) {
+                res.add(inmost);
+                remove(inmost);
+            }
+        } while (!list.isEmpty() && inmost != null);
+
+        if (!list.isEmpty()) {
+            throw new IllegalArgumentException("Can not sort list:" + list);
+        }
+
+        return res;
+    }
+
+    private void remove(SortItem<T> item) {
+        list.remove(item);
+        for (SortItem<T> o : list) {
+            o.getWithin().remove(item);
+        }
+    }
+
+    private SortItem<T> getInmost() {
+        SortItem<T> res = null;
+        for (SortItem<T> o : list) {
+            if (o.getWithin().isEmpty() && nobodyWantsAround(o)) {
+                res = o;
+                break;
+            }
+        }
+        return res;
+    }
+
+    private boolean nobodyWantsAround(SortItem<T> item) {
+        boolean res = true;
+        for (SortItem<T> o : list) {
+            if (o.getAround().contains(item)) {
+                res = false;
+                break;
+            }
+        }
+        return res;
+    }
+
 }




More information about the seam-commits mailing list