Skip to content

Commit

Permalink
Refactoring:
Browse files Browse the repository at this point in the history
Use Sealed in Field interface
Remove Properties
Move Field in fields package.
  • Loading branch information
MarcGuiot committed May 15, 2024
1 parent 549f40d commit 3733905
Show file tree
Hide file tree
Showing 189 changed files with 210 additions and 603 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.globsframework.functional;

import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.GlobType;
import org.globsframework.model.FieldValues;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.globsframework.functional;

import org.globsframework.functional.impl.DefaultFunctionalKeyBuilderFactory;
import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.GlobType;

public interface FunctionalKeyBuilderFactory {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.globsframework.functional.impl;

import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.fields.*;
import org.globsframework.model.FieldSetter;
import org.globsframework.model.FieldValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.globsframework.functional.FunctionalKeyBuilder;
import org.globsframework.functional.FunctionalKeyBuilderFactory;
import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.GlobType;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.globsframework.functional.FunctionalKey;
import org.globsframework.functional.FunctionalKeyBuilder;
import org.globsframework.functional.MutableFunctionalKey;
import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.fields.FieldValueVisitor;
import org.globsframework.model.FieldValue;
import org.globsframework.model.FieldValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.globsframework.functional.FunctionalKey;
import org.globsframework.functional.FunctionalKeyBuilder;
import org.globsframework.functional.MutableFunctionalKey;
import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.GlobType;
import org.globsframework.model.FieldValues;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.globsframework.functional.FunctionalKey;
import org.globsframework.functional.FunctionalKeyBuilder;
import org.globsframework.functional.MutableFunctionalKey;
import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.fields.FieldValueVisitor;
import org.globsframework.model.FieldValue;
import org.globsframework.utils.exceptions.ItemNotFound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.globsframework.functional.FunctionalKey;
import org.globsframework.functional.FunctionalKeyBuilder;
import org.globsframework.functional.MutableFunctionalKey;
import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.GlobType;
import org.globsframework.model.FieldValues;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.globsframework.functional.FunctionalKey;
import org.globsframework.functional.FunctionalKeyBuilder;
import org.globsframework.functional.MutableFunctionalKey;
import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.fields.FieldValueVisitor;
import org.globsframework.model.FieldValue;
import org.globsframework.utils.exceptions.ItemNotFound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.globsframework.functional.FunctionalKey;
import org.globsframework.functional.FunctionalKeyBuilder;
import org.globsframework.functional.MutableFunctionalKey;
import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.GlobType;
import org.globsframework.model.FieldValues;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.globsframework.metamodel;

import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.impl.DefaultAnnotations;
import org.globsframework.model.Glob;
import org.globsframework.model.Key;
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/org/globsframework/metamodel/GlobModel.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.globsframework.metamodel;

import org.globsframework.metamodel.properties.Property;
import org.globsframework.metamodel.properties.impl.PropertiesBuilder;
import org.globsframework.metamodel.utils.GlobTypeDependencies;
import org.globsframework.utils.exceptions.ItemNotFound;

import java.util.Collection;

Expand All @@ -17,11 +14,5 @@ public interface GlobModel extends Iterable<GlobType>, GlobTypeResolver {

GlobTypeDependencies getDependencies();

<T>
Property<GlobType, T> createGlobTypeProperty(String name, final PropertiesBuilder.PropertyBuilder<GlobType, T> valueBuilder);

<T>
Property<Field, T> createFieldProperty(String name, final PropertiesBuilder.PropertyBuilder<Field, T> fieldValueBuilder);

GlobLinkModel getLinkModel();
}
6 changes: 3 additions & 3 deletions src/main/java/org/globsframework/metamodel/GlobType.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package org.globsframework.metamodel;

import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.fields.FieldVisitor;
import org.globsframework.metamodel.fields.FieldVisitorWithContext;
import org.globsframework.metamodel.impl.DefaultValuesFieldVisitor;
import org.globsframework.metamodel.index.Index;
import org.globsframework.metamodel.properties.PropertyHolder;
import org.globsframework.metamodel.utils.MutableAnnotations;
import org.globsframework.model.GlobFactory;
import org.globsframework.model.Key;
import org.globsframework.model.MutableGlob;
import org.globsframework.utils.exceptions.ItemNotFound;

import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Optional;
import java.util.stream.Stream;

public interface GlobType extends PropertyHolder<GlobType>, Annotations {
public interface GlobType extends MutableAnnotations {

String getName();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.globsframework.metamodel;

import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.index.MultiFieldNotUniqueIndex;
import org.globsframework.metamodel.index.MultiFieldUniqueIndex;
import org.globsframework.metamodel.index.NotUniqueIndex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.globsframework.metamodel;

import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.links.DirectLink;
import org.globsframework.metamodel.links.Link;
import org.globsframework.metamodel.utils.MutableAnnotations;
Expand Down Expand Up @@ -44,7 +45,7 @@ interface DirectLinkBuilder extends LinkBuilder<DirectLinkBuilder> {
DirectLink publish();
}

interface LinkBuilder<T extends LinkBuilder> extends MutableAnnotations<T> {
interface LinkBuilder<T extends LinkBuilder> extends MutableAnnotations {

T add(Field sourceField, Field targetField);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.globsframework.metamodel.annotations;

import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.GlobType;
import org.globsframework.metamodel.GlobTypeLoaderFactory;
import org.globsframework.metamodel.fields.StringArrayField;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.globsframework.metamodel.annotations;

import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.GlobType;
import org.globsframework.metamodel.fields.StringField;
import org.globsframework.metamodel.impl.DefaultFieldFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.globsframework.metamodel.annotations;

import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.GlobType;
import org.globsframework.metamodel.GlobTypeLoader;
import org.globsframework.metamodel.GlobTypeLoaderFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.globsframework.metamodel.annotations;

import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.Field;
import org.globsframework.metamodel.GlobType;
import org.globsframework.metamodel.GlobTypeLoaderFactory;
import org.globsframework.metamodel.fields.StringField;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.Field;
import org.globsframework.model.FieldValuesAccessor;

import java.math.BigDecimal;
import java.util.function.Function;

public interface BigDecimalArrayField extends Field, Function<FieldValuesAccessor, BigDecimal[]> {
public non-sealed interface BigDecimalArrayField extends Field, Function<FieldValuesAccessor, BigDecimal[]> {
default BigDecimal[] apply(FieldValuesAccessor glob) {
return glob.get(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.Field;
import org.globsframework.model.FieldValuesAccessor;

import java.math.BigDecimal;
import java.util.function.Function;

public interface BigDecimalField extends Field, Function<FieldValuesAccessor, BigDecimal> {
public non-sealed interface BigDecimalField extends Field, Function<FieldValuesAccessor, BigDecimal> {
default BigDecimal apply(FieldValuesAccessor glob) {
return glob.get(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.Field;
import org.globsframework.model.FieldValuesAccessor;

import java.util.function.Function;

public interface BlobField extends Field, Function<FieldValuesAccessor, byte[]> {
public non-sealed interface BlobField extends Field, Function<FieldValuesAccessor, byte[]> {
default byte[] apply(FieldValuesAccessor glob) {
return glob.get(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.Field;
import org.globsframework.model.FieldValuesAccessor;

import java.util.function.Function;

public interface BooleanArrayField extends Field, Function<FieldValuesAccessor, boolean[]> {
public non-sealed interface BooleanArrayField extends Field, Function<FieldValuesAccessor, boolean[]> {
default boolean[] apply(FieldValuesAccessor glob) {
return glob.get(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.Field;
import org.globsframework.model.FieldValuesAccessor;

import java.util.function.Function;
import java.util.function.Predicate;

public interface BooleanField extends Field, Function<FieldValuesAccessor, Boolean>, Predicate<FieldValuesAccessor> {
public non-sealed interface BooleanField extends Field, Function<FieldValuesAccessor, Boolean>, Predicate<FieldValuesAccessor> {
default Boolean apply(FieldValuesAccessor glob) {
return glob.get(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.Field;
import org.globsframework.model.FieldValuesAccessor;

import java.time.LocalDate;
import java.util.function.Function;

public interface DateField extends Field, Function<FieldValuesAccessor, LocalDate> {
public non-sealed interface DateField extends Field, Function<FieldValuesAccessor, LocalDate> {
default LocalDate apply(FieldValuesAccessor glob) {
return glob.get(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.Field;
import org.globsframework.model.FieldValuesAccessor;

import java.time.ZonedDateTime;
import java.util.function.Function;

public interface DateTimeField extends Field, Function<FieldValuesAccessor, ZonedDateTime> {
public non-sealed interface DateTimeField extends Field, Function<FieldValuesAccessor, ZonedDateTime> {
default ZonedDateTime apply(FieldValuesAccessor glob) {
return glob.get(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.Field;
import org.globsframework.model.FieldValuesAccessor;

import java.util.function.Function;

public interface DoubleArrayField extends Field, Function<FieldValuesAccessor, double[]> {
public non-sealed interface DoubleArrayField extends Field, Function<FieldValuesAccessor, double[]> {
default double[] apply(FieldValuesAccessor glob) {
return glob.get(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.Field;
import org.globsframework.model.FieldValuesAccessor;

import java.util.function.Function;

public interface DoubleField extends Field, Function<FieldValuesAccessor, Double> {
public non-sealed interface DoubleField extends Field, Function<FieldValuesAccessor, Double> {
default Double apply(FieldValuesAccessor glob) {
return glob.get(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.globsframework.metamodel;
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.fields.*;
import org.globsframework.metamodel.properties.PropertyHolder;
import org.globsframework.metamodel.GlobType;
import org.globsframework.metamodel.type.DataType;
import org.globsframework.metamodel.utils.MutableAnnotations;
import org.globsframework.model.FieldValuesAccessor;
import org.globsframework.utils.exceptions.InvalidParameter;

public interface Field extends PropertyHolder<Field>, MutableAnnotations<Field> {
public sealed interface Field extends MutableAnnotations
permits BooleanField, IntegerField, LongField, StringField, DoubleField, BlobField, BigDecimalField, DateField, DateTimeField, GlobField, GlobUnionField,
BooleanArrayField, IntegerArrayField, LongArrayField, StringArrayField, DoubleArrayField, BigDecimalArrayField, GlobArrayField, GlobArrayUnionField {

String getName();

Expand All @@ -29,7 +30,7 @@ public interface Field extends PropertyHolder<Field>, MutableAnnotations<Field>

<T extends FieldVisitor> T safeVisit(T visitor);

<T extends FieldVisitorWithContext<C>, C> T visit(T visitor, C context) throws Exception;
<T extends FieldVisitorWithContext<C>, C> T visit(T visitor, C context) throws Exception;

<T extends FieldVisitorWithContext<C>, C> T safeVisit(T visitor, C context);

Expand All @@ -43,7 +44,7 @@ public interface Field extends PropertyHolder<Field>, MutableAnnotations<Field>

<T extends FieldValueVisitorWithContext<Context>, Context> T safeVisitValue(T visitor, Object value, Context context);

default <T extends FieldValueVisitorWithContext<Context>, Context> T safeVisitValue(T visitor, FieldValuesAccessor value, Context context){
default <T extends FieldValueVisitorWithContext<Context>, Context> T safeVisitValue(T visitor, FieldValuesAccessor value, Context context) {
return safeVisitValue(visitor, value.getValue(this), context);
}

Expand Down Expand Up @@ -124,28 +125,28 @@ default DateTimeField asDateTimeField() {
return (DateTimeField) this;
}

default GlobArrayField asGlobArrayField(){
default GlobArrayField asGlobArrayField() {
if (!(this instanceof GlobArrayField)) {
throw new RuntimeException(getFullName() + " is not a GlobArrayField but a " + getDataType());
}
return (GlobArrayField) this;
}

default GlobField asGlobField(){
default GlobField asGlobField() {
if (!(this instanceof GlobField)) {
throw new RuntimeException(getFullName() + " is not a GlobField but a " + getDataType());
}
return (GlobField) this;
}

default GlobArrayUnionField asGlobArrayUnionField(){
default GlobArrayUnionField asGlobArrayUnionField() {
if (!(this instanceof GlobArrayUnionField)) {
throw new RuntimeException(getFullName() + " is not a GlobArrayUnionField but a " + getDataType());
}
return (GlobArrayUnionField) this;
}

default GlobUnionField asGlobUnionField(){
default GlobUnionField asGlobUnionField() {
if (!(this instanceof GlobUnionField)) {
throw new RuntimeException(getFullName() + " is not a GlobUnionField but a " + getDataType());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.globsframework.metamodel.fields;

import org.globsframework.metamodel.Field;
import org.globsframework.metamodel.fields.impl.FieldValueVisitorButKey;
import org.globsframework.model.Glob;

Expand Down
Loading

0 comments on commit 3733905

Please sign in to comment.