
org.opentripplanner.netex.support.JAXBUtils Maven / Gradle / Ivy
The newest version!
package org.opentripplanner.netex.support;
import jakarta.xml.bind.JAXBElement;
import java.util.Collection;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Stream;
/**
* Utility class for processing JAXB objects.
*/
public final class JAXBUtils {
private JAXBUtils() {}
/**
* Transform a collection of JAXBElement wrappers into a stream containing the unwrapped values.
* Null values are filtered out. Note:
* A null JAXBElement represents an element not present in the document.
* A non-null JAXBElement wrapping a null value represents an xsi:nil element.
* There is currently no nillable elements in NeTEx.
*
* @param type the Java type of the wrapped element.
* @param c the collection of JAXBElement wrappers.
*/
public static , T> Stream streamJAXBElementValue(
Class type,
Collection c
) {
return c
.stream()
.filter(Objects::nonNull)
.map(JAXBElement::getValue)
.filter(Objects::nonNull)
.filter(type::isInstance)
.map(type::cast);
}
/**
* Transform a collection of JAXBElement wrappers into a stream containing the unwrapped values
* and apply a consumer on each value. Null values are filtered out.
*
* @param type the Java type of the wrapped element.
* @param c the collection of JAXBElement wrappers.
* @param body a consumer to apply on each unwrapped value.
*/
public static , T> void forEachJAXBElementValue(
Class type,
Collection c,
Consumer body
) {
streamJAXBElementValue(type, c).forEach(body);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy