下面列出了javax.annotation.concurrent.Immutable#com.helger.commons.annotation.ReturnsMutableCopy 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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;
}
@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 + "!");
}
}
@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;
}
/**
* 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;
}
/**
* 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);
}
@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;
}
/**
* 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;
}
/**
* 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;
}
@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;
}
@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;
}
@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 ();
}
@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;
}
@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);
}
/**
* @return List of references to {@link PSDiagnostic} elements.
*/
@Nonnull
@ReturnsMutableCopy
public ICommonsList <String> getAllDiagnostics ()
{
// May be null
return new CommonsArrayList <> (m_aDiagnostics);
}
@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);
}
@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;
}
@Override
@Nonnull
@ReturnsMutableCopy
public <K, V> CommonsWeakHashMap <K, V> createInstance ()
{
return new CommonsWeakHashMap <> ();
}
@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;
}
@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;
}
@Override
@Nonnull
@ReturnsMutableCopy
default ICommonsOrderedSet <KEYTYPE> copyOfKeySet (@Nullable final Predicate <? super KEYTYPE> aFilter)
{
if (aFilter == null)
return copyOfKeySet ();
return CollectionHelper.newOrderedSet (keySet (), aFilter);
}
@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);
}
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <String> getAllRelationIDs ()
{
final ICommonsOrderedSet <String> ret = new CommonsLinkedHashSet <> ();
if (m_aRelations != null)
ret.addAll (m_aRelations.keySet ());
return ret;
}
/**
* 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;
}
/**
* @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 ();
}
@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);
}
/**
* 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 >= 0!
* @return <code>null</code> if the passed array is <code>null</code> or has
* ≤ 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);
}
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <String> getAllExtensions ()
{
final ICommonsOrderedSet <String> ret = new CommonsLinkedHashSet <> ();
ret.addAllMapped (m_aExtensions, ExtensionWithSource::getExtension);
return ret;
}
/**
* @return A copy of all contained media queries. Never <code>null</code>.
* Maybe empty.
*/
@Nonnull
@ReturnsMutableCopy
public ICommonsList <CSSMediaQuery> getAllMediaQueries ()
{
return m_aMediaQueries.getClone ();
}
/**
* 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 >= 0!
* @return <code>null</code> if the passed array is <code>null</code> or has
* ≤ 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);
}
@Override
@Nonnull
@ReturnsMutableCopy
public <K, V> CommonsLinkedHashMap <K, V> createInstance ()
{
return new CommonsLinkedHashMap <> ();
}