1 package com.foxinmy.weixin4j.model.paging; 2 3 import java.io.Serializable; 4 import java.util.ArrayList; 5 import java.util.Arrays; 6 import java.util.LinkedHashMap; 7 import java.util.List; 8 import java.util.Map; 9 10 public class Sort implements Serializable { 11 12 private static final long serialVersionUID = -4298853295391613880L; 13 14 public static final Direction DEFAULT_DIRECTION = Direction.ASC; 15 private Map<Direction, List<String>> orders; 16 17 public Sort() { 18 } 19 20 public Sort(String... properties) { 21 this(DEFAULT_DIRECTION, properties); 22 } 23 24 public Sort(Direction direction, String... properties) { 25 this(direction, properties == null ? new ArrayList<String>() : Arrays 26 .asList(properties)); 27 } 28 29 public Sort(Direction direction, List<String> properties) { 30 if (properties == null || properties.isEmpty()) { 31 throw new IllegalArgumentException( 32 "You have to provide at least one property to sort by!"); 33 } 34 this.orders = new LinkedHashMap<Direction, List<String>>( 35 properties.size()); 36 this.orders.put(direction, properties); 37 } 38 39 public Map<Direction, List<String>> getOrders() { 40 return orders; 41 } 42 43 public boolean hasSort() { 44 return orders != null && !orders.isEmpty(); 45 } 46 47 public static enum Direction { 48 ASC, DESC; 49 } 50 51 @Override 52 public String toString() { 53 return "Sort [" + orders + "]"; 54 } 55 }