source: domaineditor/src/main/java/geniusweb/domaineditor/model/ValueSetModelType.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 1.7 KB
Line 
1package geniusweb.domaineditor.model;
2
3import geniusweb.issuevalue.DiscreteValueSet;
4import geniusweb.issuevalue.NumberValueSet;
5import geniusweb.issuevalue.ValueSet;
6import tudelft.utilities.logging.Reporter;
7
8/**
9 * Types of {@link ValueSetModel} and Model factory
10 *
11 */
12public enum ValueSetModelType {
13 DISCRETE(DiscreteValueSetModel.class), NUMBER(NumberValueSetModel.class);
14
15 private Class<? extends ValueSetModel> modelclass;
16
17 /**
18 *
19 * @param clas the model class matching with this type.
20 */
21 ValueSetModelType(Class<? extends ValueSetModel> clas) {
22 this.modelclass = clas;
23 }
24
25 /**
26 *
27 * @param valueset the {@link ValueSet} to get type of
28 * @return the type
29 */
30 public static ValueSetModelType fromModel(ValueSet valueset) {
31 if (valueset instanceof DiscreteValueSet)
32 return DISCRETE;
33 if (valueset instanceof NumberValueSet)
34 return NUMBER;
35 throw new IllegalArgumentException(
36 "valueset of Unknown class " + valueset);
37 }
38
39 /**
40 * Find the Type for the given model.
41 *
42 * @param model {@link ValueSetModel}
43 * @return {@link ValueSetModelType}
44 */
45 public static ValueSetModelType fromModel(ValueSetModel model) {
46 for (ValueSetModelType type : ValueSetModelType.values()) {
47 if (model.getClass().equals(type.modelclass))
48 return type;
49 }
50 throw new IllegalArgumentException("Model of Unknown class " + model);
51 }
52
53 public static ValueSetModel createModel(ValueSetModelType type,
54 Reporter log) {
55 switch (type) {
56 case DISCRETE:
57 return new DiscreteValueSetModel(log);
58 case NUMBER:
59 return new NumberValueSetModel(log);
60 }
61 return null; // unreachable code
62 }
63
64 /**
65 *
66 * @return the other type
67 */
68 public ValueSetModelType otherType() {
69 return this == DISCRETE ? NUMBER : DISCRETE;
70 }
71}
Note: See TracBrowser for help on using the repository browser.