/** * Parses the suffix of a given distance string and return the corresponding {@link DistanceUnit} * * @param distance string representing a distance * @param defaultUnit default unit to use, if no unit is provided by the string * @return unit of the given distance */ public static DistanceUnit parseUnit(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return unit; } } } return defaultUnit; }
/** * Convert a String to a {@link DistanceUnit} * * @param unit name of the unit * @return unit matching the given name * @throws IllegalArgumentException if no unit matches the given name */ public static DistanceUnit fromString(String unit) { for (DistanceUnit dunit : values()) { for (String name : dunit.names) { if(name.equals(unit)) { return dunit; } } } throw new IllegalArgumentException("No distance unit match [" + unit + "]"); }
/** * Read a {@link DistanceUnit} from a {@link StreamInput}. * * @param in {@link StreamInput} to read the {@link DistanceUnit} from * @return {@link DistanceUnit} read from the {@link StreamInput} * @throws IOException if no unit can be read from the {@link StreamInput} * @throws IllegalArgumentException if no matching {@link DistanceUnit} can be found */ public static DistanceUnit readFromStream(StreamInput in) throws IOException { byte b = in.readByte(); if (b < 0 || b >= values().length) { throw new IllegalArgumentException("No type for distance unit matching [" + b + "]"); } return values()[b]; }
/** * Parse a {@link Distance} from a given String * * @param distance String defining a {@link Distance} * @param defaultUnit {@link DistanceUnit} to be assumed * if not unit is provided in the first argument * @return parsed {@link Distance} */ private static Distance parseDistance(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return new Distance(Double.parseDouble(distance.substring(0, distance.length() - name.length())), unit); } } } return new Distance(Double.parseDouble(distance), defaultUnit); } }
/** * Parses the suffix of a given distance string and return the corresponding {@link DistanceUnit} * * @param distance string representing a distance * @param defaultUnit default unit to use, if no unit is provided by the string * @return unit of the given distance */ public static DistanceUnit parseUnit(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return unit; } } } return defaultUnit; }
/** * Parses the suffix of a given distance string and return the corresponding {@link DistanceUnit} * * @param distance string representing a distance * @param defaultUnit default unit to use, if no unit is provided by the string * @return unit of the given distance */ public static DistanceUnit parseUnit(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return unit; } } } return defaultUnit; }
/** * Parses the suffix of a given distance string and return the corresponding {@link DistanceUnit} * * @param distance string representing a distance * @param defaultUnit default unit to use, if no unit is provided by the string * @return unit of the given distance */ public static DistanceUnit parseUnit(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return unit; } } } return defaultUnit; }
/** * Parses the suffix of a given distance string and return the corresponding {@link DistanceUnit} * * @param distance string representing a distance * @param defaultUnit default unit to use, if no unit is provided by the string * @return unit of the given distance */ public static DistanceUnit parseUnit(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return unit; } } } return defaultUnit; }
/** * Convert a String to a {@link DistanceUnit} * * @param unit name of the unit * @return unit matching the given name * @throws IllegalArgumentException if no unit matches the given name */ public static DistanceUnit fromString(String unit) { for (DistanceUnit dunit : values()) { for (String name : dunit.names) { if(name.equals(unit)) { return dunit; } } } throw new IllegalArgumentException("No distance unit match [" + unit + "]"); }
/** * Convert a String to a {@link DistanceUnit} * * @param unit name of the unit * @return unit matching the given name * @throws IllegalArgumentException if no unit matches the given name */ public static DistanceUnit fromString(String unit) { for (DistanceUnit dunit : values()) { for (String name : dunit.names) { if(name.equals(unit)) { return dunit; } } } throw new IllegalArgumentException("No distance unit match [" + unit + "]"); }
/** * Convert a String to a {@link DistanceUnit} * * @param unit name of the unit * @return unit matching the given name * @throws IllegalArgumentException if no unit matches the given name */ public static DistanceUnit fromString(String unit) { for (DistanceUnit dunit : values()) { for (String name : dunit.names) { if(name.equals(unit)) { return dunit; } } } throw new IllegalArgumentException("No distance unit match [" + unit + "]"); }
/** * Convert a String to a {@link DistanceUnit} * * @param unit name of the unit * @return unit matching the given name * @throws IllegalArgumentException if no unit matches the given name */ public static DistanceUnit fromString(String unit) { for (DistanceUnit dunit : values()) { for (String name : dunit.names) { if(name.equals(unit)) { return dunit; } } } throw new IllegalArgumentException("No distance unit match [" + unit + "]"); }
/** * Read a {@link DistanceUnit} from a {@link StreamInput}. * * @param in {@link StreamInput} to read the {@link DistanceUnit} from * @return {@link DistanceUnit} read from the {@link StreamInput} * @throws IOException if no unit can be read from the {@link StreamInput} * @throws IllegalArgumentException if no matching {@link DistanceUnit} can be found */ public static DistanceUnit readFromStream(StreamInput in) throws IOException { byte b = in.readByte(); if (b < 0 || b >= values().length) { throw new IllegalArgumentException("No type for distance unit matching [" + b + "]"); } return values()[b]; }
/** * Read a {@link DistanceUnit} from a {@link StreamInput}. * * @param in {@link StreamInput} to read the {@link DistanceUnit} from * @return {@link DistanceUnit} read from the {@link StreamInput} * @throws IOException if no unit can be read from the {@link StreamInput} * @throws IllegalArgumentException if no matching {@link DistanceUnit} can be found */ public static DistanceUnit readFromStream(StreamInput in) throws IOException { byte b = in.readByte(); if (b < 0 || b >= values().length) { throw new IllegalArgumentException("No type for distance unit matching [" + b + "]"); } return values()[b]; }
/** * Read a {@link DistanceUnit} from a {@link StreamInput}. * * @param in {@link StreamInput} to read the {@link DistanceUnit} from * @return {@link DistanceUnit} read from the {@link StreamInput} * @throws IOException if no unit can be read from the {@link StreamInput} * @throws IllegalArgumentException if no matching {@link DistanceUnit} can be found */ public static DistanceUnit readFromStream(StreamInput in) throws IOException { byte b = in.readByte(); if (b < 0 || b >= values().length) { throw new IllegalArgumentException("No type for distance unit matching [" + b + "]"); } return values()[b]; }
/** * Read a {@link DistanceUnit} from a {@link StreamInput} * * @param in {@link StreamInput} to read the {@link DistanceUnit} from * @return {@link DistanceUnit} read from the {@link StreamInput} * @throws IOException if no unit can be read from the {@link StreamInput} * @throws IllegalArgumentException if no matching {@link DistanceUnit} can be found */ public static DistanceUnit readDistanceUnit(StreamInput in) throws IOException { byte b = in.readByte(); if(b<0 || b>=values().length) { throw new IllegalArgumentException("No type for distance unit matching [" + b + "]"); } else { return values()[b]; } }
/** * Parse a {@link Distance} from a given String * * @param distance String defining a {@link Distance} * @param defaultUnit {@link DistanceUnit} to be assumed * if not unit is provided in the first argument * @return parsed {@link Distance} */ private static Distance parseDistance(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return new Distance(Double.parseDouble(distance.substring(0, distance.length() - name.length())), unit); } } } return new Distance(Double.parseDouble(distance), defaultUnit); } }
/** * Parse a {@link Distance} from a given String * * @param distance String defining a {@link Distance} * @param defaultUnit {@link DistanceUnit} to be assumed * if not unit is provided in the first argument * @return parsed {@link Distance} */ private static Distance parseDistance(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return new Distance(Double.parseDouble(distance.substring(0, distance.length() - name.length())), unit); } } } return new Distance(Double.parseDouble(distance), defaultUnit); } }
/** * Parse a {@link Distance} from a given String * * @param distance String defining a {@link Distance} * @param defaultUnit {@link DistanceUnit} to be assumed * if not unit is provided in the first argument * @return parsed {@link Distance} */ private static Distance parseDistance(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return new Distance(Double.parseDouble(distance.substring(0, distance.length() - name.length())), unit); } } } return new Distance(Double.parseDouble(distance), defaultUnit); } }
/** * Parse a {@link Distance} from a given String * * @param distance String defining a {@link Distance} * @param defaultUnit {@link DistanceUnit} to be assumed * if not unit is provided in the first argument * @return parsed {@link Distance} */ private static Distance parseDistance(String distance, DistanceUnit defaultUnit) { for (DistanceUnit unit : values()) { for (String name : unit.names) { if(distance.endsWith(name)) { return new Distance(Double.parseDouble(distance.substring(0, distance.length() - name.length())), unit); } } } return new Distance(Double.parseDouble(distance), defaultUnit); } }