Skip to content

Commit

Permalink
Merge pull request #93 from cip4/generator1.8
Browse files Browse the repository at this point in the history
Generator1.8
  • Loading branch information
rainer-prosi authored Jun 26, 2024
2 parents 97cfaf7 + ef2c4cf commit 4625ee0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ processResources {
}

dependencies {
implementation('org.cip4.lib.jdf:JDFLibJ:2.1.7.+') {
implementation('org.cip4.lib.jdf:JDFLibJ:2.1.8.+') {
exclude group: 'xml-apis'
}

Expand Down
39 changes: 11 additions & 28 deletions src/main/java/org/cip4/jdflib/generator/GeneratorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.cip4.jdflib.core.AttributeInfo;
Expand Down Expand Up @@ -2340,20 +2341,12 @@ private static void mergeAttributeInfo(final SchemaAttribute newSchema, final Sc
* @param String usage "optional" or "required"
* @param String firstVersion i.e. "1.1" and lastVersion = ""
* @param String lastVersion i.e. "1.2" and firstVersion = ""
* @return a String of form 44333311
* @return a String of form 44333311l
*/
public static String getVersionInfoAttributes(final String usage, final String firstVersion, final String lastVersion)
{
// we need a vector the iterator can be random and we need a spezific order
final Vector version = new Vector();
version.add(EnumVersion._1_7);
version.add(EnumVersion._1_6);
version.add(EnumVersion._1_5);
version.add(EnumVersion._1_4);
version.add(EnumVersion._1_3);
version.add(EnumVersion._1_2);
version.add(EnumVersion._1_1);
version.add(EnumVersion._1_0);
final List<EnumVersion> version = EnumVersion.getReverseList();

EnumVersion eFirstVer = EnumVersion.getEnum(firstVersion);
EnumVersion eLastVer = EnumVersion.getEnum(lastVersion);
Expand All @@ -2365,14 +2358,13 @@ public static String getVersionInfoAttributes(final String usage, final String f

if (eLastVer == null)
{
eLastVer = EnumVersion._1_7;
eLastVer = EnumVersion.getLastVersion();
}

final StringBuffer verBuffer = new StringBuffer(10);
final StringBuffer verBuffer = new StringBuffer(20);

for (int i = 0; i < version.size(); i++)
for (final EnumVersion processedVersion : version)
{
final EnumVersion processedVersion = (EnumVersion) version.elementAt(i);

if (processedVersion.getValue() > eLastVer.getValue())
{
Expand All @@ -2394,6 +2386,7 @@ else if (processedVersion.getValue() >= eFirstVer.getValue())
verBuffer.append("1");
}
}
verBuffer.append("l");

return verBuffer.toString();
}
Expand All @@ -2418,15 +2411,7 @@ else if (processedVersion.getValue() >= eFirstVer.getValue())
public static String getVersionInfoElements(final boolean isOptional, final String firstVersion, final String lastVersion, final String maxOccurs)
{
// we need a vector the iterator can be random and we need a spezific order
final Vector version = new Vector();
version.add(EnumVersion._1_7);
version.add(EnumVersion._1_6);
version.add(EnumVersion._1_5);
version.add(EnumVersion._1_4);
version.add(EnumVersion._1_3);
version.add(EnumVersion._1_2);
version.add(EnumVersion._1_1);
version.add(EnumVersion._1_0);
final List<EnumVersion> version = EnumVersion.getReverseList();

EnumVersion eLastVer = EnumVersion.getEnum(lastVersion);
EnumVersion eFirstVer = EnumVersion.getEnum(firstVersion);
Expand All @@ -2438,15 +2423,13 @@ public static String getVersionInfoElements(final boolean isOptional, final Stri

if (eLastVer == null)
{
eLastVer = EnumVersion._1_7;
eLastVer = EnumVersion.getLastVersion();
}

final StringBuffer verBuffer = new StringBuffer(10);

for (int i = 0; i < version.size(); i++)
for (final EnumVersion processedVersion : version)
{
final EnumVersion processedVersion = (EnumVersion) version.elementAt(i);

if (processedVersion.getValue() > eLastVer.getValue())
{ // is deprecated
if (maxOccurs.equals("1"))
Expand Down Expand Up @@ -2488,7 +2471,7 @@ else if (processedVersion.getValue() >= eFirstVer.getValue())
verBuffer.append("1");
}
}

verBuffer.append("l");
return verBuffer.toString();
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/cip4/jdflib/generator/JavaCoreStringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
// package
package org.cip4.jdflib.generator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -88,6 +90,18 @@ public static List getEnumList()
return getEnumList(EnumVersion.class);
}

public static List<EnumVersion> getReverseList()
{
final List<EnumVersion> enumList = new ArrayList<>(getEnumList(EnumVersion.class));
Collections.reverse(enumList);
return enumList;
}

public static EnumVersion getLastVersion()
{
return (EnumVersion) getEnumList().get(getEnumList().size() - 1);
}

public static Iterator iterator()
{
return iterator(EnumVersion.class);
Expand All @@ -113,6 +127,8 @@ public static Vector getNamesVector()
public static final EnumVersion _1_5 = new EnumVersion("1.5");
public static final EnumVersion _1_6 = new EnumVersion("1.6");
public static final EnumVersion _1_7 = new EnumVersion("1.7");
public static final EnumVersion _1_8 = new EnumVersion("1.8");
public static final EnumVersion _1_9 = new EnumVersion("1.9");
}

public static String getStrJavaCoreFile(final SchemaComplexType schemaComplexType)
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/org/cip4/jdflib/generator/GeneratorUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.cip4.jdflib.generator;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

class GeneratorUtilTest
{

@Test
void testVersionAtts()
{
assertEquals(GeneratorUtil.getVersionInfoAttributes("required", "1.2", null), "2222222211l");
assertEquals(GeneratorUtil.getVersionInfoAttributes("required", null, "1.4"), "4444422222l");
}

}

0 comments on commit 4625ee0

Please sign in to comment.