Skip to content

Commit

Permalink
Refactored Version enum
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Sep 15, 2024
1 parent 2ab6a95 commit 7e2e87f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
49 changes: 43 additions & 6 deletions pmml-model/src/main/java/org/dmg/pmml/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,52 @@
package org.dmg.pmml;

public enum Version {
PMML_3_0("http://www.dmg.org/PMML-3_0"),
PMML_3_0("http://www.dmg.org/PMML-3_0"){

@Override
public Version previous(){
return null;
}
},
PMML_3_1("http://www.dmg.org/PMML-3_1"),
PMML_3_2("http://www.dmg.org/PMML-3_2"),
PMML_4_0("http://www.dmg.org/PMML-4_0"),
PMML_4_1("http://www.dmg.org/PMML-4_1"),
PMML_4_2("http://www.dmg.org/PMML-4_2"),
PMML_4_3("http://www.dmg.org/PMML-4_3"),
PMML_4_4("http://www.dmg.org/PMML-4_4"),
PMML_4_4("http://www.dmg.org/PMML-4_4"){

@Override
public Version next(){
return null;
}
},

/**
* Extended PMML
*/
XPMML("http://xpmml.org/XPMML"){

@Override
public boolean isStandard(){
return false;
}

@Override
public String getVersion(){
throw new UnsupportedOperationException();
}
}

@Override
public Version previous(){
return null;
}

@Override
public Version next(){
return null;
}
},
;

private String namespaceURI = null;
Expand All @@ -33,9 +60,7 @@ private Version(String namespaceURI){
}

public boolean isStandard(){
String namespaceURI = getNamespaceURI();

return namespaceURI.matches(Version.REGEX_PMML_XMLNS);
return true;
}

public String getNamespaceURI(){
Expand All @@ -54,6 +79,18 @@ public String getVersion(){
return version.replace('_', '.');
}

public Version previous(){
Version[] versions = Version.values();

return versions[ordinal() - 1];
}

public Version next(){
Version[] versions = Version.values();

return versions[ordinal() + 1];
}

static
public Version getMinimum(){
Version[] versions = Version.values();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void inspect(PMMLObject object, Field field, Object value){

Required required = field.getAnnotation(Required.class);
if(required != null){
updateMaximum(object, field, previous(required.value()));
updateMaximum(object, field, (required.value()).previous());
}

return;
Expand Down Expand Up @@ -133,11 +133,4 @@ private boolean isNull(Object value){

return (value == null);
}

static
private Version previous(Version version){
Version[] values = Version.values();

return values[version.ordinal() - 1];
}
}

0 comments on commit 7e2e87f

Please sign in to comment.