Package lombok

Examples of lombok.val


        dict.put(key, secondDictionary);
      }
    }

    // get all lists and combine into one resultant list
    val result = new ReifiedArrayList<TResult>(DEFAULT_LIST_SIZE, keySelector2.getReturnType());
    // get all secondary dictionaries
    for (TreeMap<TKey2, List<TResult>> tree : dict.values())
      for (List<TResult> list : tree.values())
        result.addAll(list);

    return result;
  }
View Full Code Here


        dict.put(key, secondDictionary);
      }
    }

    // get all lists and combine into one resultant list
    val result = new ReifiedArrayList<TResult>(DEFAULT_LIST_SIZE, keySelector2.getReturnType());
    // get all secondary dictionaries
    for (TreeMap<TKey2, List<TResult>> tree : dict.values())
      for (List<TResult> list : tree.values())
        result.addAll(list);

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

   */
  @Validate
  public static <T> Pair<Iterable<T>, Iterable<T>> partition(@NotNull final Iterable<T> values,
                                                             @NotNull final Predicate1<? super T> predicate)
  {
    val matching = new ArrayList<T>(DEFAULT_LIST_SIZE);
    val nonMatching = new ArrayList<T>(DEFAULT_LIST_SIZE);

    for (T item : values)
      if (predicate.evaluate(item))
        matching.add(item);
      else
        nonMatching.add(item);

    return new Pair<Iterable<T>, Iterable<T>>(matching, nonMatching);
  }
View Full Code Here

   * @throws NullPointerException The values argument is null.
   */
  @Validate
  public static <T> Pair<T[], T[]> partition(@NotNull final T[] values, @NotNull final Predicate1<T> predicate)
  {
    val matching = new ReifiedArrayList<T>(DEFAULT_LIST_SIZE, values.getClass().getComponentType());
    val nonMatching = new ReifiedArrayList<T>(DEFAULT_LIST_SIZE, values.getClass().getComponentType());

    for (T item : values)
      if (predicate.evaluate(item))
        matching.add(item);
      else
        nonMatching.add(item);

    return new Pair<T[], T[]>(matching.toArray(), nonMatching.toArray());
  }
View Full Code Here

  @Validate
  @SuppressWarnings("unchecked")
  public static <T> T changeType(@NotNull final Object value, @NotNull final Class<T> targetType)
      throws InstantiationException, IllegalAccessException
  {
    val sourceType = value.getClass();

    // check that we're not working with incompatible types
    if (sourceType.isAnnotation() || targetType.isAnnotation())
      throw new IllegalArgumentException("This conversion process does not support annotations.");
    if (sourceType.isArray() || targetType.isArray())
      throw new IllegalArgumentException("This conversion process does not support arrays.");

    // handle conversion to String
    if (targetType.equals(String.class))
      return (T) value.toString();

    // handle parsing from String
    if (sourceType.equals(String.class))
      return (T) changeTypeParseFromString(value, targetType);

    // handle simple casting scenario
    if (sourceType.isAssignableFrom(targetType))
      return targetType.cast(value);

    // handle number conversion
    if (value instanceof Number)
      return (T) changeTypeFromNumber(value, targetType);

    // handle primitive conversion
    PrimitiveType primitiveType = ReflectionUtils.getPrimitiveType(sourceType);
    if (primitiveType != PrimitiveType.NotPrimitive)
      return (T) changeTypeFromPrimitive(value, primitiveType, targetType);

    // handle number-like Character and Boolean conversion (these don't implement Number)
    if (value instanceof Character)
      return (T) changeTypeFromCharacter(value, targetType);
    if (value instanceof Boolean)
      return (T) changeTypeFromBoolean(value, targetType);

    // all attempts have failed
    throw new IllegalArgumentException("The provided object of type '" + sourceType.getSimpleName() + "' could not be converted to '"
        + targetType.getSimpleName());
  }
View Full Code Here

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

    Collections.reverse(result);

    return result;
  }
View Full Code Here

   * @throws NullPointerException When the argument is null.
   */
  @Validate
  public static <T> ReifiedList<T> reverse(@NotNull final ReifiedIterable<T> values)
  {
    val result = new ReifiedArrayList<T>(values);
    Collections.reverse(result);

    return result;
  }
View Full Code Here

   * @throws NullPointerException When an argument is null.
   */
  @Validate
  public static <TSource, TResult> TResult[] select(@NotNull final TSource[] values, @NotNull final Function1<TSource, TResult> selector)
  {
    val result = new ArrayList<TResult>(values.length);

    for (TSource item : values)
      result.add(selector.apply(item));

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

  }

  @SneakyThrows
  private static File openFile(final String fileAbsPath)
  {
    val file = new File(fileAbsPath);
    if (!file.exists())
      throw new FileNotFoundException("The file was not found: " + fileAbsPath);
    if (!file.isFile())
      throw new FileNotFoundException("The specified path is not referring to a file: " + fileAbsPath);
    return file;
  }
View Full Code Here

   */
  @Validate
  public static byte[] readFileInMemory(@NotNull final String fileAbsPath)
      throws IOException
  {
    val file = new File(fileAbsPath);
    if (!file.exists())
      throw new FileNotFoundException("The file was not found: " + fileAbsPath);
    if (!file.isFile())
      throw new FileNotFoundException("The specified path is not referring to a file: " + fileAbsPath);

    val bis = new BufferedInputStream(new FileInputStream(file));
    val result = StreamUtils.readFully(bis, file.length());
    bis.close();
    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.