Skip to content

Instantly share code, notes, and snippets.

@bytekast
Created December 12, 2014 18:42
Show Gist options
  • Save bytekast/038323353e196eb05178 to your computer and use it in GitHub Desktop.
Save bytekast/038323353e196eb05178 to your computer and use it in GitHub Desktop.
List<ModelAnnotation<?>> annotations = new ArrayList<ModelAnnotation<?>>();
annotations.add( new ModelAnnotation<Measure>( "field1", new Measure() ) );
annotations.add( new ModelAnnotation<Attribute>( "field2", new Attribute() ) );
annotations.add( new ModelAnnotation<Dimension>( "field2", new Dimension() ) );
annotations.add( new ModelAnnotation<HierarchyLevel>( "field3", new HierarchyLevel() ) );
annotations.add( new ModelAnnotation<Measure>( "field4", new Measure() ) );
for ( ModelAnnotation<?> modelAnnotation : annotations ) {
// do something with modelAnnotation - what is it? a measure, dimension, etc....
}
@kurtwalker
Copy link

If you need to know the type, you would delegate that to the annotation. modelAnnotation.getSomeTypeSpecificStuff() or modelAnnotation.doOperation.
The code I am about to check in has modelAnnotation.apply() which delegates to AnnotationType.apply which is implemented by each subtype

@bytekast
Copy link
Author

@kurtwalker not sure that would satisfy every scenario. some external logic may need to know what type it is and does not want the model annotation itself to act. for example: UI-related stuff....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment