1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.graph.property.basic;
25
26 import java.util.Iterator;
27 import java.util.NoSuchElementException;
28 import net.jcip.annotations.Immutable;
29 import org.modeshape.graph.property.Name;
30
31 /**
32 * An immutable version of a property that has no values. This is done for efficiency of the in-memory representation, since many
33 * properties will have just a single value, while others will have multiple values.
34 */
35 @Immutable
36 public class BasicEmptyProperty extends BasicProperty {
37
38 private static final Iterator<Object> SHARED_ITERATOR = new EmptyIterator<Object>();
39
40 /**
41 * Create a property with no values.
42 *
43 * @param name the property name
44 */
45 public BasicEmptyProperty( Name name ) {
46 super(name);
47 }
48
49 /**
50 * {@inheritDoc}
51 */
52 public boolean isEmpty() {
53 return true;
54 }
55
56 /**
57 * {@inheritDoc}
58 */
59 public boolean isMultiple() {
60 return false;
61 }
62
63 /**
64 * {@inheritDoc}
65 */
66 public boolean isSingle() {
67 return false;
68 }
69
70 /**
71 * {@inheritDoc}
72 */
73 public int size() {
74 return 0;
75 }
76
77 /**
78 * {@inheritDoc}
79 *
80 * @see org.modeshape.graph.property.Property#getFirstValue()
81 */
82 public Object getFirstValue() {
83 return null;
84 }
85
86 /**
87 * {@inheritDoc}
88 */
89 public Iterator<Object> iterator() {
90 return SHARED_ITERATOR;
91 }
92
93 protected static class EmptyIterator<T> implements Iterator<T> {
94
95 protected EmptyIterator() {
96 }
97
98 /**
99 * {@inheritDoc}
100 */
101 public boolean hasNext() {
102 return false;
103 }
104
105 /**
106 * {@inheritDoc}
107 */
108 public T next() {
109 throw new NoSuchElementException();
110 }
111
112 /**
113 * {@inheritDoc}
114 */
115 public void remove() {
116 throw new UnsupportedOperationException();
117 }
118
119 }
120
121 }