Source Code Cross Referenced for CodigoComDV.java in  » ERP-CRM-Financial » Personal-Finance-Manager » br » com » gfpshare » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Personal Finance Manager » br.com.gfpshare.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 08/05/2004
003:         * 
004:         * Swing Components - visit http://sf.net/projects/gfd
005:         * 
006:         * Copyright (C) 2004  Igor Regis da Silva Simões
007:         * 
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or (at your option) any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         * 
022:         */
023:        package br.com.gfpshare.util;
024:
025:        /**
026:         * Classe abstrata que representa um código qualquer que possua digito verificador
027:         * @author Igor Regis da Silva Simões
028:         */
029:        public abstract class CodigoComDV {
030:
031:            /**
032:             * Codigo
033:             */
034:            private String codigo = null;
035:
036:            /**
037:             * Retorna o digito verificador
038:             * @return String contendo o DV
039:             */
040:            public abstract String getDV();
041:
042:            /**
043:             * Retorna true quando o CNPJ é válido
044:             * @return boolean indicando a validade do CNPJ
045:             *
046:             */
047:            public abstract boolean isValido();
048:
049:            /**
050:             * Seta o códgio
051:             * @param codigo String
052:             */
053:            public void setCodigo(String codigo) {
054:                this .codigo = codigo;
055:            }
056:
057:            /**
058:             * Reotorna o código representado por esta classe
059:             * @return String com o código
060:             */
061:            public String getCodigo() {
062:                return codigo;
063:            }
064:
065:            /**
066:             * Realiza a operação Modulo10 sobre uma parte do codigo retornando um numero
067:             * @param field campo a ser usado no Modulo10
068:             * @return Retorna um numero baseado no calculo
069:             */
070:            protected String modulo10(String field) {
071:                int[] campo = new int[field.length()];
072:                int[] resultado = new int[field.length()];
073:                int[] multiplicador = new int[field.length()];
074:                int total = 0;
075:
076:                boolean fat = false;
077:                for (int i = multiplicador.length - 1; i >= 0; i--)
078:                    if (fat == false) {
079:                        multiplicador[i] = 2;
080:                        fat = true;
081:                    } else {
082:                        multiplicador[i] = 1;
083:                        fat = false;
084:                    }
085:
086:                for (int i = 0; i < field.length(); i++)
087:                    campo[i] = Integer.parseInt(field.substring(i, i + 1));
088:
089:                for (int i = 0; i < resultado.length; i++)
090:                    resultado[i] = campo[i] * multiplicador[i];
091:
092:                for (int i = 0; i < resultado.length; i++)
093:                    if (resultado[i] > 9)
094:                        resultado[i] = Integer.parseInt((String
095:                                .valueOf(resultado[i])).substring(0, 1))
096:                                + Integer
097:                                        .parseInt((String.valueOf(resultado[i]))
098:                                                .substring(1, 2));
099:
100:                for (int i = 0; i < resultado.length; i++)
101:                    total += resultado[i];
102:
103:                int dezena = 10;
104:                while (dezena < total)
105:                    dezena += 10;
106:
107:                int DV = dezena - total;
108:
109:                return String.valueOf(DV == 10 ? 0 : DV);
110:            }
111:
112:            /**
113:             * Realiza a operação Modulo11 sobre uma parte do codigo retornando um numero
114:             * @param field campo a ser usado no Modulo11
115:             * @param limite limite do multiplicatores usados no cálculo
116:             * @return Retorna um numero baseado no calculo
117:             */
118:            protected String modulo11(String field, int limite) {
119:                int[] campo = new int[field.length()];
120:                int[] resultado = new int[field.length()];
121:                int[] multiplicador = new int[field.length()];
122:                int total = 0;
123:
124:                int fator = 2;
125:                for (int i = multiplicador.length - 1; i >= 0; i--) {
126:                    if (limite != 0 && fator > limite)
127:                        fator = 2;
128:                    multiplicador[i] = fator++;
129:                }
130:
131:                for (int i = 0; i < field.length(); i++)
132:                    campo[i] = Integer.parseInt(field.substring(i, i + 1));
133:
134:                for (int i = 0; i < resultado.length; i++)
135:                    resultado[i] = campo[i] * multiplicador[i];
136:
137:                for (int i = 0; i < resultado.length; i++)
138:                    total += resultado[i];
139:
140:                int DV = 11 - (total % 11);
141:
142:                return String.valueOf((DV == 10 | DV == 11) ? 0 : DV);
143:            }
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.