Skip to content

Commit e760efa

Browse files
authored
Merge pull request #43 from JavaSaBr/extend-api
Extend API, part 1
2 parents 0ced55b + 8a674ce commit e760efa

37 files changed

+994
-172
lines changed

JavaSabr-codestyle.xml

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
<code_scheme name="JavaSabr" version="173">
2+
<option name="AUTODETECT_INDENTS" value="false" />
3+
<option name="SOFT_MARGINS" value="100" />
4+
<JavaCodeStyleSettings>
5+
<option name="VISIBILITY" value="private" />
6+
<option name="REPLACE_INSTANCEOF_AND_CAST" value="true" />
7+
<option name="ANNOTATION_PARAMETER_WRAP" value="5" />
8+
<option name="ALIGN_MULTILINE_ANNOTATION_PARAMETERS" value="true" />
9+
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="9999" />
10+
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="9999" />
11+
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
12+
<value />
13+
</option>
14+
<option name="IMPORT_LAYOUT_TABLE">
15+
<value>
16+
<package name="" withSubpackages="true" static="false" module="true" />
17+
<package name="" withSubpackages="true" static="true" />
18+
<emptyLine />
19+
<package name="" withSubpackages="true" static="false" />
20+
</value>
21+
</option>
22+
<option name="RECORD_COMPONENTS_WRAP" value="5" />
23+
<option name="NEW_LINE_AFTER_LPAREN_IN_RECORD_HEADER" value="true" />
24+
<option name="JD_ALIGN_PARAM_COMMENTS" value="false" />
25+
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false" />
26+
<REPEAT_ANNOTATIONS>
27+
<ANNO name="org.jspecify.annotations.NonNull" />
28+
<ANNO name="org.jspecify.annotations.Nullable" />
29+
<ANNO name="org.junit.jupiter.api.AfterEach" />
30+
<ANNO name="org.junit.jupiter.api.BeforeEach" />
31+
</REPEAT_ANNOTATIONS>
32+
</JavaCodeStyleSettings>
33+
<TypeScriptCodeStyleSettings version="0">
34+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
35+
<option name="USE_DOUBLE_QUOTES" value="false" />
36+
<option name="FORCE_QUOTE_STYlE" value="true" />
37+
</TypeScriptCodeStyleSettings>
38+
<editorconfig>
39+
<option name="ENABLED" value="false" />
40+
</editorconfig>
41+
<codeStyleSettings language="Groovy">
42+
<indentOptions>
43+
<option name="INDENT_SIZE" value="2" />
44+
<option name="CONTINUATION_INDENT_SIZE" value="4" />
45+
<option name="LABEL_INDENT_SIZE" value="4" />
46+
</indentOptions>
47+
</codeStyleSettings>
48+
<codeStyleSettings language="HTML">
49+
<indentOptions>
50+
<option name="INDENT_SIZE" value="2" />
51+
<option name="CONTINUATION_INDENT_SIZE" value="4" />
52+
</indentOptions>
53+
</codeStyleSettings>
54+
<codeStyleSettings language="JAVA">
55+
<option name="KEEP_LINE_BREAKS" value="false" />
56+
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
57+
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
58+
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
59+
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
60+
<option name="KEEP_BLANK_LINES_BETWEEN_PACKAGE_DECLARATION_AND_HEADER" value="1" />
61+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
62+
<option name="ALIGN_MULTILINE_ASSIGNMENT" value="true" />
63+
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
64+
<option name="ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION" value="true" />
65+
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
66+
<option name="CALL_PARAMETERS_WRAP" value="5" />
67+
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
68+
<option name="METHOD_PARAMETERS_WRAP" value="5" />
69+
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
70+
<option name="EXTENDS_LIST_WRAP" value="1" />
71+
<option name="THROWS_LIST_WRAP" value="1" />
72+
<option name="THROWS_KEYWORD_WRAP" value="1" />
73+
<option name="METHOD_CALL_CHAIN_WRAP" value="2" />
74+
<option name="WRAP_FIRST_METHOD_IN_CALL_CHAIN" value="true" />
75+
<option name="BINARY_OPERATION_WRAP" value="1" />
76+
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
77+
<option name="TERNARY_OPERATION_WRAP" value="5" />
78+
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
79+
<option name="KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE" value="true" />
80+
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true" />
81+
<option name="ARRAY_INITIALIZER_WRAP" value="2" />
82+
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
83+
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
84+
<option name="WRAP_COMMENTS" value="true" />
85+
<option name="IF_BRACE_FORCE" value="3" />
86+
<option name="WRAP_LONG_LINES" value="true" />
87+
<option name="PARAMETER_ANNOTATION_WRAP" value="5" />
88+
<option name="ENUM_CONSTANTS_WRAP" value="2" />
89+
<indentOptions>
90+
<option name="INDENT_SIZE" value="2" />
91+
<option name="CONTINUATION_INDENT_SIZE" value="4" />
92+
</indentOptions>
93+
<arrangement>
94+
<rules>
95+
<section>
96+
<rule>
97+
<match>
98+
<AND>
99+
<FIELD>true</FIELD>
100+
<FINAL>true</FINAL>
101+
<STATIC>true</STATIC>
102+
</AND>
103+
</match>
104+
<order>BY_NAME</order>
105+
</rule>
106+
</section>
107+
<section>
108+
<rule>
109+
<match>
110+
<AND>
111+
<FIELD>true</FIELD>
112+
<STATIC>true</STATIC>
113+
</AND>
114+
</match>
115+
<order>BY_NAME</order>
116+
</rule>
117+
</section>
118+
<section>
119+
<rule>
120+
<match>
121+
<AND>
122+
<INITIALIZER_BLOCK>true</INITIALIZER_BLOCK>
123+
<STATIC>true</STATIC>
124+
</AND>
125+
</match>
126+
</rule>
127+
</section>
128+
<section>
129+
<rule>
130+
<match>
131+
<AND>
132+
<METHOD>true</METHOD>
133+
<STATIC>true</STATIC>
134+
</AND>
135+
</match>
136+
</rule>
137+
</section>
138+
<section>
139+
<rule>
140+
<match>
141+
<FIELD>true</FIELD>
142+
</match>
143+
</rule>
144+
</section>
145+
<section>
146+
<rule>
147+
<match>
148+
<INITIALIZER_BLOCK>true</INITIALIZER_BLOCK>
149+
</match>
150+
</rule>
151+
</section>
152+
<section>
153+
<rule>
154+
<match>
155+
<CONSTRUCTOR>true</CONSTRUCTOR>
156+
</match>
157+
</rule>
158+
</section>
159+
<section>
160+
<rule>
161+
<match>
162+
<METHOD>true</METHOD>
163+
</match>
164+
</rule>
165+
</section>
166+
<section>
167+
<rule>
168+
<match>
169+
<ENUM>true</ENUM>
170+
</match>
171+
</rule>
172+
</section>
173+
<section>
174+
<rule>
175+
<match>
176+
<INTERFACE>true</INTERFACE>
177+
</match>
178+
</rule>
179+
</section>
180+
<section>
181+
<rule>
182+
<match>
183+
<AND>
184+
<CLASS>true</CLASS>
185+
<STATIC>true</STATIC>
186+
</AND>
187+
</match>
188+
</rule>
189+
</section>
190+
</rules>
191+
</arrangement>
192+
</codeStyleSettings>
193+
<codeStyleSettings language="JSON">
194+
<option name="WRAP_ON_TYPING" value="0" />
195+
</codeStyleSettings>
196+
<codeStyleSettings language="JavaScript">
197+
<indentOptions>
198+
<option name="INDENT_SIZE" value="2" />
199+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
200+
<option name="TAB_SIZE" value="2" />
201+
</indentOptions>
202+
</codeStyleSettings>
203+
<codeStyleSettings language="TypeScript">
204+
<option name="RIGHT_MARGIN" value="140" />
205+
<option name="IF_BRACE_FORCE" value="3" />
206+
<option name="DOWHILE_BRACE_FORCE" value="3" />
207+
<option name="WHILE_BRACE_FORCE" value="3" />
208+
<option name="FOR_BRACE_FORCE" value="3" />
209+
</codeStyleSettings>
210+
<codeStyleSettings language="XML">
211+
<indentOptions>
212+
<option name="INDENT_SIZE" value="2" />
213+
<option name="CONTINUATION_INDENT_SIZE" value="4" />
214+
</indentOptions>
215+
</codeStyleSettings>
216+
</code_scheme>

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ ext {
1818
}
1919
2020
dependencies {
21-
implementation "javasabr:rlib-common:$rlibVersion"
22-
implementation "javasabr:rlib-collections:$rlibVersion"
23-
implementation "javasabr:rlib-compiler:$rlibVersion"
24-
implementation "javasabr:rlib-concurrent:$rlibVersion"
25-
implementation "javasabr:rlib-geometry:$rlibVersion"
26-
implementation "javasabr:rlib-logger-api:$rlibVersion"
27-
implementation "javasabr:rlib-logger-slf4j:$rlibVersion"
28-
implementation "javasabr:rlib-plugin-system:$rlibVersion"
29-
implementation "javasabr:rlib-reference:$rlibVersion"
30-
implementation "javasabr:rlib-reusable:$rlibVersion"
31-
implementation "javasabr:rlib-fx:$rlibVersion"
32-
implementation "javasabr:rlib-network:$rlibVersion"
33-
implementation "javasabr:rlib-mail:$rlibVersion"
34-
implementation "javasabr:rlib-testcontainers:$rlibVersion"
21+
implementation "javasabr.rlib:rlib-common:$rlibVersion"
22+
implementation "javasabr.rlib:rlib-collections:$rlibVersion"
23+
implementation "javasabr.rlib:rlib-compiler:$rlibVersion"
24+
implementation "javasabr.rlib:rlib-concurrent:$rlibVersion"
25+
implementation "javasabr.rlib:rlib-geometry:$rlibVersion"
26+
implementation "javasabr.rlib:rlib-logger-api:$rlibVersion"
27+
implementation "javasabr.rlib:rlib-logger-slf4j:$rlibVersion"
28+
implementation "javasabr.rlib:rlib-plugin-system:$rlibVersion"
29+
implementation "javasabr.rlib:rlib-reference:$rlibVersion"
30+
implementation "javasabr.rlib:rlib-reusable:$rlibVersion"
31+
implementation "javasabr.rlib:rlib-fx:$rlibVersion"
32+
implementation "javasabr.rlib:rlib-network:$rlibVersion"
33+
implementation "javasabr.rlib:rlib-mail:$rlibVersion"
34+
implementation "javasabr.rlib:rlib-testcontainers:$rlibVersion"
3535
}
3636
```
3737
## Most interesting parts:

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
rootProject.version = "10.0.alpha"
1+
rootProject.version = "10.0.alpha1"
22
group = 'javasabr.rlib'
33

44
subprojects {

rlib-collections/src/main/java/javasabr/rlib/collections/array/Array.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ default Iterator<E> iterator() {
173173
*/
174174
int indexOf(@Nullable Object object);
175175

176+
/**
177+
* @return the index of the object or -1.
178+
*/
179+
<T> int indexOf(Function<E, T> getter, @Nullable Object object);
180+
176181
int lastIndexOf(@Nullable Object object);
177182

178183
<T > T[] toArray(T[] newArray);

rlib-collections/src/main/java/javasabr/rlib/collections/array/ArrayIterationFunctions.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
import java.util.function.BiConsumer;
44
import java.util.function.BiPredicate;
5+
import javasabr.rlib.functions.ObjIntPredicate;
56
import javasabr.rlib.functions.ObjObjLongConsumer;
67
import javasabr.rlib.functions.TriConsumer;
78
import org.jspecify.annotations.Nullable;
89

910
public interface ArrayIterationFunctions<E> {
1011

1112
@Nullable
12-
<T> E findAny(T arg1, BiPredicate<? super E, T> filter);
13+
<A> E findAny(A arg1, BiPredicate<? super E, A> filter);
1314

14-
<T> ArrayIterationFunctions<E> forEach(T arg1, BiConsumer<? super E, T> consumer);
15+
@Nullable
16+
E findAny(int arg1, ObjIntPredicate<? super E> filter);
17+
18+
<A> ArrayIterationFunctions<E> forEach(A arg1, BiConsumer<? super E, A> consumer);
1519

16-
<F, S> ArrayIterationFunctions<E> forEach(F arg1, S arg2, TriConsumer<? super E, F, S> consumer);
20+
<A, B> ArrayIterationFunctions<E> forEach(A arg1, B arg2, TriConsumer<? super E, A, B> consumer);
1721

18-
<F> ArrayIterationFunctions<E> forEach(F arg1, long arg2, ObjObjLongConsumer<? super E, F> consumer);
22+
<A> ArrayIterationFunctions<E> forEach(A arg1, long arg2, ObjObjLongConsumer<? super E, A> consumer);
1923

20-
<T> boolean anyMatch(T arg1, BiPredicate<? super E, T> filter);
24+
<A> boolean anyMatch(A arg1, BiPredicate<? super E, A> filter);
2125
}

rlib-collections/src/main/java/javasabr/rlib/collections/array/IntArray.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
*/
1111
public interface IntArray extends Iterable<Integer>, Serializable, Cloneable, RandomAccess {
1212

13+
ImmutableIntArray EMPTY = new ImmutableIntArray();
14+
1315
static IntArray empty() {
14-
return new ImmutableIntArray();
16+
return EMPTY;
1517
}
1618

1719
static IntArray of(int e1) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package javasabr.rlib.collections.array;
22

3+
import javasabr.rlib.collections.operation.LockableOperations;
34
import javasabr.rlib.collections.operation.LockableSource;
45
import javasabr.rlib.common.ThreadSafe;
56

67
public interface LockableArray<E> extends MutableArray<E>, LockableSource, ThreadSafe {
8+
9+
LockableOperations<LockableArray<E>> operations();
710
}

rlib-collections/src/main/java/javasabr/rlib/collections/array/LongArray.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
*/
1111
public interface LongArray extends Iterable<Long>, Serializable, Cloneable, RandomAccess {
1212

13+
ImmutableLongArray EMPTY = new ImmutableLongArray();
14+
1315
static LongArray empty() {
14-
return new ImmutableLongArray();
16+
return EMPTY;
1517
}
1618

1719
static LongArray of(long e1) {

rlib-collections/src/main/java/javasabr/rlib/collections/array/ReversedArrayIterationFunctions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
public interface ReversedArrayIterationFunctions<E> {
99

1010
@Nullable
11-
<T> E findAny(T arg1, BiPredicate<T, ? super E> filter);
11+
<A> E findAny(A arg1, BiPredicate<A, ? super E> filter);
1212

13-
<T> ReversedArrayIterationFunctions<E> forEach(T arg1, BiConsumer<T, ? super E> consumer);
13+
<A> ReversedArrayIterationFunctions<E> forEach(A arg1, BiConsumer<A, ? super E> consumer);
1414

15-
<F, S> ReversedArrayIterationFunctions<E> forEach(F arg1, S arg2, TriConsumer<F, S, ? super E> consumer);
15+
<A, B> ReversedArrayIterationFunctions<E> forEach(A arg1, B arg2, TriConsumer<A, B, ? super E> consumer);
1616

17-
<T> boolean anyMatch(T arg1, BiPredicate<T, ? super E> filter);
17+
<A> boolean anyMatch(A arg1, BiPredicate<A, ? super E> filter);
1818
}

rlib-collections/src/main/java/javasabr/rlib/collections/array/impl/AbstractArray.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,21 @@ public int indexOf(@Nullable Object object) {
136136
return -1;
137137
}
138138

139+
@Override
140+
public <T> int indexOf(Function<E, T> getter, @Nullable Object object) {
141+
if (object == null) {
142+
return -1;
143+
}
144+
@Nullable E[] wrapped = wrapped();
145+
for (int i = 0, length = size(); i < length; i++) {
146+
//noinspection DataFlowIssue
147+
if (object.equals(getter.apply(wrapped[i]))) {
148+
return i;
149+
}
150+
}
151+
return -1;
152+
}
153+
139154
@Override
140155
public int lastIndexOf(@Nullable Object object) {
141156
if (object == null) {

0 commit comments

Comments
 (0)