1+ /**
2+ *
3+ * Copyright (c) 2006-2016, Emil Forslund. All Rights Reserved.
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License"); You may not
6+ * use this file except in compliance with the License. You may obtain a copy of
7+ * the License at:
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+ * License for the specific language governing permissions and limitations under
15+ * the License.
16+ */
17+ package com .github .pyknic .bigarray ;
18+
19+ import com .github .pyknic .bigarray .internal .booleans .BooleanImmutableArrayBuilder ;
20+
21+ /**
22+ * An immutable boolean array that can hold a very large number of elements.
23+ * Implementations of this interface may or may not be backed by a direct buffer
24+ * depending on the size and how the data contained is structured.
25+ * <p>
26+ * To create a new instance of this interface, use the builder pattern initiated
27+ * with the {@link #builder()} method. The actual implementation that is used
28+ * will depend on the data that is passed to the builder. After the instance has
29+ * been built, it will be immutable.
30+ *
31+ * @author Emil Forslund
32+ * @since 1.0.1
33+ */
34+ public interface BooleanImmutableArray {
35+
36+ /**
37+ * Returns the value located at the specified index in the array. If the
38+ * index is outside the bounds of the array, the behavior is unspecified.
39+ *
40+ * @param index the index
41+ * @return the value at that index
42+ */
43+ boolean getAsBoolean (long index );
44+
45+ /**
46+ * Returns the length of the array (the number of booleans that can safely
47+ * be retrieved using the {@link #getAsBoolean(long)} method).
48+ *
49+ * @return the length
50+ */
51+ long length ();
52+
53+ /**
54+ * Creates a new builder. The builder guarantees that appended values will
55+ * be stored in the same order as they were inserted, but the actual size of
56+ * the array and how it is backed will be determined when the
57+ * {@link Builder#build()} method is finally invoked.
58+ * <p>
59+ * The builder should not be used after the {@link Builder#build()}-method
60+ * has been called.
61+ *
62+ * @return a new builder
63+ */
64+ static Builder builder () {
65+ return new BooleanImmutableArrayBuilder ();
66+ }
67+
68+ /**
69+ * A builder for a {@link BooleanImmutableArray}. The builder can be
70+ * appended with values using the {@link #append(boolean)}-method until it
71+ * is finalized using the {@link #build()}-method. The backing
72+ * implementation will be decided once the array is built.
73+ * <p>
74+ * The implementation of {@code Builder} is intended to handle a very large
75+ * amount of booleans as well as a very small amount.
76+ */
77+ interface Builder {
78+
79+ /**
80+ * Append an value to the builder.
81+ *
82+ * @param value the value to append
83+ * @return a reference to this builder
84+ */
85+ BooleanImmutableArray .Builder append (boolean value );
86+
87+ /**
88+ * Builds the array. After this method has been called, the builder
89+ * should be discarded. The returned array is immutable.
90+ *
91+ * @return the built array
92+ */
93+ BooleanImmutableArray build ();
94+
95+ }
96+ }
0 commit comments