package test;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.springframework.data.document.mongodb.MongoOperations;
import org.springframework.data.document.mongodb.MongoTemplate;
import org.springframework.data.document.mongodb.query.Query;
import util.DateTime;
import util.SortUtil;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
import com.mongodb.MongoOptions;
import com.mongodb.ServerAddress;
import data.table.log.LCharge;
public class Student implements Cloneable {
private int age;
private String name;
private float mark;
private double score;
private boolean isonline;
private Long time;
private Object a;
@Override
protected Object clone() throws CloneNotSupportedException {
// TODO Auto-generated method stub
return (Student) super.clone();
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getMark() {
return mark;
}
public void setMark(float mark) {
this.mark = mark;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public boolean isIsonline() {
return isonline;
}
public void setIsonline(boolean isonline) {
this.isonline = isonline;
}
public Long getTime() {
return time;
}
public void setTime(long time) {
a = time;
this.time = time;
}
public static Comparator<Object> getComp() {
return comp;
}
public static void setComp(Comparator<Object> comp) {
Student.comp = comp;
}
@Override
public String toString() {
return "Student [age=" + age + ", name=" + name + ", mark=" + mark
+ ", score=" + score + ", isonline=" + isonline + "]";
}
public Student(String name, int age, float mark, double score,
boolean isonline) {
this.age = age;
this.name = name;
this.mark = mark;
this.score = score;
this.isonline = isonline;
}
public Student() {
}
public Map<Integer, Integer> mapFun() {
Map<Integer, Integer> mp = new HashMap<Integer, Integer>();
mp.put(1, 1);
return mp;
}
@SuppressWarnings("unchecked")
public static <T, F> Map<T, F> getMap(Object... args) {
Map<T, F> map = new HashMap<T, F>();
for (int i = 0; i < args.length; i += 2) {
map.put((T) args[i], (F) args[i + 1]);
}
return map;
}
private static Comparator<Object> comp = new Comparator<Object>() {
public int compare(Object o1, Object o2) {
int a1 = ((Student) o1).getAge();
int a2 = ((Student) o2).getAge();
if (a1 < a2) {
return 1;
} else {
return 0;
}
}
};
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Map<Long, Integer> sort(Map<Long, Integer> map) {
List<Integer> list = new LinkedList(map.entrySet());
Collections.sort(list, new Comparator() {
public int compare(Object o1, Object o2) {
int t1 = ((Map.Entry<Integer, Integer>) o1).getValue();
int t2 = ((Map.Entry<Integer, Integer>) o2).getValue();
return t1 - t2 > 0 ? -1 : 1;
}
});
Map<Long, Integer> result = new LinkedHashMap();
for (Iterator it = list.iterator(); it.hasNext();) {
Map.Entry<Long, Integer> entry = (Map.Entry<Long, Integer>) it
.next();
result.put(entry.getKey(), entry.getValue());
}
return result;
}
/**
* @param args
* @throws MongoException
* @throws UnknownHostException
*/
public static void main(String[] args) throws Exception {
List<Object> st = new ArrayList<Object>();
Student sd1 = new Student("chen1", 7, 7f, 1.3, true);
Student sd2 = new Student("chen2", 4, 4f, 2.2, true);
Student sd3 = new Student("chen3", 5, 5f, 3.2, true);
Student sd4 = new Student("chen4", 3, 3f, 4.3, true);
Student sd5 = new Student("chen5", 2, 2f, 5.3, true);
Student sd6 = new Student("chen6", 7, 7f, 6.3, false);
Student sd7 = new Student("chen7", 7, 6f, 6.3, false);
Student sd8 = new Student("chen8", 8, 8f, 9.3, false);
sd8.setTime(12l);
st.add(sd1);
st.add(sd2);
st.add(sd3);
st.add(sd4);
st.add(sd5);
st.add(sd6);
st.add(sd7);
st.add(sd8);
SortUtil.sort(st, "isIsonline#-1", "getScore#1");
for(Object o:st){
System.out.println(o);
}
}
}
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.springframework.data.document.mongodb.MongoOperations;
import org.springframework.data.document.mongodb.MongoTemplate;
import org.springframework.data.document.mongodb.query.Query;
import util.DateTime;
import util.SortUtil;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
import com.mongodb.MongoOptions;
import com.mongodb.ServerAddress;
import data.table.log.LCharge;
public class Student implements Cloneable {
private int age;
private String name;
private float mark;
private double score;
private boolean isonline;
private Long time;
private Object a;
@Override
protected Object clone() throws CloneNotSupportedException {
// TODO Auto-generated method stub
return (Student) super.clone();
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getMark() {
return mark;
}
public void setMark(float mark) {
this.mark = mark;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public boolean isIsonline() {
return isonline;
}
public void setIsonline(boolean isonline) {
this.isonline = isonline;
}
public Long getTime() {
return time;
}
public void setTime(long time) {
a = time;
this.time = time;
}
public static Comparator<Object> getComp() {
return comp;
}
public static void setComp(Comparator<Object> comp) {
Student.comp = comp;
}
@Override
public String toString() {
return "Student [age=" + age + ", name=" + name + ", mark=" + mark
+ ", score=" + score + ", isonline=" + isonline + "]";
}
public Student(String name, int age, float mark, double score,
boolean isonline) {
this.age = age;
this.name = name;
this.mark = mark;
this.score = score;
this.isonline = isonline;
}
public Student() {
}
public Map<Integer, Integer> mapFun() {
Map<Integer, Integer> mp = new HashMap<Integer, Integer>();
mp.put(1, 1);
return mp;
}
@SuppressWarnings("unchecked")
public static <T, F> Map<T, F> getMap(Object... args) {
Map<T, F> map = new HashMap<T, F>();
for (int i = 0; i < args.length; i += 2) {
map.put((T) args[i], (F) args[i + 1]);
}
return map;
}
private static Comparator<Object> comp = new Comparator<Object>() {
public int compare(Object o1, Object o2) {
int a1 = ((Student) o1).getAge();
int a2 = ((Student) o2).getAge();
if (a1 < a2) {
return 1;
} else {
return 0;
}
}
};
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Map<Long, Integer> sort(Map<Long, Integer> map) {
List<Integer> list = new LinkedList(map.entrySet());
Collections.sort(list, new Comparator() {
public int compare(Object o1, Object o2) {
int t1 = ((Map.Entry<Integer, Integer>) o1).getValue();
int t2 = ((Map.Entry<Integer, Integer>) o2).getValue();
return t1 - t2 > 0 ? -1 : 1;
}
});
Map<Long, Integer> result = new LinkedHashMap();
for (Iterator it = list.iterator(); it.hasNext();) {
Map.Entry<Long, Integer> entry = (Map.Entry<Long, Integer>) it
.next();
result.put(entry.getKey(), entry.getValue());
}
return result;
}
/**
* @param args
* @throws MongoException
* @throws UnknownHostException
*/
public static void main(String[] args) throws Exception {
List<Object> st = new ArrayList<Object>();
Student sd1 = new Student("chen1", 7, 7f, 1.3, true);
Student sd2 = new Student("chen2", 4, 4f, 2.2, true);
Student sd3 = new Student("chen3", 5, 5f, 3.2, true);
Student sd4 = new Student("chen4", 3, 3f, 4.3, true);
Student sd5 = new Student("chen5", 2, 2f, 5.3, true);
Student sd6 = new Student("chen6", 7, 7f, 6.3, false);
Student sd7 = new Student("chen7", 7, 6f, 6.3, false);
Student sd8 = new Student("chen8", 8, 8f, 9.3, false);
sd8.setTime(12l);
st.add(sd1);
st.add(sd2);
st.add(sd3);
st.add(sd4);
st.add(sd5);
st.add(sd6);
st.add(sd7);
st.add(sd8);
SortUtil.sort(st, "isIsonline#-1", "getScore#1");
for(Object o:st){
System.out.println(o);
}
}
}