Package limelight.styles.compiling

Source Code of limelight.styles.compiling.IntegerAttributeCompiler

//- Copyright © 2008-2011 8th Light, Inc. All Rights Reserved.
//- Limelight and all included source files are distributed under terms of the MIT License.

package limelight.styles.compiling;

import limelight.styles.abstrstyling.StyleCompiler;
import limelight.styles.abstrstyling.StyleValue;
import limelight.styles.values.SimpleIntegerValue;

public class IntegerAttributeCompiler extends StyleCompiler
{
  public StyleValue compile(Object value)
  {
    try
    {
      int intValue;
      if(value instanceof Number)
        intValue = ((Number)value).intValue();
      else
        intValue = convertToInt(stringify(value));

      return new SimpleIntegerValue(intValue);
    }
    catch(Exception e)
    {
      throw makeError(value);
    }
  }

  public static int convertToInt(String value)
  {
    int intValue;
    if(value.indexOf(".") != -1)
      intValue = (int)(Double.parseDouble(value) + 0.5);
    else
      intValue = Integer.parseInt(value);

    return intValue;
  }
}
TOP

Related Classes of limelight.styles.compiling.IntegerAttributeCompiler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.