Java Code Examples for com.helger.commons.string.StringHelper#getImploded()

The following examples show how to use com.helger.commons.string.StringHelper#getImploded() . 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: DefaultFolderTreeItemFactoryTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasic ()
{
  final DefaultFolderTreeItemFactory <String, String, List <String>> ftif = new DefaultFolderTreeItemFactory <> (x -> StringHelper.getImploded ('/',
                                                                                                                                                x));
  assertNotNull (ftif.createRoot ());
  try
  {
    ftif.createRoot ();
    fail ();
  }
  catch (final IllegalArgumentException ex)
  {}
}
 
Example 2
Source File: DefaultFolderTreeItemFactoryTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testEquals ()
{
  final IAggregator <String, String> aAggregator = x -> StringHelper.getImploded ('/', x);
  final DefaultFolderTreeItemFactory <String, String, List <String>> ftif = new DefaultFolderTreeItemFactory <> (aAggregator);
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (ftif,
                                                                     new DefaultFolderTreeItemFactory <> (aAggregator));
  // New aggregator - different object!
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (ftif,
                                                                         new DefaultFolderTreeItemFactory <> (x -> StringHelper.getImploded ('/',
                                                                                                                                             x)));
}
 
Example 3
Source File: DefaultFolderTreeTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasic ()
{
  final IAggregator <String, String> aCombinator = x -> StringHelper.getImploded ('/', x);
  final DefaultFolderTree <String, Integer, ICommonsSet <Integer>> ft = DefaultFolderTree.createForSet (aCombinator);
  assertNotNull (ft.getRootItem ());

  final DefaultFolderTreeItem <String, Integer, ICommonsSet <Integer>> i1 = ft.getRootItem ()
                                                                              .createChildItem ("id1",
                                                                                                PrimitiveCollectionHelper.newPrimitiveSet (1,
                                                                                                                                           2,
                                                                                                                                           3));
  assertNotNull (i1);

  final DefaultFolderTreeItem <String, Integer, ICommonsSet <Integer>> i2 = ft.getRootItem ()
                                                                              .createChildItem ("id1",
                                                                                                PrimitiveCollectionHelper.newPrimitiveSet (1,
                                                                                                                                           2,
                                                                                                                                           3));
  assertNotNull (i2);
  assertSame (i1, i2);

  final DefaultFolderTreeItem <String, Integer, ICommonsSet <Integer>> i3 = ft.getRootItem ()
                                                                              .createChildItem ("id3",
                                                                                                PrimitiveCollectionHelper.newPrimitiveSet (1,
                                                                                                                                           3));
  assertNotNull (i3);
  assertNotSame (i1, i3);

  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (i1, i3);
}
 
Example 4
Source File: HttpHeaderMap.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get the header value as a combination of all contained values
 *
 * @param sName
 *        The header name to retrieve. May be <code>null</code>.
 * @param sDelimiter
 *        The delimiter to be used. May not be <code>null</code>.
 * @return <code>null</code> if no such header is contained.
 */
@Nullable
public String getHeaderCombined (@Nullable final String sName, @Nonnull final String sDelimiter)
{
  if (StringHelper.hasText (sName))
  {
    final ICommonsList <String> aValues = _getHeaderList (sName);
    if (aValues != null)
      return StringHelper.getImploded (sDelimiter, aValues);
  }
  return null;
}
 
Example 5
Source File: IAggregatorTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetStringCombinatorWithSeparatorChar ()
{
  final IAggregator <String, String> c = x -> StringHelper.getImploded (',', x);
  assertEquals ("a,b", c.apply ("a", "b"));
  assertEquals ("a,null", c.apply ("a", null));
  assertEquals ("null,b", c.apply (null, "b"));
  assertEquals ("null,null", c.apply (null, null));
  assertEquals (",", c.apply ("", ""));
}
 
Example 6
Source File: IAggregatorTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetStringCombinatorWithSeparatorString ()
{
  final IAggregator <String, String> c = x -> StringHelper.getImploded (";", x);
  assertEquals ("a;b", c.apply ("a", "b"));
  assertEquals ("a;null", c.apply ("a", null));
  assertEquals ("null;b", c.apply (null, "b"));
  assertEquals ("null;null", c.apply (null, null));
  assertEquals (";", c.apply ("", ""));
}
 
Example 7
Source File: Kruskal.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
private static String _getWeightInfo (@Nonnull final IMutableGraphRelation aRel,
                                      @Nonnull @Nonempty final String sRelationCostAttr)
{
  return "{" +
         StringHelper.getImploded (',', new CommonsTreeSet <> (aRel.getAllConnectedNodeIDs ())) +
         ":" +
         aRel.attrs ().getAsInt (sRelationCostAttr) +
         "}";
}
 
Example 8
Source File: MainCreateJAXBBinding23.java    From ph-ubl with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String _convertToPackage (@Nonnull final String sNamespaceURI)
{
  // Lowercase everything
  String s = sNamespaceURI.toLowerCase (Locale.US);

  String [] aParts;
  final URL aURL = URLHelper.getAsURL (sNamespaceURI);
  if (aURL != null)
  {
    // Host
    String sHost = aURL.getHost ();

    // Kick static prefix: www.helger.com -> helger.com
    sHost = StringHelper.trimStart (sHost, "www.");

    // Reverse domain: helger.com -> com.helger
    final List <String> x = CollectionHelper.getReverseList (StringHelper.getExploded ('.', sHost));

    // Path in regular order:
    final String sPath = StringHelper.trimStart (aURL.getPath (), '/');
    x.addAll (StringHelper.getExploded ('/', sPath));

    // Convert to array
    aParts = ArrayHelper.newArray (x, String.class);
  }
  else
  {
    // Kick known prefixes
    for (final String sPrefix : new String [] { "urn:", "http://" })
      if (s.startsWith (sPrefix))
      {
        s = s.substring (sPrefix.length ());
        break;
      }

    // Replace all illegal characters
    s = StringHelper.replaceAll (s, ':', '.');
    s = StringHelper.replaceAll (s, '-', '_');
    aParts = StringHelper.getExplodedArray ('.', s);
  }

  // Split into pieces and replace all illegal package parts (e.g. only
  // numeric) with valid ones
  for (int i = 0; i < aParts.length; ++i)
    aParts[i] = RegExHelper.getAsIdentifier (aParts[i]);

  return StringHelper.getImploded (".", aParts);
}
 
Example 9
Source File: MainCreateJAXBBinding20.java    From ph-ubl with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String _convertToPackage (@Nonnull final String sNamespaceURI)
{
  // Lowercase everything
  String s = sNamespaceURI.toLowerCase (Locale.US);

  String [] aParts;
  final URL aURL = URLHelper.getAsURL (sNamespaceURI);
  if (aURL != null)
  {
    // Host
    String sHost = aURL.getHost ();

    // Kick static prefix: www.helger.com -> helger.com
    sHost = StringHelper.trimStart (sHost, "www.");

    // Reverse domain: helger.com -> com.helger
    final ICommonsList <String> x = StringHelper.getExploded ('.', sHost);
    x.reverse ();

    // Path in regular order:
    final String sPath = StringHelper.trimStart (aURL.getPath (), '/');
    x.addAll (StringHelper.getExploded ('/', sPath));

    // Convert to array
    aParts = ArrayHelper.newArray (x, String.class);
  }
  else
  {
    // Kick known prefixes
    for (final String sPrefix : new String [] { "urn:", "http://" })
      if (s.startsWith (sPrefix))
      {
        s = s.substring (sPrefix.length ());
        break;
      }

    // Replace all illegal characters
    s = StringHelper.replaceAll (s, ':', '.');
    s = StringHelper.replaceAll (s, '-', '_');
    aParts = StringHelper.getExplodedArray ('.', s);
  }

  // Split into pieces and replace all illegal package parts (e.g. only
  // numeric) with valid ones
  for (int i = 0; i < aParts.length; ++i)
    aParts[i] = RegExHelper.getAsIdentifier (aParts[i]);

  return StringHelper.getImploded (".", aParts);
}
 
Example 10
Source File: MainCreateJAXBBinding21.java    From ph-ubl with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String _convertToPackage (@Nonnull final String sNamespaceURI)
{
  // Lowercase everything
  String s = sNamespaceURI.toLowerCase (Locale.US);

  String [] aParts;
  final URL aURL = URLHelper.getAsURL (sNamespaceURI);
  if (aURL != null)
  {
    // Host
    String sHost = aURL.getHost ();

    // Kick static prefix: www.helger.com -> helger.com
    sHost = StringHelper.trimStart (sHost, "www.");

    // Reverse domain: helger.com -> com.helger
    final List <String> x = CollectionHelper.getReverseList (StringHelper.getExploded ('.', sHost));

    // Path in regular order:
    final String sPath = StringHelper.trimStart (aURL.getPath (), '/');
    x.addAll (StringHelper.getExploded ('/', sPath));

    // Convert to array
    aParts = ArrayHelper.newArray (x, String.class);
  }
  else
  {
    // Kick known prefixes
    for (final String sPrefix : new String [] { "urn:", "http://" })
      if (s.startsWith (sPrefix))
      {
        s = s.substring (sPrefix.length ());
        break;
      }

    // Replace all illegal characters
    s = StringHelper.replaceAll (s, ':', '.');
    s = StringHelper.replaceAll (s, '-', '_');
    aParts = StringHelper.getExplodedArray ('.', s);
  }

  // Split into pieces and replace all illegal package parts (e.g. only
  // numeric) with valid ones
  for (int i = 0; i < aParts.length; ++i)
    aParts[i] = RegExHelper.getAsIdentifier (aParts[i]);

  return StringHelper.getImploded (".", aParts);
}
 
Example 11
Source File: MainCreateJAXBBinding22.java    From ph-ubl with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String _convertToPackage (@Nonnull final String sNamespaceURI)
{
  // Lowercase everything
  String s = sNamespaceURI.toLowerCase (Locale.US);

  String [] aParts;
  final URL aURL = URLHelper.getAsURL (sNamespaceURI);
  if (aURL != null)
  {
    // Host
    String sHost = aURL.getHost ();

    // Kick static prefix: www.helger.com -> helger.com
    sHost = StringHelper.trimStart (sHost, "www.");

    // Reverse domain: helger.com -> com.helger
    final List <String> x = CollectionHelper.getReverseList (StringHelper.getExploded ('.', sHost));

    // Path in regular order:
    final String sPath = StringHelper.trimStart (aURL.getPath (), '/');
    x.addAll (StringHelper.getExploded ('/', sPath));

    // Convert to array
    aParts = ArrayHelper.newArray (x, String.class);
  }
  else
  {
    // Kick known prefixes
    for (final String sPrefix : new String [] { "urn:", "http://" })
      if (s.startsWith (sPrefix))
      {
        s = s.substring (sPrefix.length ());
        break;
      }

    // Replace all illegal characters
    s = StringHelper.replaceAll (s, ':', '.');
    s = StringHelper.replaceAll (s, '-', '_');
    aParts = StringHelper.getExplodedArray ('.', s);
  }

  // Split into pieces and replace all illegal package parts (e.g. only
  // numeric) with valid ones
  for (int i = 0; i < aParts.length; ++i)
    aParts[i] = RegExHelper.getAsIdentifier (aParts[i]);

  return StringHelper.getImploded (".", aParts);
}
 
Example 12
Source File: PSDir.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
@Nullable
public String getAsText ()
{
  return StringHelper.getImploded (m_aContent);
}
 
Example 13
Source File: PSEmph.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
@Nullable
public String getAsText ()
{
  return StringHelper.getImploded (m_aContent);
}
 
Example 14
Source File: PSSpan.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
@Nullable
public String getAsText ()
{
  return StringHelper.getImploded (m_aContent);
}
 
Example 15
Source File: PSP.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
@Nullable
public String getText ()
{
  return StringHelper.getImploded (m_aContent);
}
 
Example 16
Source File: SchematronResourceSCHCache.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
/**
 * Get the Schematron validator for the passed resource. If no custom
 * parameter are present, the result is cached. The respective cache key is a
 * combination of the Schematron resource path, the phase and the language
 * code.
 *
 * @param aSchematronResource
 *        The resource of the Schematron rules. May not be <code>null</code>.
 * @param aTransformerCustomizer
 *        The XSLT transformer customizer to be used. May not be
 *        <code>null</code>.
 * @return <code>null</code> if the passed Schematron resource does not exist
 *         or is invalid.
 */
@Nullable
public static SchematronProviderXSLTFromSCH getSchematronXSLTProvider (@Nonnull final IReadableResource aSchematronResource,
                                                                       @Nonnull final SCHTransformerCustomizer aTransformerCustomizer)
{
  ValueEnforcer.notNull (aSchematronResource, "SchematronResource");
  ValueEnforcer.notNull (aTransformerCustomizer, "TransformerCustomizer");

  if (!aSchematronResource.exists ())
  {
    LOGGER.warn ("Schematron resource " + aSchematronResource + " does not exist!");
    return null;
  }

  if (!aTransformerCustomizer.canCacheResult ())
  {
    // Create new object and return without cache handling because the custom
    // parameters may have side effects on the created XSLT!
    return createSchematronXSLTProvider (aSchematronResource, aTransformerCustomizer);
  }

  // Determine the unique resource ID for caching
  final String sCacheKey = StringHelper.<String> getImploded (':',
                                                              aSchematronResource.getResourceID (),
                                                              StringHelper.getNotNull (aTransformerCustomizer.getPhase ()),
                                                              StringHelper.getNotNull (aTransformerCustomizer.getLanguageCode ()));

  s_aLock.lock ();
  try
  {
    // Validator already in the cache?
    SchematronProviderXSLTFromSCH aProvider = s_aCache.get (sCacheKey);
    if (aProvider == null)
    {
      // Create new object and put in cache
      aProvider = createSchematronXSLTProvider (aSchematronResource, aTransformerCustomizer);
      if (aProvider != null)
        s_aCache.put (sCacheKey, aProvider);
    }
    return aProvider;
  }
  finally
  {
    s_aLock.unlock ();
  }
}
 
Example 17
Source File: CSVIteratorTest.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp ()
{
  m_aMockReader = new CSVReader (new NonBlockingStringReader (StringHelper.getImploded (',', STRINGS)));
}