/*
 * Copyright 2016 The Winston Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.s13g.winston.lib.temperature;

import java.util.Locale;

/**
 * Represents a temperature.
 */
public class Temperature {
  public enum Unit {
    CELSIUS("%s C"), FAHRENHEIT("%s F");

    final String mPattern;

    Unit(String pattern) {
      mPattern = pattern;
    }
  }

  private final float mValue;
  private final Unit mUnit;

  public Temperature(float value, Unit unit) {
    mValue = value;
    mUnit = unit;
  }

  /** Returns the temperature value in the given unit. */
  public float get(Unit unit) {
    if (mUnit == unit) {
      return mValue;
    }

    if (unit == Unit.CELSIUS && mUnit == Unit.FAHRENHEIT) {
      return (mValue - 32) / 1.8f;
    } else if (unit == Unit.FAHRENHEIT && mUnit == Unit.CELSIUS) {
      return mValue * 1.8f + 32;
    }
    throw new RuntimeException("Unsupported temperature conversion");
  }

  @Override
  public String toString() {
    return String.format(Locale.getDefault(), mUnit.mPattern, mValue);
  }
}
@@ -648,16 +648,56 @@
 ature;%0A%0A
+import com.google.common.base.Strings;%0A%0A
 import j
@@ -992,16 +992,1167 @@
 mUnit;%0A%0A
+  /**%0A   * Parses the string into a temperature object.%0A   *%0A   * @param tempStr the string, like %2220 C%22 or %2269 F%22.%0A   * @return The temperature object.%0A   * @throws IllegalArgumentException thrown if the string cannot be parsed.%0A   */%0A  public static Temperature parse(String tempStr) throws IllegalArgumentException %7B%0A    if (Strings.isNullOrEmpty(tempStr)) %7B%0A      throw new IllegalArgumentException(%22Cannot parse to temperature: '%22 + tempStr + %22'.%22);%0A    %7D%0A    String%5B%5D parts = tempStr.toLowerCase().trim().split(%22 %22);%0A    if (parts.length != 2) %7B%0A      throw new IllegalArgumentException(%22Cannot parse to temperature: '%22 + tempStr + %22'.%22);%0A    %7D%0A    float number;%0A    try %7B%0A      number = Float.parseFloat(parts%5B0%5D);%0A    %7D catch (NumberFormatException ex) %7B%0A      throw new IllegalArgumentException(%22Cannot parse to temperature: '%22 + tempStr + %22'.%22);%0A    %7D%0A%0A    switch (parts%5B1%5D) %7B%0A      case %22c%22:%0A        return new Temperature(number, Unit.CELSIUS);%0A      case %22f%22:%0A        return new Temperature(number, Unit.FAHRENHEIT);%0A      default:%0A        throw new IllegalArgumentException(%22Cannot parse to temperature: '%22 + tempStr + %22'.%22);%0A    %7D%0A  %7D%0A%0A
   public

Add functionality to parse Temperature.