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