Package lombok

Examples of lombok.val


  public TResult match(final T input)
  {
    // attempt to match in order that matchers were added
    for (val current : cases)
    {
      val predicate = current.getFirst();
      if (predicate.apply(input))
      {
        val function = current.getSecond();
        return function.apply(input);
      }
    }

    // use default matcher
    if (defaultFunc != null)
View Full Code Here


   * @throws NullPointerException An argument is null.
   */
  @Validate
  public static String[] split(@NotNull final String text, @NotNull final String delimiter, StringSplitOptions options)
  {
    val delimiters = new String[] {delimiter};
    return split(text, delimiters, options);
  }
View Full Code Here

   */
  @Validate
  public static String[] splitAnchor(@NotNull String text, @NotNull final Iterable<String> delimiters)
  {
    // parts are stored here
    val result = new ReifiedArrayList<String>(String.class);

    // process delimiters serially
    for (String delim : delimiters)
    {
      if (isNullOrEmpty(delim))
        throw new IllegalArgumentException("A delimiter cannot be null or empty!");

      if (!isNullOrEmpty(text))
      {
        ReifiedList<String> parts = new ReifiedArrayList<String>(split(text, delim));

        if (parts.size() >= 2)
        {
          // store if any found
          result.add(parts.get(0));
          text = text.substring(parts.get(0).length() + 1);
        }
      }
    }

    return result.toArray();
  }
View Full Code Here

   * @throws NullPointerException An argument is null
   */
  @Validate
  public static String titleCase(@NotNull final String value)
  {
    val parts = split(value, CONSTANT.WHITESPACE_CHAR, StringSplitOptions.None);
    for (int i = 0; i < parts.length; i++)
      if (parts[i].length() > 0)
        parts[i] = parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1).toLowerCase();

    return delimit(parts, CONSTANT.WHITESPACE);
View Full Code Here

   * @throws NullPointerException An argument is null.
   */
  @Validate
  public static <T> boolean any(@NotNull final T[] values, @NotNull final Predicate1<? super T> predicate)
  {
    val count = values.length;
    for (int i = 0; i < count; i++)
      if (predicate.apply(values[i]))
        return true;

    return false;
View Full Code Here

   */
  @Validate
  public static <TSource, TDest> TDest[] cast(@NotNull final TSource[] values, @NotNull final Class<TDest> destClass,
                                              InvalidCastBehaviour castBehaviour)
  {
    val list = new ReifiedArrayList<TDest>(values.length, destClass);

    switch(castBehaviour)
    {
      case Throw:
        castThrow(values, list);
View Full Code Here

   */
  @Validate
  public static <T> T[] concat(@NotNull final T[]... values)
  {
    Class<?> componentType = null;
    val result = new ArrayList<T>(DEFAULT_LIST_SIZE);

    for (val vals : values)
    {
      if (vals == null)
        throw new NullPointerException("Item of values");
      if (componentType == null)
        componentType = vals.getClass().getComponentType();

      for (T item : vals)
        result.add(item);
    }

    return toArray(result, componentType);
  }
View Full Code Here

   * @throws NullPointerException When an argument is null.
   */
  @Validate
  public static <T> T[] defaultIfEmpty(@NotNull final T[] values)
  {
    val result = new ArrayList<T>(DEFAULT_LIST_SIZE);
    for (T item : values)
      result.add(item);

    if (result.size() == 0)
      result.add(null);

    return toArray(result, values.getClass().getComponentType());
  }
View Full Code Here

   * @throws NullPointerException An argument is null.
   */
  @Validate
  public static <T> String delimit(@NotNull final Iterable<T> values, @NotNull final String delimiter, String nullReplacementValue)
  {
    val sb = new StringBuilder(256);

    for (T value : values)
      if (value != null)
      {
        sb.append(value.toString());
        sb.append(delimiter);
      } else
      // append null replacement
      if (nullReplacementValue != null)
      {
        sb.append(nullReplacementValue);
        sb.append(delimiter);
      }

    if (sb.length() > 0)
      return sb.subSequence(0, sb.length() - delimiter.length()).toString();

    return CONSTANT.EMPTY_STRING;
  }
View Full Code Here

   * @throws NullPointerException An argument is null.
   */
  @Validate
  public static <T> String delimit(@NotNull final T[] values, @NotNull final String delimiter, String nullReplacementValue)
  {
    val sb = new StringBuilder(256);

    for (T value : values)
      if (value != null)
      {
        sb.append(value.toString());
        sb.append(delimiter);
      } else
      // append null replacement
      if (nullReplacementValue != null)
      {
        sb.append(nullReplacementValue);
        sb.append(delimiter);
      }

    if (sb.length() > 0)
      return sb.subSequence(0, sb.length() - delimiter.length()).toString();

    return CONSTANT.EMPTY_STRING;
  }
View Full Code Here

TOP

Related Classes of lombok.val

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.