Example usage for com.google.common.primitives Doubles stringConverter

List of usage examples for com.google.common.primitives Doubles stringConverter

Introduction

In this page you can find the example usage for com.google.common.primitives Doubles stringConverter.

Prototype

@Beta
public static Converter<String, Double> stringConverter() 

Source Link

Document

Returns a serializable converter object that converts between strings and doubles using Double#valueOf and Double#toString() .

Usage

From source file:com.dssmp.pipeline.config.Configuration.java

public Configuration(Map<String, Object> map) {
    Preconditions.checkNotNull(map);/*  ww w .j a va  2 s  .c om*/
    this.configMap = map;
    this.stringConverter = new Function<Object, String>() {
        @Override
        public String apply(Object input) {
            return (input == null || input instanceof String) ? ((String) input) : input.toString();
        }
    };
    this.converters.put(String.class, this.stringConverter);
    this.doubleConverter = new StringConverterWrapper<>(Doubles.stringConverter());
    this.converters.put(String.class, this.stringConverter);
    this.integerConverter = new StringConverterWrapper<>(Ints.stringConverter());
    this.converters.put(Integer.class, this.integerConverter);
    this.longConverter = new StringConverterWrapper<>(Longs.stringConverter());
    this.converters.put(Long.class, this.longConverter);
    this.booleanConverter = new BooleanConverter();
    this.converters.put(Boolean.class, this.booleanConverter);
    this.pathConverter = new PathConverter();
    this.converters.put(Path.class, this.pathConverter);
    this.configurationConverter = new ConfigurationConverter();
    this.converters.put(Configuration.class, this.configurationConverter);

    this.stringReader = new ScalarValueReader<>(String.class, this.stringConverter);
    this.readers.put(String.class, this.stringReader);
    this.doubleReader = new ScalarValueReader<>(Double.class, this.doubleConverter);
    this.readers.put(Double.class, doubleReader);
    this.integerReader = new ScalarValueReader<>(Integer.class, this.integerConverter);
    this.readers.put(Integer.class, integerReader);
    this.longReader = new ScalarValueReader<>(Long.class, this.longConverter);
    this.readers.put(Long.class, longReader);
    this.booleanReader = new ScalarValueReader<>(Boolean.class, this.booleanConverter);
    this.readers.put(Boolean.class, booleanReader);
    this.pathReader = new ScalarValueReader<>(Path.class, this.pathConverter);
    this.readers.put(Path.class, pathReader);
    this.configurationReader = new ScalarValueReader<>(Configuration.class, this.configurationConverter);
    this.readers.put(Configuration.class, this.configurationReader);
}

From source file:com.amazon.kinesis.streaming.agent.config.Configuration.java

/**
 * @param config/*from   w ww .ja v a  2  s . c o  m*/
 */
public Configuration(Map<String, Object> map) {
    Preconditions.checkNotNull(map);
    this.configMap = map;
    this.stringConverter = new Function<Object, String>() {
        @Override
        @Nullable
        public String apply(@Nullable Object input) {
            return (input == null || input instanceof String) ? ((String) input) : input.toString();
        }
    };
    this.converters.put(String.class, this.stringConverter);
    this.doubleConverter = new StringConverterWrapper<>(Doubles.stringConverter());
    this.converters.put(String.class, this.stringConverter);
    this.integerConverter = new StringConverterWrapper<>(Ints.stringConverter());
    this.converters.put(Integer.class, this.integerConverter);
    this.longConverter = new StringConverterWrapper<>(Longs.stringConverter());
    this.converters.put(Long.class, this.longConverter);
    this.booleanConverter = new BooleanConverter();
    this.converters.put(Boolean.class, this.booleanConverter);
    this.pathConverter = new PathConverter();
    this.converters.put(Path.class, this.pathConverter);
    this.configurationConverter = new ConfigurationConverter();
    this.converters.put(Configuration.class, this.configurationConverter);

    this.stringReader = new ScalarValueReader<>(String.class, this.stringConverter);
    this.readers.put(String.class, this.stringReader);
    this.doubleReader = new ScalarValueReader<>(Double.class, this.doubleConverter);
    this.readers.put(Double.class, doubleReader);
    this.integerReader = new ScalarValueReader<>(Integer.class, this.integerConverter);
    this.readers.put(Integer.class, integerReader);
    this.longReader = new ScalarValueReader<>(Long.class, this.longConverter);
    this.readers.put(Long.class, longReader);
    this.booleanReader = new ScalarValueReader<>(Boolean.class, this.booleanConverter);
    this.readers.put(Boolean.class, booleanReader);
    this.pathReader = new ScalarValueReader<>(Path.class, this.pathConverter);
    this.readers.put(Path.class, pathReader);
    this.configurationReader = new ScalarValueReader<>(Configuration.class, this.configurationConverter);
    this.readers.put(Configuration.class, this.configurationReader);
}

From source file:org.apache.brooklyn.entity.machine.AddMachineMetrics.java

public static SshFeed createMachineMetricsFeed(EntityLocal entity) {
    boolean retrieveUsageMetrics = entity.config().get(SoftwareProcess.RETRIEVE_USAGE_METRICS);
    return SshFeed.builder().period(Duration.THIRTY_SECONDS).entity(entity)
            .poll(SshPollConfig.forSensor(MachineAttributes.UPTIME).command("cat /proc/uptime")
                    .enabled(retrieveUsageMetrics).onFailureOrException(Functions.<Duration>constant(null))
                    .onSuccess(new Function<SshPollValue, Duration>() {
                        @Override
                        public Duration apply(SshPollValue input) {
                            return Duration.seconds(Double.valueOf(Strings.getFirstWord(input.getStdout())));
                        }/* w  w w  .ja v  a 2s  .c  om*/
                    }))
            .poll(SshPollConfig.forSensor(MachineAttributes.LOAD_AVERAGE).command("uptime")
                    .enabled(retrieveUsageMetrics).onFailureOrException(Functions.<Double>constant(null))
                    .onSuccess(new Function<SshPollValue, Double>() {
                        @Override
                        public Double apply(SshPollValue input) {
                            String loadAverage = Strings.getFirstWordAfter(input.getStdout(), "load average:")
                                    .replace(",", "");
                            return Double.valueOf(loadAverage);
                        }
                    }))
            .poll(SshPollConfig.forSensor(MachineAttributes.CPU_USAGE).command("ps -A -o pcpu")
                    .enabled(retrieveUsageMetrics).onFailureOrException(Functions.<Double>constant(null))
                    .onSuccess(new Function<SshPollValue, Double>() {
                        @Override
                        public Double apply(SshPollValue input) {
                            Double cpu = 0d;
                            Iterable<String> stdout = Splitter.on(CharMatcher.BREAKING_WHITESPACE)
                                    .omitEmptyStrings().split(input.getStdout());
                            for (Double each : FluentIterable.from(stdout).skip(1)
                                    .transform(Doubles.stringConverter())) {
                                cpu += each;
                            }
                            return cpu / 100d;
                        }
                    }))
            .poll(SshPollConfig.forSensor(MachineAttributes.USED_MEMORY).command("free | grep Mem:")
                    .enabled(retrieveUsageMetrics).onFailureOrException(Functions.<Long>constant(null))
                    .onSuccess(new Function<SshPollValue, Long>() {
                        @Override
                        public Long apply(SshPollValue input) {
                            List<String> memoryData = Splitter.on(" ").omitEmptyStrings()
                                    .splitToList(Strings.getFirstLine(input.getStdout()));
                            return Long.parseLong(memoryData.get(2));
                        }
                    }))
            .poll(SshPollConfig.forSensor(MachineAttributes.FREE_MEMORY).command("free | grep Mem:")
                    .enabled(retrieveUsageMetrics).onFailureOrException(Functions.<Long>constant(null))
                    .onSuccess(new Function<SshPollValue, Long>() {
                        @Override
                        public Long apply(SshPollValue input) {
                            List<String> memoryData = Splitter.on(" ").omitEmptyStrings()
                                    .splitToList(Strings.getFirstLine(input.getStdout()));
                            return Long.parseLong(memoryData.get(3));
                        }
                    }))
            .poll(SshPollConfig.forSensor(MachineAttributes.TOTAL_MEMORY).command("free | grep Mem:")
                    .enabled(retrieveUsageMetrics).onFailureOrException(Functions.<Long>constant(null))
                    .onSuccess(new Function<SshPollValue, Long>() {
                        @Override
                        public Long apply(SshPollValue input) {
                            List<String> memoryData = Splitter.on(" ").omitEmptyStrings()
                                    .splitToList(Strings.getFirstLine(input.getStdout()));
                            return Long.parseLong(memoryData.get(1));
                        }
                    }))
            .build();
}