/*******************************************************************************
 * Copyright (c) 2010 Robert "Unlogic" Olofsson (unlogic@unlogic.se).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0-standalone.html
 ******************************************************************************/
package se.unlogic.standardutils.validation;

import se.unlogic.standardutils.numbers.NumberUtils;


public class StringFloatValidator extends StringNumberValidator<Float> {

   public StringFloatValidator() {
      super(null, null);
   }

   public StringFloatValidator(final Float minValue, final Float maxValue) {
      super(minValue,maxValue);
   }

   public boolean validateFormat(String value) {

      Float numberValue = NumberUtils.toFloat(value);

      if(numberValue == null){

         return false;

      }else if(maxValue != null && minValue != null){

         return numberValue <= maxValue && numberValue > minValue;

      }else if(maxValue != null){

         return numberValue <= maxValue;

      }else if(minValue != null){

         return numberValue >= minValue;
      }
      else{
         return true;
      }
   }
}
