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, 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.gwt.shared;
029
030import java.util.Objects;
031import java.util.Set;
032import java.util.TreeSet;
033
034import com.google.common.collect.ComparisonChain;
035import com.google.gwt.user.client.rpc.IsSerializable;
036
037/**
038 * Holds information about current container types/sizes for the purpose of filtering gallery search results (currently only for functions).
039 */
040public class CmsGalleryContainerInfo implements IsSerializable {
041
042    /**
043     * A single container type/width combination.
044     */
045    public static class Item implements IsSerializable, Comparable<Item> {
046
047        /** The container type. */
048        private String m_type;
049
050        /** The container width. */
051        private int m_width;
052
053        /**
054         * Creates a new instance.
055         *
056         * @param type the container type
057         * @param width the container width
058         */
059        public Item(String type, int width) {
060
061            super();
062            m_type = type;
063            m_width = width;
064        }
065
066        /**
067         * Hidden default constructor for serialization
068         */
069        protected Item() {
070
071            // do nothing
072        }
073
074        /**
075         * @see java.lang.Comparable#compareTo(java.lang.Object)
076         */
077        public int compareTo(Item other) {
078
079            return ComparisonChain.start().compare(m_type, other.m_type).compare(m_width, other.m_width).result();
080        }
081
082        /**
083         * @see java.lang.Object#equals(java.lang.Object)
084         */
085        @Override
086        public boolean equals(Object obj) {
087
088            if (this == obj) {
089                return true;
090            }
091            if (obj == null) {
092                return false;
093            }
094            if (getClass() != obj.getClass()) {
095                return false;
096            }
097            Item other = (Item)obj;
098            return Objects.equals(m_type, other.m_type) && (m_width == other.m_width);
099        }
100
101        /**
102         * Gets the container type.
103         *
104         * @return the container type
105         */
106        public String getType() {
107
108            return m_type;
109        }
110
111        /**
112         * Gets the container width.
113         *
114         * @return the container width
115         */
116        public int getWidth() {
117
118            return m_width;
119        }
120
121        /**
122         * @see java.lang.Object#hashCode()
123         */
124        @Override
125        public int hashCode() {
126
127            return Objects.hash(m_type, Integer.valueOf(m_width));
128        }
129
130        /**
131         * @see java.lang.Object#toString()
132         */
133        @Override
134        public String toString() {
135
136            return "[type=" + m_type + ", width=" + m_width + "]";
137        }
138    }
139
140    /** The set of type/width combinations of the page. */
141    private TreeSet<Item> m_items;
142
143    /**
144     * Creates a new instance.
145     *
146     * @param items the set of type/width combinations of the page
147     */
148    public CmsGalleryContainerInfo(Set<Item> items) {
149
150        super();
151        m_items = new TreeSet<>(items);
152    }
153
154    /**
155     * Hidden default constructor for serialization.
156     */
157    protected CmsGalleryContainerInfo() {}
158
159    /**
160     * Gets the type/width combinations of the page.
161     *
162     * @return the type/width combinations
163     */
164    public TreeSet<Item> getItems() {
165
166        return m_items;
167    }
168
169    /**
170     * @see java.lang.Object#toString()
171     */
172    @Override
173    public String toString() {
174
175        return "ContainerInfo[" + m_items + "]";
176    }
177
178}