All Downloads are FREE. Search and download functionalities are using the official Maven repository.

brooklyn.event.feed.ssh.SshValueFunctions Maven / Gradle / Ivy

There is a newer version: 0.7.0-M1
Show newest version
package brooklyn.event.feed.ssh;

import javax.annotation.Nullable;

import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Predicates;

public class SshValueFunctions {

    public static Function exitStatus() {
        return new Function() {
            @Override public Integer apply(SshPollValue input) {
                return input.getExitStatus();
            }
        };
    }

    public static Function stdout() {
        return new Function() {
            @Override public String apply(SshPollValue input) {
                return input.getStdout();
            }
        };
    }
    
    public static Function stderr() {
        return new Function() {
            @Override public String apply(SshPollValue input) {
                return input.getStderr();
            }
        };
    }
    
    public static Function exitStatusEquals(final int expected) {
        return chain(SshValueFunctions.exitStatus(), Functions.forPredicate(Predicates.equalTo(expected)));
    }

    // TODO Do we want these chain methods? Does guava have them already? Duplicated in HttpValueFunctions.
    public static  Function chain(final Function f1, final Function f2) {
        return new Function() {
            @Override public C apply(@Nullable A input) {
                return f2.apply(f1.apply(input));
            }
        };
    }
    
    public static  Function chain(final Function f1, final Function f2, final Function f3) {
        return new Function() {
            @Override public D apply(@Nullable A input) {
                return f3.apply(f2.apply(f1.apply(input)));
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy