001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListOrderEnum.java,v $
003: * Date : $Date: 2008-02-27 12:05:28 $
004: * Version: $Revision: 1.11 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.list;
033:
034: import org.opencms.main.CmsIllegalArgumentException;
035:
036: import java.util.Arrays;
037: import java.util.Collections;
038: import java.util.Iterator;
039: import java.util.List;
040:
041: /**
042: * Wrapper class for
043: * the different types of table cell horizontal alignments.<p>
044: *
045: * The possibles values are:<br>
046: * <ul>
047: * <li>AscendingOrder</li>
048: * <li>DescendingOrder</li>
049: * <li>NoneOrder</li>
050: * </ul>
051: * <p>
052: *
053: * @author Michael Moossen
054: *
055: * @version $Revision: 1.11 $
056: *
057: * @since 6.0.0
058: */
059: public final class CmsListOrderEnum {
060:
061: /** Constant for ascending ordering. */
062: public static final CmsListOrderEnum ORDER_ASCENDING = new CmsListOrderEnum(
063: "asc");
064:
065: /** Constant for descending ordering. */
066: public static final CmsListOrderEnum ORDER_DESCENDING = new CmsListOrderEnum(
067: "des");
068:
069: /** Constant for none ordering. */
070: public static final CmsListOrderEnum ORDER_NONE = new CmsListOrderEnum(
071: "none");
072:
073: /** Array constant for column sorting. */
074: private static final CmsListOrderEnum[] VALUE_ARRAY = {
075: ORDER_ASCENDING, ORDER_DESCENDING, ORDER_NONE };
076:
077: /** List of ordering constants. */
078: public static final List VALUES = Collections
079: .unmodifiableList(Arrays.asList(VALUE_ARRAY));
080:
081: /** Internal representation. */
082: private final String m_order;
083:
084: /**
085: * Private constructor.<p>
086: *
087: * @param order internal representation
088: */
089: private CmsListOrderEnum(String order) {
090:
091: m_order = order;
092: }
093:
094: /**
095: * Parses an string into an element of this enumeration.<p>
096: *
097: * @param value the align to parse
098: *
099: * @return the enumeration element
100: *
101: * @throws CmsIllegalArgumentException if the given value could not be matched against a
102: * <code>CmsListColumnAlignEnum</code> type.
103: */
104: public static CmsListOrderEnum valueOf(String value)
105: throws CmsIllegalArgumentException {
106:
107: Iterator iter = VALUES.iterator();
108: while (iter.hasNext()) {
109: CmsListOrderEnum target = (CmsListOrderEnum) iter.next();
110: if (value.equals(target.getOrder())) {
111: return target;
112: }
113: }
114: throw new CmsIllegalArgumentException(Messages.get().container(
115: Messages.ERR_LIST_ENUM_PARSE_2, new Integer(value),
116: CmsListOrderEnum.class.getName()));
117: }
118:
119: /**
120: * Returns the order string.<p>
121: *
122: * @return the order string
123: */
124: public String getOrder() {
125:
126: return m_order;
127: }
128:
129: /**
130: * @see java.lang.Object#toString()
131: */
132: public String toString() {
133:
134: return m_order;
135: }
136:
137: }
|