com.helger.commons.collection.impl.ICommonsOrderedSet Java Examples

The following examples show how to use com.helger.commons.collection.impl.ICommonsOrderedSet. 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: XMLCharHelper.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLTextChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                        @Nullable final char [] aChars,
                                                                        @Nonnegative final int nOfs,
                                                                        @Nonnegative final int nLen)
{
  if (aChars == null || nLen <= 0)
    return null;

  final ICommonsOrderedSet <Character> aRes = new CommonsLinkedHashSet <> ();
  for (int i = 0; i < nLen; ++i)
  {
    final char c = aChars[nOfs + i];
    if (isInvalidXMLTextChar (eXMLVersion, c))
      aRes.add (Character.valueOf (c));
  }
  return aRes;
}
 
Example #3
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLAttributeValueChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                                  @Nullable final char [] aChars,
                                                                                  @Nonnegative final int nOfs,
                                                                                  @Nonnegative final int nLen)
{
  if (aChars == null || nLen <= 0)
    return null;

  final ICommonsOrderedSet <Character> aRes = new CommonsLinkedHashSet <> ();
  for (int i = 0; i < nLen; ++i)
  {
    final char c = aChars[nOfs + i];
    if (isInvalidXMLAttributeValueChar (eXMLVersion, c))
      aRes.add (Character.valueOf (c));
  }
  return aRes;
}
 
Example #4
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 #5
Source File: LocaleCache.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Reset the cache to the initial state.
 */
public final void reinitialize ()
{
  final ICommonsOrderedSet <Locale> aDefLocales = getAllDefaultLocales ();

  // Update map
  m_aRWLock.writeLocked ( () -> {
    m_aLocales.clear ();
    for (final Locale aLocale : aDefLocales)
      m_aLocales.put (aLocale.toString (), aLocale);
  });

  if (!isSilentMode ())
    if (LOGGER.isDebugEnabled ())
      LOGGER.debug ("Reinitialized " + LocaleCache.class.getName ());
}
 
Example #6
Source File: IGetterByIndexTrait.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Get a set of all attribute values with the same name.
 *
 * @param nIndex
 *        The index to be accessed. Should be &ge; 0.
 * @param aDefault
 *        The default value to be returned, if no such attribute is present.
 * @return <code>aDefault</code> if no such attribute value exists
 */
@Nullable
default ICommonsOrderedSet <String> getAsStringSet (@Nonnegative final int nIndex,
                                                    @Nullable final ICommonsOrderedSet <String> aDefault)
{
  final Object aValue = getValue (nIndex);
  if (aValue != null)
  {
    if (aValue instanceof String [])
    {
      // multiple values passed in the request
      return new CommonsLinkedHashSet <> ((String []) aValue);
    }
    if (aValue instanceof String)
    {
      // single value passed in the request
      return new CommonsLinkedHashSet <> ((String) aValue);
    }
  }
  return aDefault;
}
 
Example #7
Source File: IGetterByKeyTrait.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Get a set of all attribute values with the same name.
 *
 * @param aKey
 *        The key to check. May be <code>null</code>.
 * @param aDefault
 *        The default value to be returned, if no such attribute is present.
 * @return <code>aDefault</code> if no such attribute value exists
 */
@Nullable
default ICommonsOrderedSet <String> getAsStringSet (@Nullable final KEYTYPE aKey,
                                                    @Nullable final ICommonsOrderedSet <String> aDefault)
{
  final Object aValue = getValue (aKey);
  if (aValue != null)
  {
    if (aValue instanceof String [])
    {
      // multiple values passed in the request
      return new CommonsLinkedHashSet <> ((String []) aValue);
    }
    if (aValue instanceof String)
    {
      // single value passed in the request
      return new CommonsLinkedHashSet <> ((String) aValue);
    }
  }
  return aDefault;
}
 
Example #8
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLCDATAChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                         @Nullable final char [] aChars,
                                                                         @Nonnegative final int nOfs,
                                                                         @Nonnegative final int nLen)
{
  if (aChars == null || nLen <= 0)
    return null;

  final ICommonsOrderedSet <Character> aRes = new CommonsLinkedHashSet <> ();
  for (int i = 0; i < nLen; ++i)
  {
    final char c = aChars[nOfs + i];
    if (isInvalidXMLCDATAChar (eXMLVersion, c))
      aRes.add (Character.valueOf (c));
  }
  return aRes;
}
 
Example #9
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLNameChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                        @Nullable final char [] aChars)
{
  return aChars == null || aChars.length == 0 ? null
                                              : getAllInvalidXMLNameChars (eXMLVersion, aChars, 0, aChars.length);
}
 
Example #10
Source File: Graph.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 <> ();
  for (final IMutableGraphNode aNode : m_aNodes.values ())
    ret.addAll (aNode.getAllRelationIDs ());
  return ret;
}
 
Example #11
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLNameChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                        @Nullable final String s)
{
  return s == null || s.length () == 0 ? null : getAllInvalidXMLNameChars (eXMLVersion, s.toCharArray ());
}
 
Example #12
Source File: MimeTypeInfoManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get all mime types that are associated to the specified filename extension.
 *
 * @param sExtension
 *        The filename extension to search. May not be <code>null</code>.
 * @return Never <code>null</code> but maybe empty set if no mime type is
 *         associated with the passed extension.
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <IMimeType> getAllMimeTypesForExtension (@Nonnull final String sExtension)
{
  ValueEnforcer.notNull (sExtension, "Extension");

  final ICommonsOrderedSet <IMimeType> ret = new CommonsLinkedHashSet <> ();
  final ICommonsList <MimeTypeInfo> aInfos = getAllInfosOfExtension (sExtension);
  if (aInfos != null)
    for (final MimeTypeInfo aInfo : aInfos)
      ret.addAll (aInfo.getAllMimeTypes ());
  return ret;
}
 
Example #13
Source File: MimeTypeInfoManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get all mime types that are associated to the specified filename extension.
 *
 * @param sExtension
 *        The filename extension to search. May not be <code>null</code>.
 * @return Never <code>null</code> but maybe empty set if no mime type is
 *         associated with the passed extension.
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <String> getAllMimeTypeStringsForExtension (@Nonnull final String sExtension)
{
  ValueEnforcer.notNull (sExtension, "Extension");

  final ICommonsOrderedSet <String> ret = new CommonsLinkedHashSet <> ();
  final ICommonsList <MimeTypeInfo> aInfos = getAllInfosOfExtension (sExtension);
  if (aInfos != null)
    for (final MimeTypeInfo aInfo : aInfos)
      ret.addAll (aInfo.getAllMimeTypeStrings ());
  return ret;
}
 
Example #14
Source File: MimeTypeInfoManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get all extensions associated to the specified mime type
 *
 * @param aMimeType
 *        The mime type to search. May be <code>null</code>.
 * @return Never <code>null</code> but empty set if no extensions are present.
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <String> getAllExtensionsOfMimeType (@Nullable final IMimeType aMimeType)
{
  final ICommonsOrderedSet <String> ret = new CommonsLinkedHashSet <> ();
  final ICommonsList <MimeTypeInfo> aInfos = getAllInfosOfMimeType (aMimeType);
  if (aInfos != null)
    for (final MimeTypeInfo aInfo : aInfos)
      ret.addAll (aInfo.getAllExtensions ());
  return ret;
}
 
Example #15
Source File: MimeTypeInfoManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get all globs (=filename patterns) associated to the specified mime type
 *
 * @param aMimeType
 *        The mime type to search. May be <code>null</code>.
 * @return Never <code>null</code> but empty set if no globs are present.
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <String> getAllGlobsOfMimeType (@Nullable final IMimeType aMimeType)
{
  final ICommonsOrderedSet <String> ret = new CommonsLinkedHashSet <> ();
  final ICommonsList <MimeTypeInfo> aInfos = getAllInfosOfMimeType (aMimeType);
  if (aInfos != null)
    for (final MimeTypeInfo aInfo : aInfos)
      ret.addAll (aInfo.getAllGlobs ());
  return ret;
}
 
Example #16
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 #17
Source File: MicroElement.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public ICommonsOrderedSet <IMicroQName> getAllAttributeQNames ()
{
  if (hasNoAttributes ())
    return null;
  return m_aAttrs.copyOfKeySet ();
}
 
Example #18
Source File: StringHelperTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testExplodeToOrderedSet ()
{
  ICommonsOrderedSet <String> ret = StringHelper.getExplodedToOrderedSet ("@", "a@b@@c");
  assertEquals (new CommonsHashSet <> ("a", "b", "", "c"), ret);
  ret = StringHelper.getExplodedToOrderedSet ("uu", "auubuuuuuuc");
  assertEquals (new CommonsHashSet <> ("a", "b", "", "", "c"), ret);
  ret = StringHelper.getExplodedToOrderedSet (".", "a.b...c");
  assertEquals (new CommonsHashSet <> ("a", "b", "", "", "c"), ret);
  ret = StringHelper.getExplodedToOrderedSet ("o", "boo:and:foo");
  assertEquals (new CommonsHashSet <> ("b", "", ":and:f", "", ""), ret);
  ret = StringHelper.getExplodedToOrderedSet ("@", "@a@b@@c");
  assertEquals (new CommonsHashSet <> ("", "a", "b", "", "c"), ret);
  ret = StringHelper.getExplodedToOrderedSet ("@", "a@b@@c@");
  assertEquals (new CommonsHashSet <> ("a", "b", "", "c", ""), ret);
  ret = StringHelper.getExplodedToOrderedSet ("@", "@a@b@@c@");
  assertEquals (new CommonsHashSet <> ("", "a", "b", "", "c", ""), ret);
  assertTrue (StringHelper.getExplodedToOrderedSet ("@", null).isEmpty ());

  try
  {
    StringHelper.getExplodedToOrderedSet (null, "@a@b@@c@");
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example #19
Source File: GraphNode.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <String> getAllRelatedNodeIDs ()
{
  final ICommonsOrderedSet <String> ret = new CommonsLinkedHashSet <> ();
  if (m_aRelations != null)
    for (final IMutableGraphRelation aRelation : m_aRelations.values ())
    {
      ret.add (aRelation.getNode1ID ());
      ret.add (aRelation.getNode2ID ());
    }
  return ret;
}
 
Example #20
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLNameChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                        @Nullable final char [] aChars,
                                                                        @Nonnegative final int nOfs,
                                                                        @Nonnegative final int nLen)
{
  if (aChars == null || nLen <= 0)
    return null;

  final ICommonsOrderedSet <Character> aRes = new CommonsLinkedHashSet <> ();
  int nIndex = 0;
  for (int i = 0; i < nLen; ++i)
  {
    final char c = aChars[nOfs + i];
    if (nIndex == 0)
    {
      if (isInvalidXMLNameStartChar (eXMLVersion, c))
        aRes.add (Character.valueOf (c));
    }
    else
    {
      if (isInvalidXMLNameChar (eXMLVersion, c))
        aRes.add (Character.valueOf (c));
    }
    ++nIndex;
  }
  return aRes;
}
 
Example #21
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLTextChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                        @Nullable final String s)
{
  return s == null || s.length () == 0 ? null
                                       : getAllInvalidXMLTextChars (eXMLVersion, s.toCharArray (), 0, s.length ());
}
 
Example #22
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLTextChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                        @Nullable final char [] aChars)
{
  return aChars == null || aChars.length == 0 ? null
                                              : getAllInvalidXMLTextChars (eXMLVersion, aChars, 0, aChars.length);
}
 
Example #23
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLCDATAChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                         @Nullable final String s)
{
  return s == null || s.length () == 0 ? null
                                       : getAllInvalidXMLCDATAChars (eXMLVersion, s.toCharArray (), 0, s.length ());
}
 
Example #24
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLCDATAChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                         @Nullable final char [] aChars)
{
  return aChars == null || aChars.length == 0 ? null
                                              : getAllInvalidXMLCDATAChars (eXMLVersion, aChars, 0, aChars.length);
}
 
Example #25
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLAttributeValueChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                                  @Nullable final String s)
{
  return s == null ||
         s.length () == 0 ? null
                          : getAllInvalidXMLAttributeValueChars (eXMLVersion, s.toCharArray (), 0, s.length ());
}
 
Example #26
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLAttributeValueChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                                  @Nullable final char [] aChars)
{
  return aChars == null ||
         aChars.length == 0 ? null : getAllInvalidXMLAttributeValueChars (eXMLVersion, aChars, 0, aChars.length);
}
 
Example #27
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                    @Nonnull final EXMLCharMode eXMLCharMode,
                                                                    @Nullable final String s)
{
  return s == null ||
         s.length () == 0 ? null
                          : getAllInvalidXMLChars (eXMLVersion, eXMLCharMode, s.toCharArray (), 0, s.length ());
}
 
Example #28
Source File: XMLCharHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public static ICommonsOrderedSet <Character> getAllInvalidXMLChars (@Nonnull final EXMLSerializeVersion eXMLVersion,
                                                                    @Nonnull final EXMLCharMode eXMLCharMode,
                                                                    @Nullable final char [] aChars)
{
  return aChars == null ||
         aChars.length == 0 ? null : getAllInvalidXMLChars (eXMLVersion, eXMLCharMode, aChars, 0, aChars.length);
}
 
Example #29
Source File: MimeTypeInfoManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @return A non-<code>null</code> set with all mime types known to this
 *         instance.
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <IMimeType> getAllMimeTypes ()
{
  final ICommonsOrderedSet <IMimeType> ret = new CommonsLinkedHashSet <> ();
  m_aRWLock.readLocked ( () -> m_aList.forEach (i -> ret.addAll (i.getAllMimeTypes ())));
  return ret;
}
 
Example #30
Source File: MimeTypeInfoManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @return A non-<code>null</code> set with all mime types known to this
 *         instance.
 */
@Nonnull
@ReturnsMutableCopy
public ICommonsOrderedSet <String> getAllMimeTypeStrings ()
{
  final ICommonsOrderedSet <String> ret = new CommonsLinkedHashSet <> ();
  m_aRWLock.readLocked ( () -> m_aList.forEach (i -> ret.addAll (i.getAllMimeTypeStrings ())));
  return ret;
}