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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:com.googlecode.blaisemath.style.Styles.java

public static Stroke getStroke(AttributeSet style) {
    float strokeWidth = style.getFloat(Styles.STROKE_WIDTH, 1f);
    String dashes = style.getString(Styles.STROKE_DASHES, null);
    if (!Strings.isNullOrEmpty(dashes)) {
        Iterable<String> sDashes = Splitter.on(",").trimResults().split(dashes);
        try {//from  w  ww  .  ja  v  a2 s.c  o  m
            Iterable<Float> fDashes = Floats.stringConverter().convertAll(sDashes);
            float[] fArr = new float[Iterables.size(fDashes)];
            int i = 0;
            for (Float f : fDashes) {
                fArr[i] = f == null ? 0f : f;
                i++;
            }
            return new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, fArr,
                    0.0f);
        } catch (NumberFormatException x) {
            Logger.getLogger(Styles.class.getName()).log(Level.WARNING, "Invalid dash pattern: " + dashes, x);
        }
    }
    return new BasicStroke(strokeWidth);
}