com.helger.commons.annotation.ReturnsMutableCopy Java Examples

The following examples show how to use com.helger.commons.annotation.ReturnsMutableCopy. 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: XMLCharHelper.java    From ph-commons with 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 #2
Source File: Base64.java    From ph-commons with 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 #3
Source File: EigenvalueDecomposition.java    From ph-commons with 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 #4
Source File: SVRLHelper.java    From ph-schematron with 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 File: TextHelper.java    From ph-commons with 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 #6
Source File: ArrayHelper.java    From ph-commons with 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 #7
Source File: CollectionHelper.java    From ph-commons with 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 #8
Source File: QueueHelper.java    From ph-commons with 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 #9
Source File: ICommonsOrderedMap.java    From ph-commons with 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 #10
Source File: PrimitiveCollectionHelper.java    From ph-commons with 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 #11
Source File: CollectionHelper.java    From ph-commons with 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 #12
Source File: MultiHashMapLinkedHashSetBased.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@ReturnsMutableCopy
protected final CommonsLinkedHashSet <VALUETYPE> createNewCollection ()
{
  return new CommonsLinkedHashSet <> ();
}
 
Example #13
Source File: CommonsCopyOnWriteArrayList.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@ReturnsMutableCopy
public <T> CommonsCopyOnWriteArrayList <T> createInstance ()
{
  return new CommonsCopyOnWriteArrayList <> ();
}
 
Example #14
Source File: ArrayHelper.java    From ph-commons with 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 #15
Source File: XMLDebug.java    From ph-commons with 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 #16
Source File: StackHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static <ELEMENTTYPE> NonBlockingStack <ELEMENTTYPE> newStack (@Nullable final Collection <? extends ELEMENTTYPE> aCollection,
                                                                     @Nonnull final Predicate <? super ELEMENTTYPE> aFilter)
{
  if (CollectionHelper.isEmpty (aCollection))
    return newStack (0);
  final NonBlockingStack <ELEMENTTYPE> ret = newStack (aCollection.size ());
  CollectionHelper.findAll (aCollection, aFilter, ret::add);
  return ret;
}
 
Example #17
Source File: QueueHelper.java    From ph-commons with 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 #18
Source File: IErrorList.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get a sub-list with all entries that does not contain an error field name.
 *
 * @return Never <code>null</code>.
 */
@Nonnull
@ReturnsMutableCopy
default IErrorList getListWithoutField ()
{
  return getSubList (IError::hasNoErrorFieldName);
}
 
Example #19
Source File: VectorHelper.java    From ph-commons with 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 #20
Source File: PrimitiveCollectionHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static CommonsArrayList <Float> newPrimitiveList (@Nullable final float... aValues)
{
  final CommonsArrayList <Float> ret = new CommonsArrayList <> ();
  if (aValues != null)
    for (final float aValue : aValues)
      ret.add (Float.valueOf (aValue));
  return ret;
}
 
Example #21
Source File: PrimitiveCollectionHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public static CommonsLinkedHashSet <Boolean> newPrimitiveOrderedSet (@Nullable final boolean... aValues)
{
  final CommonsLinkedHashSet <Boolean> ret = new CommonsLinkedHashSet <> ();
  if (aValues != null)
    for (final boolean aValue : aValues)
      ret.add (Boolean.valueOf (aValue));
  return ret;
}
 
Example #22
Source File: GraphNode.java    From ph-commons with 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 File: LocaleCache.java    From ph-commons with 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 File: UBL22DocumentTypes.java    From ph-ubl with 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 File: Base64.java    From ph-commons with 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 File: ArrayHelper.java    From ph-commons with 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 File: MimeTypeInfo.java    From ph-commons with 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 File: PSAssertReport.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * @return A list of {@link String}, {@link PSName}, {@link PSValueOf},
 *         {@link PSEmph}, {@link PSDir} and {@link PSSpan} elements.
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsList <Object> getAllContentElements ()
{
  return m_aContent.getClone ();
}
 
Example #29
Source File: MimeTypeInfoManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get all infos associated with the passed mime type.
 *
 * @param aMimeType
 *        The mime type to search. May be <code>null</code>.
 * @return <code>null</code> if a <code>null</code> mime type was passed or
 *         the passed mime type is unknown.
 */
@Nullable
@ReturnsMutableCopy
public ICommonsList <MimeTypeInfo> getAllInfosOfMimeType (@Nullable final IMimeType aMimeType)
{
  if (aMimeType == null)
    return null;

  final ICommonsList <MimeTypeInfo> ret = m_aRWLock.readLockedGet ( () -> m_aMapMimeType.get (aMimeType));

  // Create a copy if present
  return ret == null ? null : ret.getClone ();
}
 
Example #30
Source File: CSSMediaRule.java    From ph-css with 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 ();
}