001    /****************************************************************
002     * Licensed to the Apache Software Foundation (ASF) under one   *
003     * or more contributor license agreements.  See the NOTICE file *
004     * distributed with this work for additional information        *
005     * regarding copyright ownership.  The ASF licenses this file   *
006     * to you under the Apache License, Version 2.0 (the            *
007     * "License"); you may not use this file except in compliance   *
008     * with the License.  You may obtain a copy of the License at   *
009     *                                                              *
010     *   http://www.apache.org/licenses/LICENSE-2.0                 *
011     *                                                              *
012     * Unless required by applicable law or agreed to in writing,   *
013     * software distributed under the License is distributed on an  *
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015     * KIND, either express or implied.  See the License for the    *
016     * specific language governing permissions and limitations      *
017     * under the License.                                           *
018     ****************************************************************/
019    
020    package org.apache.hupa.shared.data;
021    
022    import java.io.Serializable;
023    import java.util.ArrayList;
024    
025    /**
026     * IMAPFolder
027     * 
028     */
029    public class IMAPFolder implements Serializable {
030    
031        /**
032         * 
033         */
034        private static final long serialVersionUID = 2084188092060266479L;
035    
036        private ArrayList<IMAPFolder> childs = new ArrayList<IMAPFolder>();
037        private String fullName;
038        private String delimiter;
039        private int msgCount;
040        private int unseenMsgCount;
041        private boolean subscribed = false;
042    
043        public IMAPFolder() {
044        }
045    
046        public IMAPFolder(String fullName) {
047            setFullName(fullName);
048        }
049    
050        public void setSubscribed(boolean subscribed) {
051            this.subscribed = subscribed;
052        }
053        
054        public boolean getSubscribed() {
055            return subscribed;
056        }
057        
058        
059        /**
060         * Get the name of the folder
061         * 
062         * @return name
063         */
064        public String getName() {
065            if (delimiter != null) {
066                String fParts[] = getFullName().split("\\" + delimiter);
067                if (fParts != null && fParts.length > 0) {
068                    return fParts[fParts.length - 1];
069                }
070            }
071            return fullName;
072        }
073    
074        /**
075         * Set the child folders 
076         * 
077         * @param childs
078         */
079        public void setChildIMAPFolders(ArrayList<IMAPFolder> childs) {
080            this.childs = childs;
081        }
082    
083        /**
084         * Return the childs of this folder
085         * 
086         * @return childs
087         */
088        public ArrayList<IMAPFolder> getChildIMAPFolders() {
089            return childs;
090        }
091    
092        /**
093         * Return the full name of the folder. This include the full path
094         * @return Full name of the folder
095         */
096        public String getFullName() {
097            return fullName;
098        }
099    
100        /**
101         * Set the full name of the folder
102         * 
103         * @param fullName
104         */
105        public void setFullName(String fullName) {
106            this.fullName = fullName;
107        }
108    
109        /**
110         * Set the delimiter which is used to seperate folders
111         * 
112         * @param delimiter
113         */
114        public void setDelimiter(String delimiter) {
115            this.delimiter = delimiter;
116        }
117    
118        /**
119         * Return the delimiter
120         * 
121         * @return delimiter
122         */
123        public String getDelimiter() {
124            return delimiter;
125        }
126    
127        /**
128         * Return the total message count of the messages that exists within this folder
129         * 
130         * @return msgCount
131         */
132        public int getMessageCount() {
133            return msgCount;
134        }
135    
136        /**
137         * Set total message count
138         * 
139         * @param msgCount
140         */
141        public void setMessageCount(int msgCount) {
142            this.msgCount = msgCount;
143        }
144    
145        /**
146         * Set the count of all unseen messages within this folder
147         * 
148         * @param unseenMsgCount
149         */
150        public void setUnseenMessageCount(int unseenMsgCount) {
151            this.unseenMsgCount = unseenMsgCount;
152        }
153    
154        /**
155         * Return the unseen message count
156         * 
157         * @return unseenMsgCount
158         */
159        public int getUnseeMessageCount() {
160            return unseenMsgCount;
161        }
162    
163        @Override
164        public String toString() {
165            return getFullName();
166        }
167        
168        @Override
169        public boolean equals(Object o) {
170            if (o instanceof IMAPFolder) {
171                if (((IMAPFolder) o).getFullName().equals(getFullName())) {
172                    return true;
173                }
174            }
175            return false;
176        }
177    
178        @Override
179        public int hashCode() {
180            return getFullName().hashCode();
181        }
182        
183    }