Java Code Examples for com.helger.commons.ValueEnforcer#isGT0()

The following examples show how to use com.helger.commons.ValueEnforcer#isGT0() . 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: SizeFloat.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Return the scaled width and height relative to a maximum size.
 *
 * @param dMaxWidth
 *        Maximum width. Must be > 0.
 * @param dMaxHeight
 *        Maximum height. Must be > 0.
 * @return An array with 2 elements, where the first element is the width, and
 *         the second is the height.
 */
@Nonnull
@CheckReturnValue
public SizeFloat getBestMatchingSize (@Nonnegative final float dMaxWidth, @Nonnegative final float dMaxHeight)
{
  ValueEnforcer.isGT0 (dMaxWidth, "MaxWidth");
  ValueEnforcer.isGT0 (dMaxHeight, "MaxHeight");

  final float dRelWidth = m_dWidth / dMaxWidth;
  final float dRelHeight = m_dHeight / dMaxHeight;
  if (dRelWidth > dRelHeight)
  {
    if (m_dWidth > dMaxWidth)
      return new SizeFloat (dMaxWidth, m_dHeight / dRelWidth);
  }
  else
  {
    if (m_dHeight > dMaxHeight)
      return new SizeFloat (m_dWidth / dRelHeight, dMaxHeight);
  }
  return this;
}
 
Example 2
Source File: SizeInt.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Return the scaled width and height relative to a maximum size.
 *
 * @param nMaxWidth
 *        Maximum width. Must be > 0.
 * @param nMaxHeight
 *        Maximum height. Must be > 0.
 * @return An array with 2 elements, where the first element is the width, and
 *         the second is the height.
 */
@Nonnull
@CheckReturnValue
public SizeInt getBestMatchingSize (@Nonnegative final int nMaxWidth, @Nonnegative final int nMaxHeight)
{
  ValueEnforcer.isGT0 (nMaxWidth, "MaxWidth");
  ValueEnforcer.isGT0 (nMaxHeight, "MaxHeight");

  final double dRelWidth = MathHelper.getDividedDouble (m_nWidth, nMaxWidth);
  final double dRelHeight = MathHelper.getDividedDouble (m_nHeight, nMaxHeight);
  if (dRelWidth > dRelHeight)
  {
    if (m_nWidth > nMaxWidth)
      return new SizeInt (nMaxWidth, (int) (m_nHeight / dRelWidth));
  }
  else
  {
    if (m_nHeight > nMaxHeight)
      return new SizeInt ((int) (m_nWidth / dRelHeight), nMaxHeight);
  }
  return this;
}
 
Example 3
Source File: GlobalIDFactory.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @param nCount
 *        The number of IDs to retrieve. Must be > 0.
 * @return An array of new persistent String IDs
 */
@Nonnull
public static String [] getBulkNewPersistentStringIDs (@Nonnegative final int nCount)
{
  ValueEnforcer.isGT0 (nCount, "Count");

  return s_aRWLock.readLockedGet ( () -> {
    if (s_aPersistentStringIDFactory == null)
      throw new IllegalStateException ("No persistent string ID factory has been supplied!");
    final String [] ret = new String [nCount];
    for (int i = 0; i < nCount; ++i)
      ret[i] = s_aPersistentStringIDFactory.getNewID ();
    return ret;
  });
}
 
Example 4
Source File: GlobalIDFactory.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @param nCount
 *        The number of IDs to retrieve
 * @return An array of new String IDs
 */
@Nonnull
public static String [] getBulkNewStringIDs (@Nonnegative final int nCount)
{
  ValueEnforcer.isGT0 (nCount, "Count");

  return s_aRWLock.readLockedGet ( () -> {
    if (s_aStringIDFactory == null)
      throw new IllegalStateException ("No in-memory string ID factory has been supplied!");
    final String [] ret = new String [nCount];
    for (int i = 0; i < nCount; ++i)
      ret[i] = s_aStringIDFactory.getNewID ();
    return ret;
  });
}
 
Example 5
Source File: GlobalIDFactory.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @param nCount
 *        The number of IDs to retrieve. Must be &gt; 0.
 * @return An array of new persistent long IDs
 */
public static long [] getBulkNewPersistentLongIDs (@Nonnegative final int nCount)
{
  ValueEnforcer.isGT0 (nCount, "Count");

  return s_aRWLock.readLockedGet ( () -> {
    if (s_aPersistentLongIDFactory == null)
      throw new IllegalStateException ("No persistent long ID factory has been supplied. Don't know how to create persistent IDs!");
    final long [] ret = new long [nCount];
    for (int i = 0; i < nCount; ++i)
      ret[i] = s_aPersistentLongIDFactory.getNewID ();
    return ret;
  });
}
 
Example 6
Source File: GlobalIDFactory.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @param nCount
 *        The number of IDs to retrieve. Must be &gt; 0.
 * @return An array of new long IDs
 */
public static long [] getBulkNewLongIDs (@Nonnegative final int nCount)
{
  ValueEnforcer.isGT0 (nCount, "Count");

  return s_aRWLock.readLockedGet ( () -> {
    if (s_aLongIDFactory == null)
      throw new IllegalStateException ("No in-memory long ID factory has been supplied!");
    final long [] ret = new long [nCount];
    for (int i = 0; i < nCount; ++i)
      ret[i] = s_aLongIDFactory.getNewID ();
    return ret;
  });
}
 
Example 7
Source File: SizeFloat.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@CheckReturnValue
public SizeFloat getScaledToWidth (@Nonnegative final float dNewWidth)
{
  ValueEnforcer.isGT0 (dNewWidth, "NewWidth");

  if (m_dWidth == dNewWidth)
    return this;
  final float dMultFactory = dNewWidth / m_dWidth;
  return new SizeFloat (dNewWidth, m_dHeight * dMultFactory);
}
 
Example 8
Source File: ObjectPool.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new object pool for a certain amount of items and a factory that
 * creates the objects on demand.
 *
 * @param nItemCount
 *        The number of items in the pool. Must be &ge; 1.
 * @param aFactory
 *        The factory to create object. May not be <code>null</code>. The
 *        factory may not create <code>null</code> objects, as this leads to
 *        an error!
 */
public ObjectPool (@Nonnegative final int nItemCount, @Nonnull final ISupplier <? extends DATATYPE> aFactory)
{
  ValueEnforcer.isGT0 (nItemCount, "ItemCount");
  ValueEnforcer.notNull (aFactory, "Factory");

  m_aAvailable = new Semaphore (nItemCount);
  m_aItems = new Object [nItemCount];
  m_aUsed = new boolean [nItemCount];
  Arrays.fill (m_aUsed, 0, nItemCount, false);
  m_aFactory = aFactory;
}
 
Example 9
Source File: SizeDouble.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@CheckReturnValue
public SizeDouble getScaledToWidth (@Nonnegative final double dNewWidth)
{
  ValueEnforcer.isGT0 (dNewWidth, "NewWidth");

  if (m_dWidth == dNewWidth)
    return this;
  final double dMultFactory = dNewWidth / m_dWidth;
  return new SizeDouble (dNewWidth, m_dHeight * dMultFactory);
}
 
Example 10
Source File: SizeDouble.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@CheckReturnValue
public SizeDouble getScaledToHeight (@Nonnegative final double dNewHeight)
{
  ValueEnforcer.isGT0 (dNewHeight, "NewHeight");

  if (m_dHeight == dNewHeight)
    return this;
  final double dMultFactory = dNewHeight / m_dHeight;
  return new SizeDouble (m_dWidth * dMultFactory, dNewHeight);
}
 
Example 11
Source File: Matrix.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a matrix quickly without checking arguments.
 *
 * @param aOther
 *        Two-dimensional array of doubles. Is directly reused!
 * @param nRows
 *        Number of rows.
 * @param nCols
 *        Number of columns.
 */
@SuppressFBWarnings ("EI_EXPOSE_REP")
Matrix (@Nonnull final double [] [] aOther, @Nonnegative final int nRows, @Nonnegative final int nCols)
{
  ValueEnforcer.notNull (aOther, "Other");
  ValueEnforcer.isGT0 (nRows, "rows");
  ValueEnforcer.isGT0 (nCols, "cols");
  ValueEnforcer.isTrue (aOther.length >= nRows, "array is too short");
  for (int nRow = 0; nRow < nRows; nRow++)
    ValueEnforcer.isTrue (aOther[nRow].length >= nCols, "All rows must have the same length.");

  m_aData = aOther;
  m_nRows = nRows;
  m_nCols = nCols;
}
 
Example 12
Source File: IntIntMap.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public IntIntMap (final int nSize, final float fFillFactor)
{
  ValueEnforcer.isBetweenInclusive (fFillFactor, "FillFactor", 0f, 1f);
  ValueEnforcer.isGT0 (nSize, "Size");
  final int nCapacity = MapHelper.arraySize (nSize, fFillFactor);
  m_nMask = nCapacity - 1;
  m_fFillFactor = fFillFactor;

  m_aKeys = new int [nCapacity];
  m_aValues = _createValueArray (nCapacity);
  m_nThreshold = (int) (nCapacity * fFillFactor);
}
 
Example 13
Source File: SizeInt.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@CheckReturnValue
public SizeInt getScaledToHeight (@Nonnegative final int nNewHeight)
{
  ValueEnforcer.isGT0 (nNewHeight, "NewHeight");

  if (m_nHeight == nNewHeight)
    return this;
  final double dMultFactory = MathHelper.getDividedDouble (nNewHeight, m_nHeight);
  return new SizeInt ((int) (m_nWidth * dMultFactory), nNewHeight);
}
 
Example 14
Source File: IntObjectMap.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public IntObjectMap (final int nSize, final float fFillFactor)
{
  ValueEnforcer.isBetweenInclusive (fFillFactor, "FillFactor", 0f, 1f);
  ValueEnforcer.isGT0 (nSize, "Size");
  final int nCapacity = MapHelper.arraySize (nSize, fFillFactor);
  m_nMask = nCapacity - 1;
  m_fFillFactor = fFillFactor;

  m_aKeys = new int [nCapacity];
  m_aValues = _createValueArray (nCapacity);
  m_nThreshold = (int) (nCapacity * fFillFactor);
}
 
Example 15
Source File: RingBufferFifo.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor
 *
 * @param nCapacity
 *        The number of elements in the ring buffer. Must be &gt; 0.
 * @param bAllowOverwrite
 *        <code>true</code> if the oldest element gets overwritten when the
 *        next element is put.
 */
public RingBufferFifo (@Nonnegative final int nCapacity, final boolean bAllowOverwrite)
{
  ValueEnforcer.isGT0 (nCapacity, "Capacity");
  m_nCapacity = nCapacity;
  m_aElements = new Object [nCapacity];
  m_bAllowOverwrite = bAllowOverwrite;
}
 
Example 16
Source File: NonBlockingPushbackInputStream.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a <code>PushbackInputStream</code> with a pushback buffer of the
 * specified <code>size</code>, and saves its argument, the input stream
 * <code>in</code>, for later use. Initially, there is no pushed-back byte
 * (the field <code>pushBack</code> is initialized to <code>-1</code>).
 *
 * @param aIS
 *        the input stream from which bytes will be read.
 * @param nSize
 *        the size of the pushback buffer.
 * @exception IllegalArgumentException
 *            if size is &le; 0
 * @since JDK1.1
 */
public NonBlockingPushbackInputStream (@Nonnull final InputStream aIS, @Nonnegative final int nSize)
{
  super (aIS);
  ValueEnforcer.isGT0 (nSize, "Size");
  m_aBuf = new byte [nSize];
  m_nBufPos = nSize;
}
 
Example 17
Source File: CSSReaderSettings.java    From ph-css with Apache License 2.0 3 votes vote down vote up
/**
 * Set the tab size to be used to determine the source location.
 *
 * @param nTabSize
 *        The tab size to use. Must be &gt; 0.
 * @return this for chaining
 * @since 5.0.2
 */
@Nonnull
public CSSReaderSettings setTabSize (@Nonnegative final int nTabSize)
{
  ValueEnforcer.isGT0 (nTabSize, "TabSize");
  m_nTabSize = nTabSize;
  return this;
}
 
Example 18
Source File: PasswordSaltBCrypt.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor to create a new BCrypt password salt with the provided rounds.
 *
 * @param nRounds
 *        the log2 of the number of rounds of hashing to apply - the work
 *        factor therefore increases as 2**log_rounds.
 */
public PasswordSaltBCrypt (@Nonnegative final int nRounds)
{
  ValueEnforcer.isGT0 (nRounds, "Rounds");
  m_sSalt = BCrypt.gensalt (nRounds);
  m_aBytes = m_sSalt.getBytes (StandardCharsets.UTF_8);
}
 
Example 19
Source File: AbstractPersistingIntIDFactory.java    From ph-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param nReserveCount
 *        The number of IDs to reserve per persistence layer access. Must be
 *        &gt; 0.
 */
public AbstractPersistingIntIDFactory (@Nonnegative final int nReserveCount)
{
  ValueEnforcer.isGT0 (nReserveCount, "ReserveCount");
  m_nReserveCount = nReserveCount;
}
 
Example 20
Source File: AbstractConcurrentCollector.java    From ph-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor creating an {@link ArrayBlockingQueue} internally.
 *
 * @param nMaxQueueSize
 *        The maximum number of items that can be in the queue. Must be &gt;
 *        0.
 */
public AbstractConcurrentCollector (@Nonnegative final int nMaxQueueSize)
{
  this (new ArrayBlockingQueue <> (ValueEnforcer.isGT0 (nMaxQueueSize, "MaxQueueSize")));
}