All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.metadata.viewer.converter.RationalConverter Maven / Gradle / Ivy

/*******************************************************************************
 *
 * blueMarine - open source photo workflow
 * =======================================
 *
 * Copyright (C) 2003-2009 by Fabrizio Giudici
 * Project home page: http://bluemarine.tidalwave.it
 *
 *******************************************************************************
 *
 * 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. 
 *
 *******************************************************************************
 *
 * $Id$
 *
 ******************************************************************************/
package it.tidalwave.metadata.viewer.converter;

import org.jdesktop.beansbinding.Converter;
import it.tidalwave.image.Rational;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/*******************************************************************************
 *
 * A {@link Converter} for {@link Rational}.
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 ******************************************************************************/
public class RationalConverter extends Converter
  {
    @Override
    @CheckForNull
    public String convertForward (@CheckForNull final Rational rational)
      {
        return (rational == null) ? null : rational.toString();
      }

    @Override
    @Nonnull
    public Rational convertReverse (@Nonnull final String string)
      {
        final String[] split = string.split("/");
        // FIXME: requires a dependency on Metadata-Extractor because there's a Rational constructor using it.
        // Drop it!
        if (split.length == 1)
          {
            return new Rational(Integer.valueOf(split[0].trim()), 1);  
          }
        
        return new Rational(Integer.valueOf(split[0].trim()), Integer.valueOf(split[1].trim()));  
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy