hps-java/src/main/java/org/lcsim/hps/users/phansson
diff -N TestSort.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TestSort.java 20 Apr 2013 01:05:08 -0000 1.1
@@ -0,0 +1,79 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.lcsim.hps.users.phansson;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ *
+ * @author phansson
+ */
+public class TestSort {
+
+ public static class CmpClass implements Comparable<CmpClass> {
+ private int _val;
+ public CmpClass(int i) {
+ _val = i;
+ }
+ public void set(int i) {
+ _val = i;
+ }
+ public int get() {
+ return _val;
+ }
+
+ @Override
+ public int compareTo(CmpClass o) {
+ return o._val-_val;
+ }
+
+ }
+
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+
+ List<CmpClass> list = new ArrayList<>();
+ list.add(new CmpClass(1));
+ list.add(new CmpClass(2));
+ list.add(new CmpClass(3));
+
+ System.out.printf("list:\n");
+
+ for (CmpClass c : list) {
+ System.out.printf("%d\n",c._val);
+ }
+
+ Collections.sort(list);
+
+ System.out.printf("after sort:\n");
+
+ for (CmpClass c : list) {
+ System.out.printf("%d\n",c._val);
+ }
+
+ list.get(1).set(4);
+
+ System.out.printf("list:\n");
+
+ for (CmpClass c : list) {
+ System.out.printf("%d\n",c._val);
+ }
+
+ Collections.sort(list);
+
+ System.out.printf("after sort:\n");
+
+ for (CmpClass c : list) {
+ System.out.printf("%d\n",c._val);
+ }
+
+
+ }
+}