/** * Adapts an action to a different type by casting the object before giving it to the action. * * @param actionType The type the action is expecting * @param action The action * @param <T> The type the action is expecting * @param <I> The type before casting * @return An action that casts the object to the given type before giving it to the given action */ public static <T, I> Action<I> castBefore(final Class<T> actionType, final Action<? super T> action) { return transformBefore(action, Transformers.cast(actionType)); }
public void execute(T thing) { try { doExecute(thing); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } }
/** * Note: always throws the failure in some form. The return value is to keep the compiler happy. */ public static RuntimeException throwAsUncheckedException(Throwable t) { return throwAsUncheckedException(t, false); }
/** * Returns the line separator for this platform. */ public static String getPlatformLineSeparator() { return SystemProperties.getInstance().getLineSeparator(); }
public static <T> Collection<? extends T> checkedCast(Class<T> type, Collection<?> input) { for (Object o : input) { cast(type, o); } return Cast.uncheckedCast(input); }
protected List<File> getFiles() { if (files == null) { files = filesFactory.create(); } return files; }
public void transform(File destination, final Action<? super Writer> generator) { IoActions.writeTextFile(destination, new Action<Writer>() { public void execute(Writer writer) { transform(writer, generator); } }); }
@Override public void execute(MutableModelNode modelNode, T view, List<ModelView<?>> inputs) { action.execute(modelNode, view); } }
@Override public boolean accept(File file) { return hasExtension(file, ".jar"); } });
/** * Creates an action that itself takes an action that will perform that actual writing to the file. * * All IO is deferred until the execution of the returned action. * * @param output The file to write to * @param encoding The character encoding to write with * @return An action that receives an action that performs the actual writing */ public static Action<Action<? super BufferedWriter>> createTextFileWriteAction(File output, String encoding) { return new TextFileWriterIoAction(output, encoding); }
/** * Checks if the given file path ends with the given extension (ignoring case). * @param fileName the file name * @param extension candidate extension including leading dot * @return true if the file name ends with extension, ignoring case */ public static boolean hasExtensionIgnoresCase(String fileName, String extension) { return endsWithIgnoreCase(fileName, extension); }
/** * Transforms strings which may have spaces and which may have already been escaped with * quotes into safe command-line arguments. */ public static Transformer<String, String> asSafeCommandLineArgument() { return new CommandLineArgumentTransformer(); }
/** * Returns a describable that converts the provided values to string each time the display name is queried, separating the values with a space character. Can pass a {@link Describable} or {@link DisplayName} for any parameter. */ public static DisplayName of(Object part1, Object part2) { return new TwoPartDescribable(part1, part2); }
/** * Transforms a properties object. This will modify the * original. * @param original the properties to transform * @return the transformed properties */ private Properties doTransform(Properties original) { actions.execute(original); return original; } }
/** * Creates an action that will call each of the given actions in order. * * @param actions The actions to make a composite of. * @param <T> The type of the object that action is for * @return The composite action. */ public static <T> Action<T> composite(Iterable<? extends Action<? super T>> actions) { return new CompositeAction<T>(actions); }
/** * Returns a describable that calculates the display name of the given describable when first requested and reuses the result. */ public static DisplayName memoize(Describable describable) { return new MemoizingDescribable(describable); }
public void transform(File destination, final String encoding, final Action<? super Writer> generator) { IoActions.writeTextFile(destination, encoding, new Action<Writer>() { public void execute(Writer writer) { transform(writer, encoding, generator); } }); }
@Override protected void execute(MutableModelNode modelNode, T view, List<ModelView<?>> inputs) { action.execute(view, inputs); } }
/** * Creates an action that itself takes an action that will perform that actual writing to the file. * * All IO is deferred until the execution of the returned action. * * @param output The file to write to * @param encoding The character encoding to write with * @return An action that receives an action that performs the actual writing */ public static Action<Action<? super BufferedWriter>> createTextFileWriteAction(File output, String encoding) { return new TextFileWriterIoAction(output, encoding); }
@Override public void execute(A a, B b) { for (BiAction<? super A, ? super B> action : actions) { action.execute(a, b); } } };