Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jtemporal/util/EmptySet.java


1   /*
2      Copyright (C) 2002 Thomas A Beck (http://thomas.beck.name)
3   
4      This library is free software; you can redistribute it and/or
5      modify it under the terms of the GNU Lesser General Public
6      License as published by the Free Software Foundation; either
7      version 2.1 of the License, or (at your option) any later version.
8   
9      This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     Lesser General Public License for more details.
13  
14     You should have received a copy of the GNU Lesser General Public
15     License along with this library; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA    */
17  
18  package jtemporal.util;
19  
20  import java.util.*;
21  import java.io.InvalidObjectException;
22  import java.io.Serializable;
23  
24  /**
25   * Immutable empty read-only set (singleton).  <BR>
26   * <B>For methods description, see java.util.Set</B>
27   * @author Thomas Beck
28   * @version $Id$
29   */
30  public class EmptySet extends AbstractSet implements Serializable {
31  
32    private static final EmptySet INSTANCE = new EmptySet();
33    private static final long serialVersionUID = 1896628674035L;
34  
35    static public EmptySet getInstance() {
36      return INSTANCE;
37    }
38  
39    static final private String IMMUTABLE_ERROR = "This EmptySet is immutable";
40    static private Object[] emptyArray = new Object[0];
41  
42    private EmptySet() {
43    }
44  
45    /**
46     * Resolves instances being deserialized to the predefined constant.
47     */
48    private Object readResolve() throws InvalidObjectException {
49      return INSTANCE;
50    }
51  
52    public boolean contains(Object o) {
53      return false;
54    }
55    public boolean remove(Object o) {
56      throw new UnsupportedOperationException(IMMUTABLE_ERROR);
57    }
58    public boolean isEmpty() {
59      return true;
60    }
61    public boolean add(Object o) {
62      throw new UnsupportedOperationException(IMMUTABLE_ERROR);
63    }
64    public int size() {
65      return 0;
66    }
67    public boolean containsAll(Collection parm1) {
68      return false;
69    }
70    public Object[] toArray() {
71      return this.emptyArray;
72    }
73    public void clear() {
74      throw new UnsupportedOperationException(IMMUTABLE_ERROR);
75    }
76    public Iterator iterator() {
77      return EmptyIterator.getInstance();
78    }
79    public boolean addAll(Collection parm1) {
80      throw new UnsupportedOperationException(IMMUTABLE_ERROR);
81    }
82  }