01: /*
02: * Created on 14/04/2004
03: *
04: * Swing Components - visit http://sf.net/projects/gfd
05: *
06: * Copyright (C) 2004 Igor Regis da Silva Simões
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or (at your option) any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23: package br.com.gfpshare.util;
24:
25: /**
26: * Classe que representa um CNPJ e realiza a validação
27: * @author Igor Regis da Silva Simões
28: */
29: public class CNPJ extends CodigoComDV {
30:
31: /**
32: * Creates a new instance of CNPJ
33: * @param cnpj Numero do CNPJ
34: **/
35: public CNPJ(String cnpj) {
36: setCodigo(cnpj);
37: }
38:
39: /**
40: * @see br.com.gfpshare.util.CodigoComDV#getDV()
41: */
42: @Override
43: public String getDV() {
44: return getCodigo().substring(12);
45: }
46:
47: /**
48: * @see br.com.gfpshare.util.CodigoComDV#isValido()
49: */
50: @Override
51: public boolean isValido() {
52: if (getCodigo().length() != 14)
53: return false;
54: String dv1 = modulo11(getCodigo().substring(0, 12), 9);
55: String dv2 = modulo11(getCodigo().substring(0, 13), 9);
56: return getDV().equals(dv1 + dv2);
57: }
58: }
|