Skip to content

Commit

Permalink
better xjdf conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-prosi committed Nov 22, 2024
1 parent cebb271 commit e49f4ca
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 17 deletions.
38 changes: 22 additions & 16 deletions src/main/java/org/cip4/jdflib/extensions/ProcessXJDFSplit.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/
package org.cip4.jdflib.extensions;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Vector;
Expand Down Expand Up @@ -200,28 +201,33 @@ protected Vector<VString> splitTypes(final XJDFHelper root)

protected VString extractTypes(final XJDFHelper root, final VString types, final int pos)
{
final SetHelper niSet = root.getSet(ElementName.NODEINFO, EnumUsage.Input, null, pos);
if (niSet != null)
resLoop: for (final String resType : new String[] { ElementName.DEVICE, ElementName.NODEINFO })
{
final JDFIntegerList cpi = niSet.getCombinedProcessIndex();
final VString found = new VString();
final int[] il = cpi.getIntArray();
int currentPos = pos;
for (final int ipos : il)
final SetHelper resSet = root.getSet(resType, EnumUsage.Input, null, pos);
if (resSet != null)
{
if (ipos == currentPos++)
final JDFIntegerList cpi = resSet.getCombinedProcessIndex();
final VString found = new VString();
final int[] il = cpi.getIntArray();
Arrays.sort(il);
int currentPos = pos;
for (final int ipos : il)
{
found.add(types.get(ipos - pos));
}
else
{
return extractTypes(types);
if (ipos == currentPos++)
{
found.add(types.get(ipos - pos));
}
else
{
continue resLoop; // java has goto!!!
}
}
for (int i = 0; i < il.length; i++)
types.remove(0);
return found;
}
for (int i = 0; i < il.length; i++)
types.remove(0);
return found;
}

return extractTypes(types);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,87 @@ void testSplitNodeInfo() throws DataFormatException

final ProcessXJDFSplit splitter = new ProcessXJDFSplit();

VString types = h.getTypes();
final VString types = h.getTypes();
final VString t0 = splitter.extractTypes(h, types, 0);
assertEquals(2, t0.size());
final VString t1 = splitter.extractTypes(h, types, 2);
assertEquals(1, t1.size());
final VString t2 = splitter.extractTypes(h, types, 3);
assertEquals(3, t2.size());
}

/**
* @throws DataFormatException
*
*/
@Test
void testSplitDevice2() throws DataFormatException
{
final XJDFHelper h = new XJDFHelper("j1", "root", null);
h.setTypes("Screening ImageSetting ConventionalPrinting Cutting Folding Trimming");
h.appendSet(ElementName.DEVICE, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("0 1"));
h.appendSet(ElementName.DEVICE, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("2"));
h.appendSet(ElementName.DEVICE, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("3 5 4"));

final ProcessXJDFSplit splitter = new ProcessXJDFSplit();

final VString types = h.getTypes();
final VString t0 = splitter.extractTypes(h, types, 0);
assertEquals(2, t0.size());
final VString t1 = splitter.extractTypes(h, types, 2);
assertEquals(1, t1.size());
final VString t2 = splitter.extractTypes(h, types, 3);
assertEquals(3, t2.size());
}

/**
* @throws DataFormatException
*
*/
@Test
void testSplitDeviceNI() throws DataFormatException
{
final XJDFHelper h = new XJDFHelper("j1", "root", null);
h.setTypes("Screening ImageSetting ConventionalPrinting Cutting Folding Trimming");
h.appendSet(ElementName.NODEINFO, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("0 1"));
h.appendSet(ElementName.NODEINFO, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("2"));
h.appendSet(ElementName.NODEINFO, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("3 4 5"));

final XJDFHelper h2 = new XJDFHelper("j1", "root", null);
h2.setTypes("Screening ImageSetting ConventionalPrinting Cutting Folding Trimming");
h2.appendSet(ElementName.DEVICE, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("0 1"));
h2.appendSet(ElementName.DEVICE, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("2"));
h2.appendSet(ElementName.DEVICE, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("3 4 5"));

final ProcessXJDFSplit splitter = new ProcessXJDFSplit();

final VString types = h2.getTypes();
final VString t0 = splitter.extractTypes(h2, types, 0);
assertEquals(2, t0.size());
final VString t1 = splitter.extractTypes(h2, types, 2);
assertEquals(1, t1.size());
final VString t2 = splitter.extractTypes(h2, types, 3);
assertEquals(3, t2.size());
}

/**
* @throws DataFormatException
*
*/
@Test
void testSplitDeviceNIMix() throws DataFormatException
{
final XJDFHelper h = new XJDFHelper("j1", "root", null);
h.setTypes("Screening ImageSetting ConventionalPrinting Cutting Folding Trimming");
h.appendSet(ElementName.NODEINFO, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("2"));
h.appendSet(ElementName.NODEINFO, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("3 4 5"));

h.appendSet(ElementName.DEVICE, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("0 1"));
h.appendSet(ElementName.DEVICE, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("2"));

final ProcessXJDFSplit splitter = new ProcessXJDFSplit();

final VString types = h.getTypes();
final VString t0 = splitter.extractTypes(h, types, 0);
assertEquals(2, t0.size());
final VString t1 = splitter.extractTypes(h, types, 2);
Expand Down

0 comments on commit e49f4ca

Please sign in to comment.