Package lombok

Examples of lombok.val


   * @throws NullPointerException When the values argument is null.
   */
  @Validate
  public static <T> T[] distinct(@NotNull final T[] values, final Comparator<? super T> comparer)
  {
    val list = new ReifiedArrayList<T>(DEFAULT_LIST_SIZE, values.getClass().getComponentType());
    Set<T> set;
    if (comparer != null)
      set = new TreeSet<T>(comparer);
    else
      set = new TreeSet<T>();

    for (T item : values)
      if (!set.contains(item))
      {
        set.add(item);
        list.add(item);
      }

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


   * @throws NullPointerException When the first or second argument is null.
   */
  @Validate
  public static <T> T[] intersect(@NotNull final T[] first, @NotNull final T[] second, final Comparator<? super T> comparer)
  {
    val result = new ArrayList<T>(DEFAULT_LIST_SIZE);

    T[] distinctFirst;
    T[] distinctSecond;

    if (comparer == null)
    {
      distinctFirst = distinct(first);
      distinctSecond = distinct(second);
    } else
    {
      distinctFirst = distinct(first, comparer);
      distinctSecond = distinct(second, comparer);
    }

    for (T item : distinctFirst)
      if (contains(distinctSecond, item))
        result.add(item);

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

  public static <TOuter, TInner, TKey extends Comparable<TKey>, TResult> TResult[]
      join(@NotNull final TOuter[] outerValues, @NotNull final TInner[] innerValues,
           @NotNull final Function1<TOuter, TKey> outerKeySelector, @NotNull final Function1<TInner, TKey> innerKeySelector,
           @NotNull final Function2<TOuter, TInner, TResult> resultSelector)
  {
    val result = new ArrayList<TResult>(DEFAULT_LIST_SIZE);
    val lookup = new AvlHashtable<TKey, TOuter>(outerKeySelector.getReturnType(), outerKeySelector.getReturnType());

    for (TOuter value : outerValues)
    {
      TKey outerKey = outerKeySelector.apply(value);
      lookup.add(outerKey, value);
    }

    for (TInner inner : innerValues)
    {
      TKey innerKey = innerKeySelector.apply(inner);

      if (lookup.containsKey(innerKey))
      {
        TOuter outer = lookup.get(innerKey);
        TResult res = resultSelector.apply(outer, inner);
        result.add(res);
      }
    }
View Full Code Here

  public static <T> T maxOccurring(@NotNull final T[] items, final Comparator<? super T> comparator)
  {
    if (items.length <= 0)
      return null;

    val lookup = new TreeMap<T, ModuloCounter>(comparator);
    for (T item : items)
      if (!lookup.containsKey(item))
        lookup.put(item, new ModuloCounter(Long.MAX_VALUE - 1));
      else

        lookup.get(item).next();

    long max = -1;
    T result = null;
    for (val kvp : lookup.entrySet())
    {
      if (kvp.getValue().getValue() > max)
      {
        max = kvp.getValue().getValue();
        result = kvp.getKey();
View Full Code Here

   * @throws NullPointerException An argument is null
   */
  @Validate
  public static <T> T maxOccurring(@NotNull final Iterable<T> items, final Comparator<? super T> comparator)
  {
    val lookup = new TreeMap<T, ModuloCounter>(comparator);
    for (T item : items)
      if (!lookup.containsKey(item))
        lookup.put(item, new ModuloCounter(Long.MAX_VALUE - 1));
      else
        lookup.get(item).next();

    if (lookup.size() <= 0)
      return null;

    long max = -1;
    T result = null;
    for (val kvp : lookup.entrySet())
    {
      if (kvp.getValue().getValue() > max)
      {
        max = kvp.getValue().getValue();
        result = kvp.getKey();
View Full Code Here

  public static <T> T minOccurring(@NotNull final T[] items, final Comparator<? super T> comparator)
  {
    if (items.length <= 0)
      return null;

    val lookup = new TreeMap<T, ModuloCounter>(comparator);
    for (T item : items)
      if (!lookup.containsKey(item))
        lookup.put(item, new ModuloCounter(Long.MAX_VALUE - 1));
      else
        lookup.get(item).next();

    long min = Long.MAX_VALUE;
    T result = null;
    for (val kvp : lookup.entrySet())
    {
      if (kvp.getValue().getValue() < min)
      {
        min = kvp.getValue().getValue();
        result = kvp.getKey();
View Full Code Here

   * @throws NullPointerException An argument is null
   */
  @Validate
  public static <T> T minOccurring(@NotNull final Iterable<T> items, final Comparator<? super T> comparator)
  {
    val lookup = new TreeMap<T, ModuloCounter>(comparator);

    for (T item : items)
      if (!lookup.containsKey(item))
        lookup.put(item, new ModuloCounter(Long.MAX_VALUE - 1));
      else
        lookup.get(item).next();

    if (lookup.size() <= 0)
      return null;

    long min = Long.MAX_VALUE;
    T result = null;
    for (val kvp : lookup.entrySet())
    {
      if (kvp.getValue().getValue() < min)
      {
        min = kvp.getValue().getValue();
        result = kvp.getKey();
View Full Code Here

   * @throws NullPointerException When the argument is null.
   */
  @Validate
  public static <TSource, TDest> TDest[] ofType(@NotNull final TSource[] values, @NotNull final Class<TDest> destinationClass)
  {
    val result = new ReifiedArrayList<TDest>(DEFAULT_LIST_SIZE, destinationClass);

    for (TSource item : values)
    {
      try
      {
        TDest temp = destinationClass.cast(item);
        result.add(temp);
      }
      catch(ClassCastException e)
      {}
    }

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

        v.add(item);
        dict.put(key, v);
      }
    }

    val result = new ReifiedArrayList<TResult>(DEFAULT_LIST_SIZE, keySelector.getParameterType1());
    for (List<TResult> list : dict.values())
      result.addAll(list);

    return result;
  }
View Full Code Here

        v.add(item);
        dict.put(key, v);
      }
    }

    val result = new ReifiedArrayList<TResult>(DEFAULT_LIST_SIZE, keySelector.getParameterType1());
    for (List<TResult> list : dict.values())
      result.addAll(list);

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