use of com.helger.commons.state.ETriState in project ph-commons by phax.
the class XMLSerializer method _writeDocument.
private void _writeDocument(@Nonnull final XMLEmitter aXMLWriter, @Nonnull final Document aDocument) {
if (m_aSettings.getSerializeXMLDeclaration().isEmit()) {
String sXMLVersion = null;
ETriState eDocumentStandalone = ETriState.UNDEFINED;
try {
sXMLVersion = aDocument.getXmlVersion();
eDocumentStandalone = ETriState.valueOf(aDocument.getXmlStandalone());
} catch (final LinkageError | DOMException ex) {
// LinkageError Happens e.g. in dom4j 1.6.1:
// AbstractMethodError: getXmlVersion and getXmlStandalone
// DOMException in dom4j 2.0.3
}
final EXMLVersion eXMLVersion = EXMLVersion.getFromVersionOrDefault(sXMLVersion, m_aSettings.getXMLVersion());
aXMLWriter.onXMLDeclaration(eXMLVersion, m_aSettings.getCharset().name(), m_aSettings.getSerializeXMLDeclaration().isEmitStandalone() ? eDocumentStandalone : ETriState.UNDEFINED, m_aSettings.isNewLineAfterXMLDeclaration());
}
_writeNodeList(aXMLWriter, aDocument, aDocument.getChildNodes());
}
use of com.helger.commons.state.ETriState in project ph-commons by phax.
the class AnnotationUsageCache method hasAnnotation.
/**
* Check if the provided class has the annotation from the constructor or not.
* If the value is not yet in the cache, it will be determined.
*
* @param aClass
* The class to check. May not be <code>null</code>.
* @return <code>true</code> if the provided class has the annotation,
* <code>false</code> if not.
*/
public boolean hasAnnotation(@Nonnull final Class<?> aClass) {
ValueEnforcer.notNull(aClass, "Class");
final String sClassName = aClass.getName();
if (false) {
// ConcurrentModificationException in Java 11
return m_aMap.computeIfAbsent(sClassName, k -> ETriState.valueOf(aClass.getAnnotation(m_aAnnotationClass) != null)).isTrue();
}
// This version is save for Java 1.8 and Java 11
ETriState e = m_aMap.get(sClassName);
if (e == null) {
// Evtl. double retrieval is okay
e = ETriState.valueOf(aClass.getAnnotation(m_aAnnotationClass) != null);
m_aMap.put(sClassName, e);
}
return e.isTrue();
}
Aggregations