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

br.com.objectos.jabuticava.boleto.NumeroBancario Maven / Gradle / Ivy

The newest version!
/*
 * NumeroBancario.java criado em 21/03/2013
 * 
 * Propriedade de Objectos Fábrica de Software LTDA.
 * Reprodução parcial ou total proibida.
 */
package br.com.objectos.jabuticava.boleto;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import br.com.objectos.way.core.lang.HasIntValue;
import br.com.objectos.way.core.lang.HasLongValue;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

/**
 * @author [email protected] (Marcio Endo)
 */
class NumeroBancario implements HasIntValue, HasLongValue {

  private static final Pattern pattern = Pattern.compile("([0-9]+)(|\\-([0-9]))");

  private final long numero;

  private final char digito;

  private final int digitoValue;

  NumeroBancario(String numero) {
    Matcher matcher = pattern.matcher(numero);
    Preconditions.checkArgument(matcher.matches());

    String _numero = matcher.group(1);
    this.numero = Long.parseLong(_numero);

    String _digito = matcher.group(3);
    this.digito = Strings.isNullOrEmpty(_digito) ? 0 : _digito.charAt(0);

    this.digitoValue = Character.getNumericValue(digito);
  }

  @Override
  public int intValue() {
    return (int) numero;
  }
  @Override
  public long longValue() {
    return numero;
  }

  public char getDigito() {
    return digito;
  }

  public int getDigitoValue() {
    return digitoValue;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy