org.jpmml.xjc.XJCUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pmml-xjc Show documentation
Show all versions of pmml-xjc Show documentation
JPMML XJC plugins for programmatic class model customization
/*
* Copyright (c) 2013 KNIME.com AG, Zurich, Switzerland
*/
package org.jpmml.xjc;
import java.util.Arrays;
import java.util.function.Predicate;
import com.sun.tools.xjc.outline.FieldOutline;
public class XJCUtil {
private XJCUtil(){
}
static
public FieldOutline findSingletonField(FieldOutline[] fieldOutlines, Predicate predicate){
FieldOutline[] acceptedFieldOutlines = filterFields(fieldOutlines, predicate);
if(acceptedFieldOutlines.length == 0){
return null;
} else
if(acceptedFieldOutlines.length == 1){
return acceptedFieldOutlines[0];
} else
{
throw new IllegalArgumentException();
}
}
static
public FieldOutline[] filterFields(FieldOutline[] fieldOutlines, Predicate predicate){
return Arrays.stream(fieldOutlines).filter(predicate).toArray(FieldOutline[]::new);
}
}