|
From: <be...@us...> - 2006-10-23 21:13:31
|
Revision: 50
http://svn.sourceforge.net/jtreemap/?rev=50&view=rev
Author: benoitx
Date: 2006-10-23 14:13:05 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByWeight.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByWeight.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByWeight.java (from rev 49, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByWeight.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByWeight.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByWeight.java 2006-10-23 21:13:05 UTC (rev 50)
@@ -0,0 +1,53 @@
+package org.jense.swing.jtreemap;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+/**
+ * Strategy who split the elements in 2 groups of equivalent weight.
+ *
+ * @author Laurent Dutheil
+ */
+
+public class SplitByWeight extends SplitStrategy {
+
+ @Override
+ public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1,
+ Vector<TreeMapNode> v2) {
+ double memWeight = 0.0;
+ double sumWeight = sumWeight(v);
+ double elemWeight = 0.0;
+
+ for (Iterator<TreeMapNode> i = v.iterator(); i.hasNext();) {
+ TreeMapNode tmn = i.next();
+ elemWeight = tmn.getWeight();
+ // if adding the current element pass the middle of total weight
+ if (memWeight + elemWeight >= sumWeight / 2) {
+ // we look at the finest split (the nearest of the middle of weight)
+ if (((sumWeight / 2) - memWeight) > ((memWeight + elemWeight) - (sumWeight / 2))) {
+ // if it is after the add, we add the element to the first Vector
+ memWeight += elemWeight;
+ v1.addElement(tmn);
+ } else {
+ // we must have at least 1 element in the first vector
+ if (v1.isEmpty()) {
+ v1.addElement(tmn);
+ } else {
+ // if it is before the add, we add the element to the second Vector
+ v2.addElement(tmn);
+ }
+ }
+ // then we fill the second Vector qith the rest of elements
+ while (i.hasNext()) {
+ tmn = i.next();
+ v2.addElement(tmn);
+ }
+ } else {
+ // we add in the first vector while we don't reach the middle of weight
+ memWeight += elemWeight;
+ v1.addElement(tmn);
+ }
+ }
+ }
+
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByWeight.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByWeight.java 2006-10-23 21:09:11 UTC (rev 49)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByWeight.java 2006-10-23 21:13:05 UTC (rev 50)
@@ -1,53 +0,0 @@
-package org.jense.swing.jtreemap;
-
-import java.util.Iterator;
-import java.util.Vector;
-
-/**
- * Strategy who split the elements in 2 groups of equivalent weight.
- *
- * @author Laurent Dutheil
- */
-
-public class SplitByWeight extends SplitStrategy {
-
- @Override
- public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1,
- Vector<TreeMapNode> v2) {
- double memWeight = 0.0;
- double sumWeight = sumWeight(v);
- double elemWeight = 0.0;
-
- for (Iterator<TreeMapNode> i = v.iterator(); i.hasNext();) {
- TreeMapNode tmn = i.next();
- elemWeight = tmn.getWeight();
- // if adding the current element pass the middle of total weight
- if (memWeight + elemWeight >= sumWeight / 2) {
- // we look at the finest split (the nearest of the middle of weight)
- if (((sumWeight / 2) - memWeight) > ((memWeight + elemWeight) - (sumWeight / 2))) {
- // if it is after the add, we add the element to the first Vector
- memWeight += elemWeight;
- v1.addElement(tmn);
- } else {
- // we must have at least 1 element in the first vector
- if (v1.isEmpty()) {
- v1.addElement(tmn);
- } else {
- // if it is before the add, we add the element to the second Vector
- v2.addElement(tmn);
- }
- }
- // then we fill the second Vector qith the rest of elements
- while (i.hasNext()) {
- tmn = i.next();
- v2.addElement(tmn);
- }
- } else {
- // we add in the first vector while we don't reach the middle of weight
- memWeight += elemWeight;
- v1.addElement(tmn);
- }
- }
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|