Java Code Examples for com.helger.commons.collection.impl.ICommonsList#isNotEmpty()

The following examples show how to use com.helger.commons.collection.impl.ICommonsList#isNotEmpty() . 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: MicroDocument.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Override
protected void onAppendChild (@Nonnull final AbstractMicroNode aChildNode)
{
  if (!_canBeAppendedToDocumentRoot (aChildNode))
    throw new MicroException ("Cannot add nodes of type " + aChildNode + " to a document");

  // Ensure that only one element is appended to the document root
  if (aChildNode.isElement ())
  {
    final ICommonsList <IMicroNode> aChildren = directGetAllChildren ();
    if (aChildren != null && aChildren.isNotEmpty ())
      for (final IMicroNode aCurChild : aChildren)
        if (aCurChild.isElement ())
          throw new MicroException ("A document can only have one document element! Already has " +
                                    aCurChild +
                                    " and wants to add " +
                                    aChildNode);
  }
  super.onAppendChild (aChildNode);
}
 
Example 2
Source File: Graph.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public boolean containsCycles ()
{
  // Use cached result?
  if (m_eCacheHasCycles.isUndefined ())
  {
    m_eCacheHasCycles = ETriState.FALSE;
    // Check all nodes, in case we a small cycle and a set of other nodes (see
    // test case testCycles2)
    final ICommonsList <IMutableGraphNode> aAllNodes = m_aNodes.copyOfValues ();
    while (aAllNodes.isNotEmpty ())
    {
      // Iterate from the first node
      final GraphIterator it = new GraphIterator (aAllNodes.removeFirst ());
      if (it.hasCycles ())
      {
        m_eCacheHasCycles = ETriState.TRUE;
        break;
      }
      while (it.hasNext ())
      {
        // Remove from remaining list, because node is reachable from some
        // other node
        aAllNodes.remove (it.next ());
      }
    }
  }

  // cannot be undefined here
  return m_eCacheHasCycles.getAsBooleanValue (true);
}
 
Example 3
Source File: MimeTypeInfoManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get the primary (=first) mime type that is associated to the specified
 * filename extension.
 *
 * @param sExtension
 *        The filename extension to search. May not be <code>null</code>.
 * @return <code>null</code> if no mime type is associated with the passed
 *         extension.
 */
@Nullable
public IMimeType getPrimaryMimeTypeForExtension (@Nonnull final String sExtension)
{
  ValueEnforcer.notNull (sExtension, "Extension");

  final ICommonsList <MimeTypeInfo> aInfos = getAllInfosOfExtension (sExtension);
  if (aInfos != null && aInfos.isNotEmpty ())
    return aInfos.getFirst ().getPrimaryMimeType ();
  return null;
}
 
Example 4
Source File: MimeTypeInfoManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get the primary (=first) mime type that is associated to the specified
 * filename extension.
 *
 * @param sExtension
 *        The filename extension to search. May not be <code>null</code>.
 * @return <code>null</code> if no mime type is associated with the passed
 *         extension.
 */
@Nullable
public String getPrimaryMimeTypeStringForExtension (@Nonnull final String sExtension)
{
  ValueEnforcer.notNull (sExtension, "Extension");

  final ICommonsList <MimeTypeInfo> aInfos = getAllInfosOfExtension (sExtension);
  if (aInfos != null && aInfos.isNotEmpty ())
    return aInfos.getFirst ().getPrimaryMimeTypeString ();
  return null;
}
 
Example 5
Source File: PDTDisplayHelper.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Nonempty
public static String getPeriodText (final int nYears,
                                    final int nMonths,
                                    final int nDays,
                                    final long nHours,
                                    final long nMinutes,
                                    final long nSeconds,
                                    @Nonnull final IPeriodTextProvider aTextProvider)
{
  final String sYear = aTextProvider.getYears (nYears);
  final String sMonth = aTextProvider.getMonths (nMonths);
  final String sDay = aTextProvider.getDays (nDays);
  final String sHour = aTextProvider.getHours (nHours);
  final String sMinute = aTextProvider.getMinutes (nMinutes);
  final String sSecond = aTextProvider.getSeconds (nSeconds);

  // Skip all "leading 0" parts
  final ICommonsList <String> aParts = new CommonsArrayList <> (6);
  if (nYears != 0)
    aParts.add (sYear);
  if (nMonths != 0 || aParts.isNotEmpty ())
    aParts.add (sMonth);
  if (nDays != 0 || aParts.isNotEmpty ())
    aParts.add (sDay);
  if (nHours != 0 || aParts.isNotEmpty ())
    aParts.add (sHour);
  if (nMinutes != 0 || aParts.isNotEmpty ())
    aParts.add (sMinute);
  aParts.add (sSecond);

  final int nParts = aParts.size ();
  if (nParts == 1)
    return aParts.get (0);
  if (nParts == 2)
    return aParts.get (0) + aTextProvider.getAnd () + aParts.get (1);

  final StringBuilder aSB = new StringBuilder ();
  for (int i = 0; i < nParts - 1; ++i)
  {
    if (aSB.length () > 0)
      aSB.append (aTextProvider.getComma ());
    aSB.append (aParts.get (i));
  }
  return aSB.append (aTextProvider.getAnd ()).append (aParts.getLast ()).toString ();
}