Package lombok

Examples of lombok.val


   * minutes become "about 13 hours". The suffix can be used to describe the event's position in time, use e.g. " ago" or " from now"
   */
  @Validate
  public static String toHumanReadable(@NotNull final Duration ts, @NotNull final String suffix)
  {
    val values = new AvlHashtable<Double, String>(Double.class, String.class);

    long totalSeconds = Math.abs(ts.getStandardSeconds());
    final double totalMinutes = Math.round(totalSeconds / 60);
    double totalHours = Math.round(totalMinutes / 60);
    double totalDays = Math.floor(totalHours / 24);
    double totalMonths = Math.floor(totalDays / 30);
    double totalYears = Math.floor(totalMonths / 12);

    values.add(0.75d, "less than a minute");
    values.add(1.5d, "about a minute");
    values.add(45d, String.format("%d minutes", (int) totalMinutes));
    values.add(90d, "about an hour");
    values.add(1440d, String.format("about %d hours", (int) totalHours)); // 60 * 24
    values.add(2880d, "a day"); // 60 * 48
    values.add(43200d, String.format("%d days", (int) totalDays)); // 60 * 24 * 30
    values.add(86400d, "about a month"); // 60 * 24 * 60
    values.add(525600d, String.format("%d months", (int) totalMonths)); // 60 * 24 * 365
    values.add(1051200d, "about a year"); // 60 * 24 * 365 * 2
    values.add(Double.MAX_VALUE, String.format("%d years", (int) totalYears));

    Double key = Linq.first(values.getKeys(), keyGreaterThan(totalMinutes));
    return values.get(key) + suffix;
  }
View Full Code Here


   * @throws NullPointerException When an argument is null, or an item in the iterable is null.
   */
  @Validate
  public static <T> List<T>[] split(@NotNull final Iterable<? extends T> values, @NotNull final T delimiter)
  {
    val parts = new ReifiedArrayList<List<T>>() {};
    parts.add(new ArrayList<T>(DEFAULT_LIST_SIZE));

    for (T item : values)
    {
      if (!item.equals(delimiter))
        parts.get(parts.size() - 1).add(item);
      else
        parts.add(new ArrayList<T>(DEFAULT_LIST_SIZE));
    }

    return where(parts.toArray(), isNotEmpty);
  }
View Full Code Here

   * @throws NullPointerException When an argument is null, or an item in the iterable is null.
   */
  @Validate
  public static <T> List<T>[] split(@NotNull final T[] values, @NotNull final T delimiter)
  {
    val parts = new ReifiedArrayList<List<T>>() {};
    parts.add(new ArrayList<T>(DEFAULT_LIST_SIZE));

    for (T item : values)
    {
      if (!item.equals(delimiter))
        parts.get(parts.size() - 1).add(item);
      else
        parts.add(new ArrayList<T>(DEFAULT_LIST_SIZE));
    }

    return where(parts.toArray(), isNotEmpty);
  }
View Full Code Here

   * @throws NullPointerException When an argument is null, or an item in the iterable is null and the comparer does not handle this case.
   */
  @Validate
  public static <T> List<T>[] split(@NotNull final Iterable<T> values, @NotNull final T delimiter, final Comparator<? super T> comparer)
  {
    val parts = new ReifiedArrayList<List<T>>() {};
    parts.add(new ArrayList<T>(DEFAULT_LIST_SIZE));

    for (T item : values)
    {
      if (comparer.compare(item, delimiter) != 0)
        // not a delimiter, add to parts
        parts.get(parts.size() - 1).add(item);
      else
        parts.add(new ArrayList<T>(DEFAULT_LIST_SIZE));
    }

    return where(parts.toArray(), isNotEmpty);
  }
View Full Code Here

   * @throws NullPointerException When an argument is null, or an item in the iterable is null and the comparer does not handle this case.
   */
  @Validate
  public static <T> List<T>[] split(@NotNull final T[] values, @NotNull final T delimiter, final Comparator<? super T> comparer)
  {
    val parts = new ReifiedArrayList<List<T>>() {};
    parts.add(new ArrayList<T>(DEFAULT_LIST_SIZE));

    for (T item : values)
    {
      if (comparer.compare(item, delimiter) != 0)
        parts.get(parts.size() - 1).add(item);
      else
        parts.add(new ArrayList<T>(DEFAULT_LIST_SIZE));
    }

    List<T> result = new ArrayList<T>(DEFAULT_LIST_SIZE);

    return where(parts.toArray(), isNotEmpty);
  }
View Full Code Here

   * @throws IllegalArgumentException The count argument is out of range.
   */
  @Validate
  public static <T> T[] take(@NotNull final T[] values, final int count)
  {
    val result = new ArrayList<T>(count);
    for (int i = 0; i < count && i < values.length; i++)
      result.add(values[i]);

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

   * @throws NullPointerException An argument is null.
   */
  @Validate
  public static <T> T[] takeWhile(@NotNull final T[] values, @NotNull final Predicate1<? super T> predicate)
  {
    val result = new ArrayList<T>(DEFAULT_LIST_SIZE);

    val count = values.length;
    for (int i = 0; i < count; i++)
    {
      T item = values[i];
      if (predicate.apply(item))
        result.add(item);
View Full Code Here

   * @throws NullPointerException An argument is null.
   */
  @Validate
  public static <T> T[] toArray(@NotNull final Enumeration<T> enumeration, @NotNull final Class<?> componentType)
  {
    val result = new ReifiedArrayList<T>(componentType);
    while (enumeration.hasMoreElements())
      result.add(enumeration.nextElement());

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

   */
  @Validate
  public static <T> T[] toArray(@NotNull final Iterable<T> values, @NotNull final Class<?> componentType)
  {
    // count items
    val count = count(values);

    val result = (T[]) Array.newInstance(componentType, count);

    val iterator = values.iterator();

    for (int i = 0; i < count; i++)
      result[i] = iterator.next();

    return result;
  }
View Full Code Here

   */
  @Validate
  public static <T> T[] toArray(@NotNull final Collection<T> list, @NotNull final Class<?> componentType)
  {
    // count items
    val size = list.size();
    val result = (T[]) Array.newInstance(componentType, size);

    val iterator = list.iterator();

    for (int i = 0; i < size; i++)
      result[i] = iterator.next();

    return result;
  }
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.