Add RecordBuilderFull
- Add `@RecordBuilderFull` which will have most optional features enabled - Change `@RecordBuilder.Template` to be `RetentionPolicy.CLASS`
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
[◀︎ RecordBuilder](README.md) • Customizing RecordBuilder
|
[◀︎ RecordBuilder](README.md) • Customizing RecordBuilder
|
||||||
|
|
||||||
|
# RecordBuilderFull
|
||||||
|
|
||||||
|
Note: `@RecordBuilderFull` has most optional features enabled. It's an alternate
|
||||||
|
form of `@RecordBuilder` that uses the [templating mechanism](#create-a-custom-annotation) to
|
||||||
|
enable optional features.
|
||||||
|
|
||||||
# Customizing RecordBuilder
|
# Customizing RecordBuilder
|
||||||
|
|
||||||
RecordBuilder can be customized in a number of ways. The types of customizations will change over time. See
|
RecordBuilder can be customized in a number of ways. The types of customizations will change over time. See
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ public @interface RecordBuilder {
|
|||||||
boolean useImmutableCollections() default false;
|
boolean useImmutableCollections() default false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.CLASS)
|
||||||
@Target(ElementType.ANNOTATION_TYPE)
|
@Target(ElementType.ANNOTATION_TYPE)
|
||||||
@Inherited
|
@Inherited
|
||||||
@interface Template {
|
@interface Template {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2019 Jordan Zimmerman
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package io.soabase.recordbuilder.core;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@RecordBuilder.Template(options = @RecordBuilder.Options(
|
||||||
|
interpretNotNulls = true,
|
||||||
|
useImmutableCollections = true
|
||||||
|
))
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Inherited
|
||||||
|
/**
|
||||||
|
* An alternate form of {@code @RecordBuilder} that has most
|
||||||
|
* optional features turned on
|
||||||
|
*/
|
||||||
|
public @interface RecordBuilderFull {
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2019 Jordan Zimmerman
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package io.soabase.recordbuilder.test;
|
||||||
|
|
||||||
|
import io.soabase.recordbuilder.core.RecordBuilderFull;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RecordBuilderFull
|
||||||
|
public record FullRecord(@NotNull List<Number> numbers, @NotNull Map<Number, FullRecord> fullRecords) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2019 Jordan Zimmerman
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package io.soabase.recordbuilder.test;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
class TestRecordBuilderFull {
|
||||||
|
@Test
|
||||||
|
void testNonNull() {
|
||||||
|
Assertions.assertThrows(NullPointerException.class, () -> FullRecordBuilder.builder().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testImmutable() {
|
||||||
|
var record = FullRecordBuilder.builder()
|
||||||
|
.fullRecords(new HashMap<>())
|
||||||
|
.numbers(new ArrayList<>())
|
||||||
|
.build();
|
||||||
|
Assertions.assertThrows(UnsupportedOperationException.class, () -> record.fullRecords().put(1, record));
|
||||||
|
Assertions.assertThrows(UnsupportedOperationException.class, () -> record.numbers().add(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user