Ver código fonte

Added all Comparator for sorting HolonElementList

Toni Schneider 7 anos atrás
pai
commit
c11f0151f7

+ 1 - 1
src/ElementComparator/ElemCompOnEleName.java

@@ -9,7 +9,7 @@ public class ElemCompOnEleName extends ElementComparator {
 
 		String eleNameA = a.getEleName();
 		String eleNameB = b.getEleName();
-		
+
 		return eleNameA.compareTo(eleNameB);
 
 	}

+ 19 - 0
src/ElementComparator/ElemCompOnFlexible.java

@@ -0,0 +1,19 @@
+package ElementComparator;
+
+import classes.HolonElement;
+
+public class ElemCompOnFlexible extends ElementComparator {
+	
+	@Override
+	public int compare(HolonElement a, HolonElement b) {
+
+		float flexA = a.getFlexibleEnergyAvailablePerElement();
+		float flexB = b.getFlexibleEnergyAvailablePerElement();
+		if (flexA < flexB)
+			return -1;
+		if (flexA > flexB)
+			return 1;
+		return 0;
+
+	}
+}

+ 20 - 0
src/ElementComparator/ElemCompOnIsActivated.java

@@ -0,0 +1,20 @@
+package ElementComparator;
+
+import classes.HolonElement;
+
+public class ElemCompOnIsActivated  extends ElementComparator {
+	
+	@Override
+	public int compare(HolonElement a, HolonElement b) {
+
+		boolean ifA = a.isActive();
+		boolean ifB = b.isActive();
+		if (ifA&&!ifB)
+			return -1;
+		if (!ifA && ifB)
+			return 1;
+		return 0;
+
+	}
+
+}

+ 18 - 0
src/ElementComparator/ElemCompOnIsFlexible.java

@@ -0,0 +1,18 @@
+package ElementComparator;
+
+import classes.HolonElement;
+
+public class ElemCompOnIsFlexible extends ElementComparator{
+
+	@Override
+	public int compare(HolonElement a, HolonElement b) {
+		boolean ifA = a.isFlexible();
+		boolean ifB = b.isFlexible();
+		if (ifA&&!ifB)
+			return -1;
+		if (!ifA && ifB)
+			return 1;
+		return 0;
+	}
+
+}

+ 16 - 0
src/ElementComparator/ElemCompOnObj.java

@@ -0,0 +1,16 @@
+package ElementComparator;
+
+import classes.HolonElement;
+
+public class ElemCompOnObj extends ElementComparator {
+
+	@Override
+	public int compare(HolonElement a, HolonElement b) {
+
+		String objNameA = a.getObjName();
+		String objNameB = b.getObjName();
+		return objNameA.compareTo(objNameB);
+
+	}
+
+}

+ 20 - 0
src/ElementComparator/ElemCompOnQuantity.java

@@ -0,0 +1,20 @@
+package ElementComparator;
+
+import classes.HolonElement;
+
+public class ElemCompOnQuantity extends ElementComparator {
+
+	@Override
+	public int compare(HolonElement a, HolonElement b) {
+
+		float amountA = a.getAmount();
+		float amountB = b.getAmount();
+		if (amountA < amountB)
+			return -1;
+		if (amountA > amountB)
+			return 1;
+		return 0;
+
+	}
+
+}