Search in sources :

Example 31 with ETriState

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());
}
Also used : DOMException(org.w3c.dom.DOMException) ETriState(com.helger.commons.state.ETriState) EXMLVersion(com.helger.xml.EXMLVersion)

Example 32 with ETriState

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();
}
Also used : CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ETriState(com.helger.commons.state.ETriState) Annotation(java.lang.annotation.Annotation) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) ToStringGenerator(com.helger.commons.string.ToStringGenerator) Nonnull(javax.annotation.Nonnull) Retention(java.lang.annotation.Retention) RetentionPolicy(java.lang.annotation.RetentionPolicy) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) ValueEnforcer(com.helger.commons.ValueEnforcer) ETriState(com.helger.commons.state.ETriState)

Aggregations

ETriState (com.helger.commons.state.ETriState)32 Nonnull (javax.annotation.Nonnull)24 Nullable (javax.annotation.Nullable)10 ValueEnforcer (com.helger.commons.ValueEnforcer)7 ErrorList (com.helger.commons.error.list.ErrorList)7 Consumer (java.util.function.Consumer)7 AmountType (un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType)7 CGlobal (com.helger.commons.CGlobal)6 CollectionHelper (com.helger.commons.collection.CollectionHelper)6 EqualsHelper (com.helger.commons.equals.EqualsHelper)6 IErrorList (com.helger.commons.error.list.IErrorList)6 MathHelper (com.helger.commons.math.MathHelper)6 StringHelper (com.helger.commons.string.StringHelper)6 Serializable (java.io.Serializable)6 BigDecimal (java.math.BigDecimal)6 LocalDate (java.time.LocalDate)6 CrossIndustryInvoiceType (un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType)6 FormattedDateTimeType (un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType)6 un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100 (un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100)6 BinaryObjectType (un.unece.uncefact.data.standard.unqualifieddatatype._100.BinaryObjectType)6