-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default values evolution #20
Open
MicrexIT
wants to merge
1
commit into
master
Choose a base branch
from
feat/instantiate-default-values
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/org/globsframework/metamodel/annotations/DefaultBigDecimal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.globsframework.metamodel.annotations; | ||
|
||
import org.globsframework.metamodel.GlobType; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@java.lang.annotation.Target({ElementType.FIELD}) | ||
public @interface DefaultBigDecimal { | ||
String value(); | ||
|
||
GlobType TYPE = DefaultBigDecimalAnnotationType.DESC; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/globsframework/metamodel/annotations/DefaultBigDecimalAnnotationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.globsframework.metamodel.annotations; | ||
|
||
import org.globsframework.metamodel.GlobType; | ||
import org.globsframework.metamodel.GlobTypeLoader; | ||
import org.globsframework.metamodel.GlobTypeLoaderFactory; | ||
import org.globsframework.metamodel.fields.BigDecimalField; | ||
import org.globsframework.metamodel.fields.DoubleField; | ||
import org.globsframework.model.Glob; | ||
import org.globsframework.model.Key; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class DefaultBigDecimalAnnotationType { | ||
|
||
public static GlobType DESC; | ||
|
||
@DefaultFieldValue | ||
public static BigDecimalField DEFAULT_VALUE; | ||
|
||
@InitUniqueKey | ||
public static Key UNIQUE_KEY; | ||
|
||
public static Glob create(String defaultBigDecimal) { | ||
return DESC.instantiate().set(DEFAULT_VALUE, new BigDecimal(defaultBigDecimal)); | ||
} | ||
|
||
static { | ||
GlobTypeLoader loader = GlobTypeLoaderFactory.create(DefaultBigDecimalAnnotationType.class); | ||
loader.register(GlobCreateFromAnnotation.class, annotation -> create(((DefaultBigDecimal)annotation).value())) | ||
.load(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/java/org/globsframework/metamodel/impl/DefaultValuesFieldVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package org.globsframework.metamodel.impl; | ||
|
||
import org.globsframework.metamodel.annotations.*; | ||
import org.globsframework.metamodel.fields.*; | ||
import org.globsframework.model.MutableGlob; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class DefaultValuesFieldVisitor implements FieldVisitorWithContext<MutableGlob> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il y a un Abstract dans l'interface pour ne pas avoir a implementer les methodes vide |
||
@Override | ||
public void visitInteger(IntegerField field, MutableGlob context) throws Exception { | ||
if (field.hasAnnotation(DefaultIntegerAnnotationType.UNIQUE_KEY)) { | ||
context.set(field.asIntegerField(), (int) field.getDefaultValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public void visitIntegerArray(IntegerArrayField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitDouble(DoubleField field, MutableGlob context) throws Exception { | ||
if (field.hasAnnotation(DefaultDoubleAnnotationType.UNIQUE_KEY)) { | ||
context.set(field.asDoubleField(), (double) field.getDefaultValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public void visitDoubleArray(DoubleArrayField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitString(StringField field, MutableGlob context) throws Exception { | ||
if (field.hasAnnotation(DefaultStringAnnotationType.UNIQUE_KEY)) { | ||
context.set(field.asStringField(), (String) field.getDefaultValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public void visitStringArray(StringArrayField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitBoolean(BooleanField field, MutableGlob context) throws Exception { | ||
if (field.hasAnnotation(DefaultBooleanAnnotationType.UNIQUE_KEY)) { | ||
context.set(field.asBooleanField(), (boolean) field.getDefaultValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public void visitBooleanArray(BooleanArrayField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitBigDecimal(BigDecimalField field, MutableGlob context) throws Exception { | ||
if (field.hasAnnotation(DefaultBigDecimalAnnotationType.UNIQUE_KEY)) { | ||
context.set(field.asBigDecimalField(), (BigDecimal) field.getDefaultValue()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void visitBigDecimalArray(BigDecimalArrayField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitLong(LongField field, MutableGlob context) throws Exception { | ||
if (field.hasAnnotation(DefaultLongAnnotationType.UNIQUE_KEY)) { | ||
context.set(field.asLongField(), (long) field.getDefaultValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public void visitLongArray(LongArrayField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitDate(DateField field, MutableGlob context) throws Exception { | ||
} | ||
|
||
@Override | ||
public void visitDateTime(DateTimeField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitBlob(BlobField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitGlob(GlobField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitGlobArray(GlobArrayField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitUnionGlob(GlobUnionField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void visitUnionGlobArray(GlobArrayUnionField field, MutableGlob context) throws Exception { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/java/org/globsframework/metamodel/GlobTypeInstantiateWithDefaultsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.globsframework.metamodel; | ||
|
||
import org.globsframework.model.MutableGlob; | ||
import org.junit.Test; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class GlobTypeInstantiateWithDefaultsTest { | ||
@Test | ||
public void test() { | ||
MutableGlob globWithDefaults = DummyObjectWithDefaultValues.TYPE.instantiateWithDefaults(); | ||
|
||
assertEquals(globWithDefaults.get(DummyObjectWithDefaultValues.STRING), "Hello"); | ||
assertEquals(globWithDefaults.get(DummyObjectWithDefaultValues.DOUBLE), Double.valueOf(3.14159265)); | ||
assertEquals(globWithDefaults.get(DummyObjectWithDefaultValues.INTEGER), Integer.valueOf(7)); | ||
assertEquals(globWithDefaults.get(DummyObjectWithDefaultValues.LONG), Long.valueOf(5)); | ||
assertEquals(globWithDefaults.get(DummyObjectWithDefaultValues.BIG_DECIMAL), new BigDecimal("1.61803398875")); | ||
assertNull(globWithDefaults.get(DummyObjectWithDefaultValues.ID)); | ||
assertNull(globWithDefaults.get(DummyObjectWithDefaultValues.LINK)); | ||
assertTrue(globWithDefaults.get(DummyObjectWithDefaultValues.BOOLEAN)); | ||
|
||
MutableGlob glob = DummyObjectWithDefaultValues.TYPE.instantiate(); | ||
assertNull(glob.get(DummyObjectWithDefaultValues.STRING)); | ||
assertNull(glob.get(DummyObjectWithDefaultValues.DOUBLE)); | ||
assertNull(glob.get(DummyObjectWithDefaultValues.INTEGER)); | ||
assertNull(glob.get(DummyObjectWithDefaultValues.LONG)); | ||
assertNull(glob.get(DummyObjectWithDefaultValues.BIG_DECIMAL)); | ||
assertNull(glob.get(DummyObjectWithDefaultValues.ID)); | ||
assertNull(glob.get(DummyObjectWithDefaultValues.LINK)); | ||
assertNull(glob.get(DummyObjectWithDefaultValues.BOOLEAN)); | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Michele,
Sauf si quelque chose m'a échapper, le visiteur est un double dispatcheur, qui remplace aussi le switch.