Skip to content

Commit 29166bd

Browse files
committed
Add support for floats, doubles and booleans
1 parent 141fe81 commit 29166bd

33 files changed

Lines changed: 1107 additions & 68 deletions

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<modelVersion>4.0.0</modelVersion>
2525
<groupId>com.github.pyknic</groupId>
2626
<artifactId>immutable-array</artifactId>
27-
<version>1.0.0</version>
27+
<version>1.0.1</version>
2828
<packaging>jar</packaging>
2929

3030
<name>Immutable Array</name>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
}

src/main/java/com/github/pyknic/bigarray/ByteImmutableArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package com.github.pyknic.bigarray;
1818

19-
import com.github.pyknic.bigarray.internal.ByteImmutableArrayBuilder;
19+
import com.github.pyknic.bigarray.internal.bytes.ByteImmutableArrayBuilder;
2020

2121
/**
2222
* An immutable byte array that can hold a very large number of elements.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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.doubles.DoubleImmutableArrayBuilder;
20+
21+
/**
22+
* An immutable double 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 DoubleImmutableArray {
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+
double getAsDouble(long index);
44+
45+
/**
46+
* Returns the length of the array (the number of doubles that can safely
47+
* be retrieved using the {@link #getAsDouble(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 DoubleImmutableArrayBuilder();
66+
}
67+
68+
/**
69+
* A builder for a {@link DoubleImmutableArray}. The builder can be appended
70+
* with values using the {@link #append(double)}-method until it is
71+
* finalized using the {@link #build()}-method. The backing implementation
72+
* 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 doubles 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+
DoubleImmutableArray.Builder append(double 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+
DoubleImmutableArray build();
94+
95+
}
96+
97+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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.floats.FloatImmutableArrayBuilder;
20+
21+
/**
22+
* An immutable float 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 FloatImmutableArray {
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+
float getAsFloat(long index);
44+
45+
/**
46+
* Returns the length of the array (the number of floats that can safely
47+
* be retrieved using the {@link #getAsFloat(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 FloatImmutableArrayBuilder();
66+
}
67+
68+
/**
69+
* A builder for a {@link FloatImmutableArray}. The builder can be appended
70+
* with values using the {@link #append(float)}-method until it is finalized
71+
* using the {@link #build()}-method. The backing implementation will be
72+
* decided once the array is built.
73+
* <p>
74+
* The implementation of {@code Builder} is intended to handle a very large
75+
* amount of floats 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+
FloatImmutableArray.Builder append(float 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+
FloatImmutableArray build();
94+
95+
}
96+
97+
}

src/main/java/com/github/pyknic/bigarray/IntImmutableArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package com.github.pyknic.bigarray;
1818

19-
import com.github.pyknic.bigarray.internal.IntImmutableArrayBuilder;
19+
import com.github.pyknic.bigarray.internal.ints.IntImmutableArrayBuilder;
2020

2121
/**
2222
* An immutable integer array that can hold a very large number of elements.

src/main/java/com/github/pyknic/bigarray/LongImmutableArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package com.github.pyknic.bigarray;
1818

19-
import com.github.pyknic.bigarray.internal.LongImmutableArrayBuilder;
19+
import com.github.pyknic.bigarray.internal.longs.LongImmutableArrayBuilder;
2020

2121
/**
2222
* An immutable long array that can hold a very large number of elements.

src/main/java/com/github/pyknic/bigarray/ShortImmutableArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package com.github.pyknic.bigarray;
1818

19-
import com.github.pyknic.bigarray.internal.ShortImmutableArrayBuilder;
19+
import com.github.pyknic.bigarray.internal.shorts.ShortImmutableArrayBuilder;
2020

2121
/**
2222
* An immutable short array that can hold a very large number of elements.

src/main/java/com/github/pyknic/bigarray/internal/EmptyImmutableArray.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
*/
1717
package com.github.pyknic.bigarray.internal;
1818

19+
import com.github.pyknic.bigarray.BooleanImmutableArray;
1920
import com.github.pyknic.bigarray.ByteImmutableArray;
21+
import com.github.pyknic.bigarray.DoubleImmutableArray;
22+
import com.github.pyknic.bigarray.FloatImmutableArray;
2023
import com.github.pyknic.bigarray.IntImmutableArray;
2124
import com.github.pyknic.bigarray.LongImmutableArray;
2225
import com.github.pyknic.bigarray.ShortImmutableArray;
@@ -26,13 +29,16 @@
2629
* @author Emil Forslund
2730
* @since 1.0.0
2831
*/
29-
final class EmptyImmutableArray
32+
public final class EmptyImmutableArray
3033
implements LongImmutableArray,
3134
IntImmutableArray,
3235
ShortImmutableArray,
33-
ByteImmutableArray {
36+
ByteImmutableArray,
37+
FloatImmutableArray,
38+
DoubleImmutableArray,
39+
BooleanImmutableArray {
3440

35-
EmptyImmutableArray() {}
41+
public EmptyImmutableArray() {}
3642

3743
@Override
3844
public long getAsLong(long index) {
@@ -53,6 +59,21 @@ public short getAsShort(long index) {
5359
public byte getAsByte(long index) {
5460
throw new ArrayIndexOutOfBoundsException();
5561
}
62+
63+
@Override
64+
public float getAsFloat(long index) {
65+
throw new ArrayIndexOutOfBoundsException();
66+
}
67+
68+
@Override
69+
public double getAsDouble(long index) {
70+
throw new ArrayIndexOutOfBoundsException();
71+
}
72+
73+
@Override
74+
public boolean getAsBoolean(long index) {
75+
throw new ArrayIndexOutOfBoundsException();
76+
}
5677

5778
@Override
5879
public long length() {

0 commit comments

Comments
 (0)