Java Code Examples for com.helger.commons.ValueEnforcer#notEmptyNoNullValue()

The following examples show how to use com.helger.commons.ValueEnforcer#notEmptyNoNullValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CSSShortHandDescriptor.java    From ph-css with Apache License 2.0 6 votes vote down vote up
public CSSShortHandDescriptor (@Nonnull final ECSSProperty eProperty,
                               @Nonnull @Nonempty final CSSPropertyWithDefaultValue... aSubProperties)
{
  ValueEnforcer.notNull (eProperty, "Property");
  ValueEnforcer.notEmptyNoNullValue (aSubProperties, "SubProperties");
  m_eProperty = eProperty;
  m_aSubProperties = new CommonsArrayList <> (aSubProperties);

  // Check that a free text property may only be at the end
  final int nMax = aSubProperties.length;
  for (int i = 0; i < nMax; ++i)
  {
    final CSSPropertyWithDefaultValue aSubProperty = aSubProperties[i];
    final ICSSProperty aProp = aSubProperty.getProperty ();
    if (aProp instanceof CSSPropertyFree && i < nMax - 1)
      throw new IllegalArgumentException ("The SubProperty " +
                                          aSubProperty +
                                          " may not use an unspecified CSSPropertyFree except for the last element!");
  }
}
 
Example 2
Source File: MimeTypeInfo.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
public MimeTypeInfo (@Nonnull @Nonempty final ICommonsOrderedSet <MimeTypeWithSource> aMimeTypes,
                     @Nullable final String sComment,
                     @Nonnull final ICommonsOrderedSet <String> aParentTypes,
                     @Nonnull final ICommonsOrderedSet <String> aGlobs,
                     @Nonnull final ICommonsOrderedSet <ExtensionWithSource> aExtensions,
                     @Nullable final String sSource)
{
  ValueEnforcer.notEmptyNoNullValue (aMimeTypes, "MimeTypes");
  ValueEnforcer.notNull (aParentTypes, "ParentTypes");
  ValueEnforcer.notNull (aGlobs, "Globs");
  ValueEnforcer.notNull (aExtensions, "Extensions");
  m_aMimeTypes = aMimeTypes.getClone ();
  m_sComment = sComment;
  m_aParentTypes = aParentTypes.getClone ();
  m_aGlobs = aGlobs.getClone ();
  m_aExtensions = aExtensions.getClone ();
  m_sSource = sSource;
}
 
Example 3
Source File: CSSValueList.java    From ph-css with Apache License 2.0 5 votes vote down vote up
public CSSValueList (@Nonnull final ECSSProperty eProperty,
                     @Nonnull final ICSSProperty [] aProperties,
                     @Nonnull final String [] aValues,
                     final boolean bIsImportant)
{
  ValueEnforcer.notNull (eProperty, "Property");
  ValueEnforcer.notEmptyNoNullValue (aProperties, "Properties");
  ValueEnforcer.notEmptyNoNullValue (aValues, "Values");
  if (aProperties.length != aValues.length)
    throw new IllegalArgumentException ("Different number of properties and values passed");

  boolean bFound = false;
  for (final ICSSProperty aProperty : aProperties)
    if (aProperty.getProp () == eProperty)
    {
      bFound = true;
      break;
    }
  if (!bFound)
    throw new IllegalArgumentException ("The property " +
                                        eProperty +
                                        " is not contained in an ICSSProperty instance!");

  m_eProperty = eProperty;
  m_aValues = new CommonsArrayList<> (aProperties.length);
  for (int i = 0; i < aProperties.length; ++i)
    m_aValues.add (new CSSValue (aProperties[i], aValues[i], bIsImportant));
}
 
Example 4
Source File: CSSValueMultiValue.java    From ph-css with Apache License 2.0 5 votes vote down vote up
public CSSValueMultiValue (@Nonnull final ICSSProperty aProperty,
                           @Nonnull @Nonempty final String [] aValues,
                           final boolean bIsImportant)
{
  ValueEnforcer.notNull (aProperty, "Property");
  ValueEnforcer.notEmptyNoNullValue (aValues, "Values");

  for (final String sValue : aValues)
    m_aValues.add (new CSSValue (aProperty, sValue, bIsImportant));
}
 
Example 5
Source File: CSSPropertyEnum.java    From ph-css with Apache License 2.0 5 votes vote down vote up
public CSSPropertyEnum (@Nonnull final ECSSProperty eProp,
                        @Nullable final ECSSVendorPrefix eVendorPrefix,
                        @Nullable final ICSSPropertyCustomizer aCustomizer,
                        @Nonnull @Nonempty final Iterable <String> aEnumValues)
{
  super (eProp, eVendorPrefix, aCustomizer);
  ValueEnforcer.notEmptyNoNullValue (aEnumValues, "EnumValues");
  m_aEnumValues = new CommonsHashSet <> ();
  for (final String sPotentialValue : aEnumValues)
  {
    if (StringHelper.hasNoText (sPotentialValue))
      throw new IllegalArgumentException ("At least one enumeration value is empty");
    m_aEnumValues.add (sPotentialValue);
  }
}
 
Example 6
Source File: CSSPropertyEnum.java    From ph-css with Apache License 2.0 5 votes vote down vote up
public CSSPropertyEnum (@Nonnull final ECSSProperty eProp,
                        @Nullable final ECSSVendorPrefix eVendorPrefix,
                        @Nullable final ICSSPropertyCustomizer aCustomizer,
                        @Nonnull @Nonempty final String... aEnumValues)
{
  super (eProp, eVendorPrefix, aCustomizer);
  ValueEnforcer.notEmptyNoNullValue (aEnumValues, "EnumValues");
  m_aEnumValues = new CommonsHashSet <> (aEnumValues.length);
  for (final String sPotentialValue : aEnumValues)
  {
    if (StringHelper.hasNoText (sPotentialValue))
      throw new IllegalArgumentException ("At least one enumeration value is empty");
    m_aEnumValues.add (sPotentialValue);
  }
}
 
Example 7
Source File: SchemaCache.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Schema createSchema (@Nonnull final SchemaFactory aSchemaFactory,
                                   @Nonnull final String sSchemaTypeName,
                                   @Nonnull @Nonempty final ICommonsList <? extends IReadableResource> aResources)
{
  ValueEnforcer.notNull (aSchemaFactory, "SchemaFactory");
  ValueEnforcer.notEmptyNoNullValue (aResources, "Resources");

  // Collect all sources
  final Source [] aSources = new Source [aResources.size ()];
  for (int i = 0; i < aResources.size (); ++i)
    aSources[i] = TransformSourceFactory.create (aResources.get (i));

  try
  {
    final Schema ret = aSchemaFactory.newSchema (aSources);
    if (ret == null)
      throw new IllegalStateException ("Failed to create " +
                                       sSchemaTypeName +
                                       " schema from " +
                                       aResources.toString ());
    return ret;
  }
  catch (final SAXException ex)
  {
    throw new IllegalArgumentException ("Failed to parse " + sSchemaTypeName + " from " + aResources.toString (), ex);
  }
}
 
Example 8
Source File: ConfigFileBuilder.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public ConfigFileBuilder setPaths (@Nonnull @Nonempty final String... aConfigPaths)
{
  ValueEnforcer.notEmptyNoNullValue (aConfigPaths, "ConfigPaths");
  m_aPaths.setAll (aConfigPaths);
  return this;
}
 
Example 9
Source File: JAXBContextCacheKey.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Cache key using package and optional class loader
 *
 * @param aClasses
 *        Classes to be used. May not be <code>null</code>.
 * @param aProperties
 *        JAXB context properties. May be <code>null</code>.
 * @since v9.4.2
 */
public JAXBContextCacheKey (@Nonnull final ICommonsList <Class <?>> aClasses,
                            @Nullable final Map <String, ?> aProperties)
{
  ValueEnforcer.notEmptyNoNullValue (aClasses, "Classes");
  m_aPackage = null;
  m_aClassLoader = null;
  m_aClasses = new CommonsArrayList <> (aClasses, WeakReference::new);
  m_aProperties = new CommonsHashMap <> (aProperties);
  m_sEqualsHashCodeKey = StringHelper.getImplodedMapped (':', aClasses, Class::getName);
}
 
Example 10
Source File: CSSKeyframesBlock.java    From ph-css with Apache License 2.0 4 votes vote down vote up
public CSSKeyframesBlock (@Nonnull @Nonempty final Iterable <String> aKeyframesSelectors)
{
  ValueEnforcer.notEmptyNoNullValue (aKeyframesSelectors, "KeyframesSelectors");
  m_aKeyframesSelectors = new CommonsArrayList <> (aKeyframesSelectors);
}
 
Example 11
Source File: DefaultDAOContainer.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public DefaultDAOContainer (@Nonnull @Nonempty final IDAO... aDAOs)
{
  ValueEnforcer.notEmptyNoNullValue (aDAOs, "DAOs");
  m_aDAOs = new CommonsArrayList <> (aDAOs);
}
 
Example 12
Source File: DefaultDAOContainer.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public DefaultDAOContainer (@Nonnull @Nonempty final Iterable <? extends IDAO> aDAOs)
{
  ValueEnforcer.notEmptyNoNullValue (aDAOs, "DAOs");
  m_aDAOs = new CommonsArrayList <> (aDAOs);
}
 
Example 13
Source File: ReadableResourceProviderChain.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public ReadableResourceProviderChain (@Nonnull final IReadableResourceProvider... aResProviders)
{
  ValueEnforcer.notEmptyNoNullValue (aResProviders, "ResourceProviders");

  m_aReadingResourceProviders = new CommonsArrayList <> (aResProviders);
}
 
Example 14
Source File: ReadableResourceProviderChain.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public ReadableResourceProviderChain (@Nonnull final Iterable <? extends IReadableResourceProvider> aResProviders)
{
  ValueEnforcer.notEmptyNoNullValue (aResProviders, "ResourceProviders");

  m_aReadingResourceProviders = new CommonsArrayList <> (aResProviders);
}
 
Example 15
Source File: JAXBDocumentType.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Simple constructor when you know what you are doing.
 *
 * @param aClass
 *        The JAXB generated class of the root element. May not be
 *        <code>null</code>. This class must have the <code>@XmlType</code>
 *        annotation and the package the class resides in must have the
 *        <code>@XmlSchema</code> annotation with a non-null
 *        <code>namespace</code> property!
 * @param aXSDs
 *        The classpath relative paths to the XML Schema. May not be
 *        <code>null</code> but maybe empty. If the main XSD imports another
 *        XSD, the imported XSD must come first in the list. So the XSDs
 *        without any dependencies must come first!
 * @param sNamespaceURI
 *        The namespace URI to use. May be <code>null</code>.
 * @param sLocalName
 *        The locale name of the element. May neither be <code>null</code> nor
 *        empty.
 * @since 9.4.0
 */
public JAXBDocumentType (@Nonnull final Class <?> aClass,
                         @Nullable final List <? extends ClassPathResource> aXSDs,
                         @Nullable final String sNamespaceURI,
                         @Nonnull @Nonempty final String sLocalName)
{
  ValueEnforcer.notNull (aClass, "Class");
  if (aXSDs != null)
  {
    ValueEnforcer.notEmptyNoNullValue (aXSDs, "XSDs");
    for (final ClassPathResource aRes : aXSDs)
      ValueEnforcer.isTrue (aRes.hasClassLoader (),
                            () -> "ClassPathResource " + aRes + " should define its ClassLoader for OSGI handling!");
  }
  ValueEnforcer.notEmpty (sLocalName, "sLocalName");

  // Check whether it is an @XmlType class
  final XmlType aXmlType = aClass.getAnnotation (XmlType.class);
  if (aXmlType == null)
    throw new IllegalArgumentException ("The passed class '" +
                                        aClass.getName () +
                                        "' does not have an @XmlType annotation!");

  // Get the package of the passed Class
  final Package aPackage = aClass.getPackage ();

  // The package must have the annotation "XmlSchema" with the corresponding
  // namespace it supports (maybe empty but not null). If the base XSD does
  // not contain any namespace URI, the XMLSchema annotation might be missing!
  final XmlSchema aXmlSchema = aPackage.getAnnotation (XmlSchema.class);
  if (aXmlSchema != null && aXmlSchema.namespace () == null)
    throw new IllegalArgumentException ("The package '" +
                                        aPackage.getName () +
                                        "' has no namespace URI in the @XmlSchema annotation!");

  m_aClass = aClass;
  if (aXSDs != null)
    m_aXSDs.addAll (aXSDs);
  m_sNamespaceURI = sNamespaceURI;
  m_sLocalName = sLocalName;
}
 
Example 16
Source File: JAXBDocumentType.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param aClass
 *        The JAXB generated class of the root element. May not be
 *        <code>null</code>. This class must have the <code>@XmlType</code>
 *        annotation and the package the class resides in must have the
 *        <code>@XmlSchema</code> annotation with a non-null
 *        <code>namespace</code> property!
 * @param aXSDs
 *        The classpath relative paths to the XML Schema. May not be
 *        <code>null</code> but maybe empty. If the main XSD imports another
 *        XSD, the imported XSD must come first in the list. So the XSDs
 *        without any dependencies must come first!
 * @param aTypeToElementNameMapper
 *        An optional function to determine element name from type name. E.g.
 *        in UBL the type has an additional "Type" at the end that may not
 *        occur here. SBDH in contrary does not have such a suffix. May be
 *        <code>null</code> indicating that no name mapping is necessary.
 */
public JAXBDocumentType (@Nonnull final Class <?> aClass,
                         @Nullable final List <? extends ClassPathResource> aXSDs,
                         @Nullable final Function <? super String, ? extends String> aTypeToElementNameMapper)
{
  ValueEnforcer.notNull (aClass, "Class");
  if (aXSDs != null)
  {
    ValueEnforcer.notEmptyNoNullValue (aXSDs, "XSDs");
    for (final ClassPathResource aRes : aXSDs)
      ValueEnforcer.isTrue (aRes.hasClassLoader (),
                            () -> "ClassPathResource " + aRes + " should define its ClassLoader for OSGI handling!");
  }

  // Check whether it is an @XmlType class
  final XmlType aXmlType = aClass.getAnnotation (XmlType.class);
  if (aXmlType == null)
    throw new IllegalArgumentException ("The passed class '" +
                                        aClass.getName () +
                                        "' does not have an @XmlType annotation!");

  // Get the package of the passed Class
  final Package aPackage = aClass.getPackage ();

  // The package must have the annotation "XmlSchema" with the corresponding
  // namespace it supports (maybe empty but not null). If the base XSD does
  // not contain any namespace URI, the XMLSchema annotation might be missing!
  final XmlSchema aXmlSchema = aPackage.getAnnotation (XmlSchema.class);
  if (aXmlSchema != null && aXmlSchema.namespace () == null)
    throw new IllegalArgumentException ("The package '" +
                                        aPackage.getName () +
                                        "' has no namespace URI in the @XmlSchema annotation!");

  // Depending on the generation mode, the class may have the @XmlRootElement
  // annotation or not. If it is present, use the namespace URI and the local
  // name from it, else try to deduce the name from the type.
  String sNamespaceURI;
  String sLocalName;
  final XmlRootElement aRootElement = aClass.getAnnotation (XmlRootElement.class);
  if (aRootElement != null)
  {
    // Annotation is present
    sNamespaceURI = aRootElement.namespace ();
    if (JAXB_DEFAULT.equals (sNamespaceURI) && aXmlSchema != null)
      sNamespaceURI = aXmlSchema.namespace ();

    sLocalName = aRootElement.name ();
    if (JAXB_DEFAULT.equals (sLocalName))
      sLocalName = aXmlType.name ();
  }
  else
  {
    // Hack: build the element name from the type name
    if (aXmlSchema != null)
      sNamespaceURI = aXmlSchema.namespace ();
    else
      sNamespaceURI = null;
    sLocalName = aXmlType.name ();
  }
  // Call customizer (if provided)
  if (aTypeToElementNameMapper != null)
    sLocalName = aTypeToElementNameMapper.apply (sLocalName);
  if (StringHelper.hasNoText (sLocalName))
    throw new IllegalArgumentException ("Failed to determine the local name of the element to be created!");

  m_aClass = aClass;
  if (aXSDs != null)
    m_aXSDs.addAll (aXSDs);
  m_sNamespaceURI = StringHelper.getNotNull (sNamespaceURI);
  m_sLocalName = sLocalName;
}
 
Example 17
Source File: CSSKeyframesBlock.java    From ph-css with Apache License 2.0 4 votes vote down vote up
public CSSKeyframesBlock (@Nonnull @Nonempty final String... aKeyframesSelectors)
{
  ValueEnforcer.notEmptyNoNullValue (aKeyframesSelectors, "KeyframesSelectors");
  m_aKeyframesSelectors = new CommonsArrayList <> (aKeyframesSelectors);
}
 
Example 18
Source File: SchemaCache.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Get a cached {@link Schema} that consists of multiple resources.
 *
 * @param aResources
 *        The resources to parse into a single {@link Schema}. May neither
 *        <code>null</code> nor empty nor may it contain <code>null</code>
 *        elements.
 * @return Either the {@link Schema} from the cache or the newly compiled one.
 */
@Nonnull
public final Schema getSchema (@Nonnull @Nonempty final Collection <? extends IReadableResource> aResources)
{
  ValueEnforcer.notEmptyNoNullValue (aResources, "Resources");

  return getFromCache (new CommonsArrayList <> (aResources));
}
 
Example 19
Source File: SchemaCache.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Get a cached {@link Schema} that consists of multiple resources.
 *
 * @param aResources
 *        The resources to parse into a single {@link Schema}. May neither
 *        <code>null</code> nor empty nor may it contain <code>null</code>
 *        elements.
 * @return Either the {@link Schema} from the cache or the newly compiled one.
 */
@Nonnull
public final Schema getSchema (@Nonnull @Nonempty final IReadableResource... aResources)
{
  ValueEnforcer.notEmptyNoNullValue (aResources, "Resources");

  return getFromCache (new CommonsArrayList <> (aResources));
}
 
Example 20
Source File: JAXBContextCache.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Get the {@link JAXBContext} from existing {@link Class} objects and
 * optional JAXB Context properties.
 *
 * @param aClasses
 *        The classes for which the JAXB context is to be created. May not be
 *        <code>null</code> nor empty.
 * @param aProperties
 *        JAXB context properties. May be <code>null</code>.
 * @return May be <code>null</code>.
 * @since v9.4.2
 */
@Nullable
public JAXBContext getFromCache (@Nonnull final ICommonsList <Class <?>> aClasses,
                                 @Nullable final Map <String, ?> aProperties)
{
  ValueEnforcer.notEmptyNoNullValue (aClasses, "Classes");
  return getFromCache (new JAXBContextCacheKey (aClasses, aProperties));
}