Java Code Examples for com.helger.commons.annotation.ReturnsMutableCopy

The following examples show how to use com.helger.commons.annotation.ReturnsMutableCopy. These examples are extracted from open source projects. 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 Project: ph-commons   Source File: Base64.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Decode the string with the default encoding (US-ASCII is the preferred
 * one).
 *
 * @param sEncoded
 *        The encoded string.
 * @param nOptions
 *        Decoding options.
 * @return <code>null</code> if decoding failed.
 */
@Nullable
@ReturnsMutableCopy
public static byte [] safeDecode (@Nullable final String sEncoded, final int nOptions)
{
  if (sEncoded != null)
    try
    {
      return decode (sEncoded, nOptions);
    }
    catch (final Exception ex)
    {
      // fall through
    }
  return null;
}
 
Example 2
Source Project: ph-commons   Source File: XMLCharHelper.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                    @Nonnull final EXMLCharMode eXMLCharMode,
                                                                    @Nullable final char [] aChars,
                                                                    @Nonnegative final int nOfs,
                                                                    @Nonnegative final int nLen)
{
  switch (eXMLCharMode)
  {
    case ELEMENT_NAME:
    case ATTRIBUTE_NAME:
      return getAllInvalidXMLNameChars (eXMLVersion, aChars, nOfs, nLen);
    case ATTRIBUTE_VALUE_DOUBLE_QUOTES:
    case ATTRIBUTE_VALUE_SINGLE_QUOTES:
      return getAllInvalidXMLAttributeValueChars (eXMLVersion, aChars, nOfs, nLen);
    case TEXT:
      return getAllInvalidXMLTextChars (eXMLVersion, aChars, nOfs, nLen);
    case CDATA:
      return getAllInvalidXMLCDATAChars (eXMLVersion, aChars, nOfs, nLen);
    default:
      throw new IllegalArgumentException ("Unsupported XML character mode " + eXMLCharMode + "!");
  }
}
 
Example 3
Source Project: ph-commons   Source File: TextHelper.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static MultilingualText createMultilingualTextFromMap (@Nonnull final Map <String, String> aMap)
{
  ValueEnforcer.notNull (aMap, "Map");

  final MultilingualText ret = new MultilingualText ();
  final LocaleCache aLC = LocaleCache.getInstance ();
  for (final Map.Entry <String, String> aEntry : aMap.entrySet ())
  {
    final String sText = aEntry.getValue ();
    if (sText != null)
      ret.setText (aLC.getLocale (aEntry.getKey ()), sText);
  }
  return ret;
}
 
Example 4
Source Project: ph-schematron   Source File: SVRLHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get a list of all failed assertions in a given schematron output, with an
 * error level equally or more severe than the passed error level.
 *
 * @param aSchematronOutput
 *        The schematron output to be used. May be <code>null</code>.
 * @param aErrorLevel
 *        Minimum error level to be queried
 * @return A non-<code>null</code> list with all failed assertions.
 */
@Nonnull
@ReturnsMutableCopy
public static ICommonsList <SVRLFailedAssert> getAllFailedAssertionsMoreOrEqualSevereThan (@Nullable final SchematronOutputType aSchematronOutput,
                                                                                           @Nonnull final IErrorLevel aErrorLevel)
{
  final ICommonsList <SVRLFailedAssert> ret = new CommonsArrayList <> ();
  if (aSchematronOutput != null)
    for (final Object aObj : aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert ())
      if (aObj instanceof FailedAssert)
      {
        final SVRLFailedAssert aFA = new SVRLFailedAssert ((FailedAssert) aObj);
        if (aFA.getFlag ().isGE (aErrorLevel))
          ret.add (aFA);
      }
  return ret;
}
 
Example 5
Source Project: ph-commons   Source File: ArrayHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get an array that contains all elements, except for the passed elements.
 *
 * @param <ELEMENTTYPE>
 *        Array element type
 * @param aArray
 *        The source array. May be <code>null</code>.
 * @param aElementsToRemove
 *        The elements to skip.
 * @return <code>null</code> if the passed array is <code>null</code>. The
 *         original array, if no elements need to be skipped. A non-
 *         <code>null</code> copy of the array without the passed elements
 *         otherwise.
 */
@Nullable
@ReturnsMutableCopy
@SafeVarargs
public static <ELEMENTTYPE> ELEMENTTYPE [] getAllExcept (@Nullable final ELEMENTTYPE [] aArray,
                                                         @Nullable final ELEMENTTYPE... aElementsToRemove)
{
  if (isEmpty (aArray) || isEmpty (aElementsToRemove))
    return aArray;

  final ELEMENTTYPE [] tmp = getCopy (aArray);
  int nDst = 0;
  for (int nSrc = 0; nSrc < tmp.length; ++nSrc)
    if (!contains (aElementsToRemove, tmp[nSrc]))
      tmp[nDst++] = tmp[nSrc];
  return getCopy (tmp, 0, nDst);
}
 
Example 6
Source Project: ph-commons   Source File: CollectionHelper.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
@SafeVarargs
public static <ELEMENTTYPE extends Comparable <? super ELEMENTTYPE>> CommonsTreeMap <ELEMENTTYPE, ELEMENTTYPE> newSortedMap (@Nullable final ELEMENTTYPE... aValues)
{
  if (ArrayHelper.isEmpty (aValues))
    return newSortedMap ();

  if ((aValues.length % 2) != 0)
    throw new IllegalArgumentException ("The passed array needs an even number of elements!");

  final CommonsTreeMap <ELEMENTTYPE, ELEMENTTYPE> ret = newSortedMap ();
  for (int i = 0; i < aValues.length; i += 2)
    ret.put (aValues[i], aValues[i + 1]);
  return ret;
}
 
Example 7
Source Project: ph-commons   Source File: EigenvalueDecomposition.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return the block diagonal eigenvalue matrix
 *
 * @return D
 */
@Nonnull
@ReturnsMutableCopy
public Matrix getD ()
{
  final Matrix aNewMatrix = new Matrix (m_nDim, m_nDim);
  final double [] [] aNewArray = aNewMatrix.internalGetArray ();
  for (int nRow = 0; nRow < m_nDim; nRow++)
  {
    final double [] aDstRow = aNewArray[nRow];
    Arrays.fill (aDstRow, 0.0);
    aDstRow[nRow] = m_aEVd[nRow];

    final double dEVe = m_aEVe[nRow];
    if (dEVe > 0)
      aDstRow[nRow + 1] = dEVe;
    else
      if (dEVe < 0)
        aDstRow[nRow - 1] = dEVe;
  }
  return aNewMatrix;
}
 
Example 8
Source Project: ph-commons   Source File: ArrayHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get a new array that combines the passed head element and the array. The
 * head element will be the first element of the created array.
 *
 * @param aHead
 *        The first element of the result array.
 * @param aTailArray
 *        The tail array. May be <code>null</code>.
 * @return A non-<code>null</code> array with all elements in the correct
 *         order.
 */
@Nonnull
@ReturnsMutableCopy
public static char [] getConcatenated (final char aHead, @Nullable final char... aTailArray)
{
  if (isEmpty (aTailArray))
    return new char [] { aHead };

  final char [] ret = new char [1 + aTailArray.length];
  ret[0] = aHead;
  System.arraycopy (aTailArray, 0, ret, 1, aTailArray.length);
  return ret;
}
 
Example 9
Source Project: ph-commons   Source File: QueueHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <SRCTYPE, DSTTYPE> PriorityQueue <DSTTYPE> newQueueMapped (@Nullable final Collection <? extends SRCTYPE> aCollection,
                                                                         @Nonnull final Function <? super SRCTYPE, DSTTYPE> aMapper)
{
  if (CollectionHelper.isEmpty (aCollection))
    return newQueue (0);
  final PriorityQueue <DSTTYPE> ret = newQueue (aCollection.size ());
  for (final SRCTYPE aValue : aCollection)
    ret.add (aMapper.apply (aValue));
  return ret;
}
 
Example 10
Source Project: ph-schematron   Source File: PSLet.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static PSLet create (@Nullable final String sName, @Nullable final String sValue)
{
  final PSLet ret = new PSLet ();
  ret.setName (sName);
  ret.setValue (sValue);
  return ret;
}
 
Example 11
Source Project: ph-commons   Source File: XMLDebug.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsList <String> getAllSupportedFeatures (@Nonnull final EXMLDOMFeatureVersion eFeatureVersion)
{
  final ICommonsList <String> ret = s_aSupportedFeatures.get (eFeatureVersion);
  return ret == null ? null : ret.getClone ();
}
 
Example 12
Source Project: ph-commons   Source File: QueueHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <ELEMENTTYPE> PriorityQueue <ELEMENTTYPE> newQueue (@Nullable final Iterator <? extends ELEMENTTYPE> aIter)
{
  final PriorityQueue <ELEMENTTYPE> ret = newQueue ();
  if (aIter != null)
    while (aIter.hasNext ())
      ret.add (aIter.next ());
  return ret;
}
 
Example 13
Source Project: ph-commons   Source File: MimeTypeInfoManager.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public ICommonsList <MimeTypeInfo> getAllInfosOfFilename (@Nullable final String sFilename)
{
  if (StringHelper.hasNoText (sFilename))
    return null;

  final String sExtension = FilenameHelper.getExtension (sFilename);
  return getAllInfosOfExtension (sExtension);
}
 
Example 14
Source Project: ph-schematron   Source File: PSAssertReport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return List of references to {@link PSDiagnostic} elements.
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsList <String> getAllDiagnostics ()
{
  // May be null
  return new CommonsArrayList <> (m_aDiagnostics);
}
 
Example 15
Source Project: ph-commons   Source File: XMLWriterSettings.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static XMLWriterSettings createForHTML4 ()
{
  return new XMLWriterSettings ().setSerializeVersion (EXMLSerializeVersion.HTML)
                                 .setSerializeXMLDeclaration (EXMLSerializeXMLDeclaration.IGNORE)
                                 .setIndentDeterminator (new XMLIndentDeterminatorHTML ())
                                 .setBracketModeDeterminator (new XMLBracketModeDeterminatorHTML4 ())
                                 .setSpaceOnSelfClosedElement (true)
                                 .setPutNamespaceContextPrefixesInRoot (true);
}
 
Example 16
Source Project: ph-commons   Source File: CollectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <KEYTYPE extends Comparable <? super KEYTYPE>, VALUETYPE> CommonsTreeMap <KEYTYPE, VALUETYPE> newSortedMap (@Nullable final Collection <? extends Map.Entry <KEYTYPE, VALUETYPE>> aCollection)
{
  if (isEmpty (aCollection))
    return newSortedMap ();

  final CommonsTreeMap <KEYTYPE, VALUETYPE> ret = newSortedMap ();
  ret.putAll (aCollection);
  return ret;
}
 
Example 17
Source Project: ph-commons   Source File: CommonsWeakHashMap.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@ReturnsMutableCopy
public <K, V> CommonsWeakHashMap <K, V> createInstance ()
{
  return new CommonsWeakHashMap <> ();
}
 
Example 18
Source Project: ph-commons   Source File: CollectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <KEYTYPE, VALUETYPE> CommonsLinkedHashMap <KEYTYPE, VALUETYPE> newOrderedMap (@Nullable final Map <? extends KEYTYPE, ? extends VALUETYPE> [] aMaps)
{
  if (ArrayHelper.isEmpty (aMaps))
    return newOrderedMap (0);

  final CommonsLinkedHashMap <KEYTYPE, VALUETYPE> ret = newOrderedMap ();
  for (final Map <? extends KEYTYPE, ? extends VALUETYPE> aMap : aMaps)
    ret.putAll (aMap);
  return ret;
}
 
Example 19
Source Project: ph-commons   Source File: PrimitiveCollectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static CommonsTreeSet <Float> newPrimitiveSortedSet (@Nullable final float... aValues)
{
  final CommonsTreeSet <Float> ret = new CommonsTreeSet <> ();
  if (aValues != null)
    for (final float aValue : aValues)
      ret.add (Float.valueOf (aValue));
  return ret;
}
 
Example 20
Source Project: ph-commons   Source File: ICommonsOrderedMap.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@ReturnsMutableCopy
default ICommonsOrderedSet <KEYTYPE> copyOfKeySet (@Nullable final Predicate <? super KEYTYPE> aFilter)
{
  if (aFilter == null)
    return copyOfKeySet ();
  return CollectionHelper.newOrderedSet (keySet (), aFilter);
}
 
Example 21
Source Project: ph-commons   Source File: VectorHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <ELEMENTTYPE> CommonsVector <ELEMENTTYPE> newVector (@Nullable final Collection <? extends ELEMENTTYPE> aCont)
{
  if (CollectionHelper.isEmpty (aCont))
    return newVector (0);

  return new CommonsVector <> (aCont);
}
 
Example 22
Source Project: ph-commons   Source File: GraphNode.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <String> getAllRelationIDs ()
{
  final ICommonsOrderedSet <String> ret = new CommonsLinkedHashSet <> ();
  if (m_aRelations != null)
    ret.addAll (m_aRelations.keySet ());
  return ret;
}
 
Example 23
Source Project: ph-commons   Source File: LocaleCache.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get all contained locales that consist only of a non-empty language.
 *
 * @return a set with all contained languages, except "all" and "independent"
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsSet <Locale> getAllLanguages ()
{
  final ICommonsSet <Locale> ret = new CommonsHashSet <> ();
  for (final Locale aLocale : getAllLocales ())
  {
    final String sLanguage = aLocale.getLanguage ();
    if (StringHelper.hasText (sLanguage))
      ret.add (getLocale (sLanguage, null, null));
  }
  return ret;
}
 
Example 24
Source Project: ph-ubl   Source File: UBL22DocumentTypes.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return A non-<code>null</code> set of all supported UBL 2.2 namespaces.
 */
@Nonnull
@ReturnsMutableCopy
public static ICommonsSet <String> getAllNamespaces ()
{
  return s_aNamespace2DocType.copyOfKeySet ();
}
 
Example 25
Source Project: ph-commons   Source File: Base64.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static byte [] safeEncodeBytesToBytes (@Nullable final byte [] aDecoded,
                                              @Nonnegative final int nOfs,
                                              @Nonnegative final int nLen)
{
  return safeEncodeBytesToBytes (aDecoded, nOfs, nLen, NO_OPTIONS);
}
 
Example 26
Source Project: ph-commons   Source File: ArrayHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get an array that contains all elements, except for the last <em>n</em>
 * elements.
 *
 * @param aArray
 *        The source array. May be <code>null</code>.
 * @param nElementsToSkip
 *        The number of elements to skip. Must be &gt;= 0!
 * @return <code>null</code> if the passed array is <code>null</code> or has
 *         &le; elements than elements to be skipped. A non-<code>null</code>
 *         copy of the array without the last elements otherwise.
 */
@Nullable
@ReturnsMutableCopy
public static byte [] getAllExceptLast (@Nullable final byte [] aArray, @Nonnegative final int nElementsToSkip)
{
  ValueEnforcer.isGE0 (nElementsToSkip, "ElementsToSkip");

  if (nElementsToSkip == 0)
    return aArray;
  if (aArray == null || nElementsToSkip >= aArray.length)
    return null;
  return getCopy (aArray, 0, aArray.length - nElementsToSkip);
}
 
Example 27
Source Project: ph-commons   Source File: MimeTypeInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <String> getAllExtensions ()
{
  final ICommonsOrderedSet <String> ret = new CommonsLinkedHashSet <> ();
  ret.addAllMapped (m_aExtensions, ExtensionWithSource::getExtension);
  return ret;
}
 
Example 28
Source Project: ph-css   Source File: CSSMediaRule.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return A copy of all contained media queries. Never <code>null</code>.
 *         Maybe empty.
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsList <CSSMediaQuery> getAllMediaQueries ()
{
  return m_aMediaQueries.getClone ();
}
 
Example 29
Source Project: ph-commons   Source File: ArrayHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get an array that contains all elements, except for the first <em>n</em>
 * elements.
 *
 * @param aArray
 *        The source array. May be <code>null</code>.
 * @param nElementsToSkip
 *        The number of elements to skip. Must be &gt;= 0!
 * @return <code>null</code> if the passed array is <code>null</code> or has
 *         &le; elements than elements to be skipped. A non-<code>null</code>
 *         copy of the array without the first elements otherwise.
 */
@Nullable
@ReturnsMutableCopy
public static char [] getAllExceptFirst (@Nullable final char [] aArray, @Nonnegative final int nElementsToSkip)
{
  ValueEnforcer.isGE0 (nElementsToSkip, "ElementsToSkip");

  if (nElementsToSkip == 0)
    return aArray;
  if (aArray == null || nElementsToSkip >= aArray.length)
    return null;
  return getCopy (aArray, nElementsToSkip, aArray.length - nElementsToSkip);
}
 
Example 30
Source Project: ph-commons   Source File: CommonsLinkedHashMap.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@ReturnsMutableCopy
public <K, V> CommonsLinkedHashMap <K, V> createInstance ()
{
  return new CommonsLinkedHashMap <> ();
}