01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.uilib.list;
16:
17: import java.util.Iterator;
18: import java.util.Map;
19: import java.util.TreeMap;
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22:
23: public class MultiOrderHelper {
24: private static final Log log = LogFactory
25: .getLog(MultiOrderHelper.class);
26:
27: public static OrderInfo getOrderInfo(Map orderInfoMap) {
28: Map fieldOrders = new TreeMap();
29:
30: for (Iterator i = orderInfoMap.entrySet().iterator(); i
31: .hasNext();) {
32: Map.Entry entry = (Map.Entry) i.next();
33: String column = (String) entry.getKey();
34: long value = Long.parseLong(entry.getValue().toString());
35: if (value != 0) {
36: boolean ascending = value > 0;
37: Long priority = new Long(Math.abs(value));
38: if (log.isDebugEnabled()) {
39: log.debug("Ordered column \"" + column
40: + "\", priority: " + priority + ", "
41: + (ascending ? "asc" : "desc"));
42: }
43:
44: OrderInfoField orderInfoField = new OrderInfoField(
45: column, ascending);
46: fieldOrders.put(priority, orderInfoField);
47: }
48: }
49:
50: OrderInfo orderInfo = new OrderInfo();
51: for (Iterator i = fieldOrders.values().iterator(); i.hasNext();) {
52: OrderInfoField orderInfoField = (OrderInfoField) i.next();
53: if (log.isDebugEnabled()) {
54: log.debug("Column order \""
55: + orderInfoField.getId()
56: + "\", "
57: + (orderInfoField.isAscending() ? "asc"
58: : "desc"));
59: }
60: orderInfo.addField(orderInfoField);
61: }
62: return orderInfo;
63: }
64: }
|