diff --git a/README.md b/README.md
new file mode 100644
index 0000000..db1286d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,68 @@
+Read-Write Sets Implementation
+==============================
+
+[](https://gitter.im/fulano7/ProjetoCompiladores?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+
+Directories
+-----------
+
+```bin``` - build files (e.g., class files).
+```code``` - instrumentation - ignore.
+```dat``` - resources (e.g., .xml and .txt configuration files).
+```docs``` - some documentation.
+```example-apps``` - sample applications to demo this project.
+```libs``` - java libraries (.jar files).
+```results``` - temporary directory to store execution-generated files.
+```scripts``` - script to use the system.
+```src``` - source of the read-writes set implementation.
+```src-tests``` - source of test cases.
+
+Files modified in this fork
+---------------------------
+
+* Added several files under directories ```src-tests/rwsets``` and ```example-apps```.
+* Added file ```rwset_bugs```.
+* ```src-tests/rwsets/Helper.java``` - Modified
+* ```src-tests/rwsets/AllTests.java``` - Modified
+* ```README.txt``` - changed to ```README.md``` and added some stuff.
+
+Apps used in the tests
+----------------------
+
+* ```Projeto IP``` - small app that models a delivery management system, featuring very simple classes, interfaces and subpackages.
+* ```Restaurante``` - same as ```Projeto IP```, with all the code in a single package.
+* ```Projeto PG``` - complex app that models graphic processing of surfaces.
+* ```Projeto GDI``` - simple app that connects to an Oracle database and inserts one row into one table.
+
+Configuration
+-------------
+
+Please follow configuration instructions in the following files for
+your setup.
+
+Please choose either ```Mac OS```, ```Unix``` or ```Windows```, if you want our support. Detailed
+setup information can be found at ```docs/CONFIG_MAC```, ```docs/CONFIG_UNIX``` and ```docs/CONFIG_WINDOWS```.
+
+Please use ```JDK 1.7```. We apologize for this inconvenience, we should
+address this limitation in the future.
+
+Documentation
+-------------
+
+```docs/RWSETS.txt``` - summarized explanation of the read-write sets algorithm.
+```docs/TRY.txt``` - info on how to use the system from the command line.
+
+Known issues
+------------
+
+- Unpredictable results for ```JDK``` different than ```1.7```.
+- The directory where ```Java Runtime``` libraries are located is hardcoded in ```wala.properties```.
+- Doesn't provide support for ```implements``` clause.
+- Command-line script only handles ```Unix``` and ```Mac OS``` installations. Run scripts on Windows requires [Cygwin](https://www.cygwin.com) installed.
+- ./scripts/runRegressionTests breaks (mab@cin.ufpe.br is working on this).
+- 2 tests are ignored (mab@cin.ufpe.br is working on this).
+
+Questions
+---------
+
+if688-l@cin.ufpe.br
diff --git a/README.txt b/README.txt
deleted file mode 100644
index 545ca78..0000000
--- a/README.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-=== Read-Write Sets Implementation ===
-
-> Directories
-
-bin - build files (e.g., class files)
-code-instrumentation - ignore
-dat - resources (e.g., xml and txt configuration files)
-docs - some documentation
-example-apps - sample applications to demo this project
-libs - java libraries (.jar files)
-results - temporary directory to store execution-generated files
-scripts - script to use the system
-src - source of the read-writes set implementation
-src-tests - source of test cases
-
-=========================================
-
-> Configuration
-
-Please follow configuration instructions in the following files for
-your setup.
-
-Please choose either MAC or UNIX, if you want our support. Detailed
-setup information can be found at docs/CONFIG_MAC and
-docs/CONFIG_UNIX.
-
-Please use JDK 1.7. We apologize for this inconvenience, we should
-address this limitation in the future.
-
-=========================================
-
-> Documentation
-
-docs/RWSETS.txt - summarized explanation of the read-write sets algo
-docs/TRY.txt - info on how to use the system from the command line
-
-=========================================
-
-> Known issues
-
-- Unpredictable results for JDK different than 1.7
-- Command-line script only handle unix and macos installations
-- ./scripts/runRegressionTests breaks
- (mab@cin is working on this)
-- 2 tests are ignored
- (mab@cin is working on this)
-
-=========================================
-
-> Questions
-
-if688-l@cin.ufpe.br
diff --git a/example-apps/PG_Projeto_2.jar b/example-apps/PG_Projeto_2.jar
new file mode 100644
index 0000000..83116f8
Binary files /dev/null and b/example-apps/PG_Projeto_2.jar differ
diff --git a/example-apps/projetoGDI.jar b/example-apps/projetoGDI.jar
new file mode 100644
index 0000000..cdf12d4
Binary files /dev/null and b/example-apps/projetoGDI.jar differ
diff --git a/example-apps/projetoip.jar b/example-apps/projetoip.jar
new file mode 100644
index 0000000..f784464
Binary files /dev/null and b/example-apps/projetoip.jar differ
diff --git a/example-apps/projetoipempacotado.jar b/example-apps/projetoipempacotado.jar
new file mode 100644
index 0000000..fafc522
Binary files /dev/null and b/example-apps/projetoipempacotado.jar differ
diff --git a/example-apps/src/IP/br/ufpe/cin/dados/IRepositorio.java b/example-apps/src/IP/br/ufpe/cin/dados/IRepositorio.java
new file mode 100644
index 0000000..74b8ff7
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/dados/IRepositorio.java
@@ -0,0 +1,19 @@
+package br.ufpe.cin.dados;
+
+import java.util.Iterator;
+
+import br.ufpe.cin.exception.ClienteJaCadastradoException;
+import br.ufpe.cin.exception.ClienteNaoCadastradoException;
+import br.ufpe.cin.exception.PedidoNaoExistenteException;
+import br.ufpe.cin.exception.ProdutoJaCadastradoException;
+import br.ufpe.cin.exception.ProdutoNaoCadastradoException;
+
+public interface IRepositorio {
+ void inserir(T valor) throws ClienteJaCadastradoException,
+ ProdutoJaCadastradoException;
+
+ void remover(T valor) throws ClienteNaoCadastradoException,
+ PedidoNaoExistenteException, ProdutoNaoCadastradoException;
+
+ Iterator procurar(T valor);
+}
diff --git a/example-apps/src/IP/br/ufpe/cin/dados/RepositorioClientesArray.java b/example-apps/src/IP/br/ufpe/cin/dados/RepositorioClientesArray.java
new file mode 100644
index 0000000..f2a5a92
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/dados/RepositorioClientesArray.java
@@ -0,0 +1,65 @@
+package br.ufpe.cin.dados;
+
+import java.util.Iterator;
+
+import br.ufpe.cin.exception.ClienteJaCadastradoException;
+import br.ufpe.cin.exception.ClienteNaoCadastradoException;
+import br.ufpe.cin.restaurante.Cliente;
+
+public class RepositorioClientesArray implements IRepositorio {
+ private Cliente[] clientes;
+ private int indice;
+
+ public RepositorioClientesArray(int tamanhoArray) {
+ this.clientes = new Cliente[tamanhoArray];
+ this.indice = 0;
+ }
+
+ public void inserir(Cliente cliente)
+ throws ClienteJaCadastradoException {
+ if (this.procurar(cliente.getTelefone()) == null) {
+ clientes[indice] = cliente;
+ indice++;
+ } else {
+ throw new ClienteJaCadastradoException();
+ }
+ }
+
+ public void remover(Cliente cliente) throws ClienteNaoCadastradoException {
+ if (this.procurar(cliente.getTelefone()) == null) {
+ throw new ClienteNaoCadastradoException();
+ } else {
+ clientes[this.getPosicao(cliente)] = clientes[indice - 1];
+ clientes[indice - 1] = null;
+ indice--;
+
+ }
+ }
+
+ private Cliente procurar(String telefone) {
+ Cliente retorno = null;
+ boolean achou = false;
+ for (int i = 0; i < indice && !achou; i++) {
+ if (clientes[i].getTelefone().equals(telefone)) {
+ retorno = clientes[i];
+ }
+ }
+ return retorno;
+ }
+
+ private int getPosicao(Cliente cliente) {
+ int resposta = 0;
+ for (int i = 0; i < indice; i++) {
+ if (clientes[i].getTelefone() == cliente.getTelefone()) {
+ resposta = i;
+ }
+ }
+ return resposta;
+ }
+
+ @Override
+ public Iterator procurar(Cliente valor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/example-apps/src/IP/br/ufpe/cin/dados/RepositorioPedidosArray.java b/example-apps/src/IP/br/ufpe/cin/dados/RepositorioPedidosArray.java
new file mode 100644
index 0000000..eb3234b
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/dados/RepositorioPedidosArray.java
@@ -0,0 +1,59 @@
+package br.ufpe.cin.dados;
+
+import java.util.Iterator;
+
+import br.ufpe.cin.exception.PedidoNaoExistenteException;
+import br.ufpe.cin.restaurante.Pedido;
+
+public class RepositorioPedidosArray {
+ // implements IRepositorio
+ private Pedido[] pedidos;
+ private int indice;
+
+ public RepositorioPedidosArray(int tamanhoArray) {
+ this.pedidos = new Pedido[tamanhoArray];
+ this.indice = 0;
+ }
+
+ public void inserir(Pedido pedido) {
+ this.pedidos[indice] = pedido;
+ this.indice++;
+ }
+
+ public void remover(Pedido pedido)
+ throws PedidoNaoExistenteException {
+ if (this.procurar(pedido.getCodigo()) == null) {
+ throw new PedidoNaoExistenteException();
+ } else {
+ pedidos[this.getPosicao(pedido)] = pedidos[indice - 1];
+ pedidos[indice - 1] = null;
+ indice--;
+
+ }
+ }
+
+ private Pedido procurar(String codigo) {
+ Pedido retorno = null;
+ boolean achou = false;
+ for (int i = 0; i < indice && !achou; i++) {
+ if (pedidos[i].getCodigo().equals(codigo)) {
+ retorno = pedidos[i];
+ }
+ }
+ return retorno;
+ }
+
+ private int getPosicao(Pedido pedido) {
+ int posicao = 0;
+ for (int i = 0; i < indice; i++) {
+ if (pedidos[i].getCodigo() == pedido.getCodigo()) {
+ posicao = i;
+ }
+ }
+ return posicao;
+ }
+
+ public Iterator procurar(Pedido valor) {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/example-apps/src/IP/br/ufpe/cin/dados/RepositorioProdutosArray.java b/example-apps/src/IP/br/ufpe/cin/dados/RepositorioProdutosArray.java
new file mode 100644
index 0000000..7452f4c
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/dados/RepositorioProdutosArray.java
@@ -0,0 +1,67 @@
+package br.ufpe.cin.dados;
+
+import java.util.Iterator;
+
+import br.ufpe.cin.exception.ProdutoJaCadastradoException;
+import br.ufpe.cin.exception.ProdutoNaoCadastradoException;
+import br.ufpe.cin.restaurante.Produto;
+
+public class RepositorioProdutosArray implements IRepositorio{
+
+ private Produto[] produtos;
+ private int indice;
+
+ public RepositorioProdutosArray(int tamanhoArray) {
+ this.produtos = new Produto[tamanhoArray];
+ this.indice = 0;
+ }
+
+ public void inserir(Produto produto)
+ throws ProdutoJaCadastradoException {
+ if (this.procurar(produto.getCodigo()) == null) {
+ produtos[indice] = produto;
+ indice++;
+ } else {
+ throw new ProdutoJaCadastradoException();
+ }
+ }
+
+ public void remover(Produto produto)
+ throws ProdutoNaoCadastradoException {
+ if (this.procurar(produto.getCodigo()) == null) {
+ throw new ProdutoNaoCadastradoException();
+ } else {
+ produtos[this.getPosicao(produto)] = produtos[indice - 1];
+ produtos[indice - 1] = null;
+ indice--;
+
+ }
+ }
+
+ private Produto procurar(String codigo) {
+ Produto retorno = null;
+ boolean achou = false;
+ for (int i = 0; i < indice && !achou; i++) {
+ if (produtos[i].getCodigo().equals(codigo)) {
+ retorno = produtos[i];
+ }
+ }
+ return retorno;
+ }
+
+ private int getPosicao(Produto produto) {
+ int resposta = 0;
+ for (int i = 0; i < indice; i++) {
+ if (produtos[i].getCodigo() == produto.getCodigo()) {
+ resposta = i;
+ }
+ }
+ return resposta;
+ }
+
+ @Override
+ public Iterator procurar(Produto valor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/example-apps/src/IP/br/ufpe/cin/exception/ClienteJaCadastradoException.java b/example-apps/src/IP/br/ufpe/cin/exception/ClienteJaCadastradoException.java
new file mode 100644
index 0000000..84866fa
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/exception/ClienteJaCadastradoException.java
@@ -0,0 +1,13 @@
+package br.ufpe.cin.exception;
+
+public class ClienteJaCadastradoException extends Exception{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6490933969455438764L;
+
+ public ClienteJaCadastradoException(){
+ super("O cliente ja esta cadastrado.");
+ }
+}
diff --git a/example-apps/src/IP/br/ufpe/cin/exception/ClienteNaoCadastradoException.java b/example-apps/src/IP/br/ufpe/cin/exception/ClienteNaoCadastradoException.java
new file mode 100644
index 0000000..be0e9cb
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/exception/ClienteNaoCadastradoException.java
@@ -0,0 +1,13 @@
+package br.ufpe.cin.exception;
+
+public class ClienteNaoCadastradoException extends Exception{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4855606300053472516L;
+
+ public ClienteNaoCadastradoException(){
+ super("Cliente nao cadastrado.");
+ }
+}
diff --git a/example-apps/src/IP/br/ufpe/cin/exception/PedidoNaoExistenteException.java b/example-apps/src/IP/br/ufpe/cin/exception/PedidoNaoExistenteException.java
new file mode 100644
index 0000000..6e4c7fe
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/exception/PedidoNaoExistenteException.java
@@ -0,0 +1,13 @@
+package br.ufpe.cin.exception;
+
+public class PedidoNaoExistenteException extends Exception{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 9143022182046227046L;
+
+ public PedidoNaoExistenteException(){
+ super("Pedido nao existente.");
+ }
+}
diff --git a/example-apps/src/IP/br/ufpe/cin/exception/ProdutoJaCadastradoException.java b/example-apps/src/IP/br/ufpe/cin/exception/ProdutoJaCadastradoException.java
new file mode 100644
index 0000000..86b89f3
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/exception/ProdutoJaCadastradoException.java
@@ -0,0 +1,13 @@
+package br.ufpe.cin.exception;
+
+public class ProdutoJaCadastradoException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3967223092703092831L;
+
+ public ProdutoJaCadastradoException() {
+ super("Produto ja cadastrado.");
+ }
+}
diff --git a/example-apps/src/IP/br/ufpe/cin/exception/ProdutoNaoCadastradoException.java b/example-apps/src/IP/br/ufpe/cin/exception/ProdutoNaoCadastradoException.java
new file mode 100644
index 0000000..f19acf2
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/exception/ProdutoNaoCadastradoException.java
@@ -0,0 +1,13 @@
+package br.ufpe.cin.exception;
+
+public class ProdutoNaoCadastradoException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7251989337883106223L;
+
+ public ProdutoNaoCadastradoException() {
+ super("Produto nao cadastrado.");
+ }
+}
diff --git a/example-apps/src/IP/br/ufpe/cin/restaurante/Cliente.java b/example-apps/src/IP/br/ufpe/cin/restaurante/Cliente.java
new file mode 100644
index 0000000..f901a4a
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/restaurante/Cliente.java
@@ -0,0 +1,59 @@
+package br.ufpe.cin.restaurante;
+
+public class Cliente {
+
+ private String cpf;
+ private String telefone;
+ private String endereco;
+ private String nome;
+ private String observacoes;
+
+ public Cliente(String cpf, String telefone, String nome, String endereco, String observacoes){
+ this.cpf = cpf;
+ this.endereco = endereco;
+ this.nome = nome;
+ this.observacoes = observacoes;
+ this.telefone = telefone;
+ }
+
+ public String getTelefone() {
+ return telefone;
+ }
+
+ public String getCpf() {
+ return cpf;
+ }
+
+ public void setCpf(String cpf) {
+ this.cpf = cpf;
+ }
+
+ public String getEndereco() {
+ return endereco;
+ }
+
+ public void setEndereco(String endereco) {
+ this.endereco = endereco;
+ }
+
+ public String getNome() {
+ return nome;
+ }
+
+ public void setNome(String nome) {
+ this.nome = nome;
+ }
+
+ public String getObservacoes() {
+ return observacoes;
+ }
+
+ public void setObservacoes(String observacoes) {
+ this.observacoes = observacoes;
+ }
+
+ public void setTelefone(String telefone) {
+ this.telefone = telefone;
+ }
+
+}
diff --git a/example-apps/src/IP/br/ufpe/cin/restaurante/Pedido.java b/example-apps/src/IP/br/ufpe/cin/restaurante/Pedido.java
new file mode 100644
index 0000000..f3c2261
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/restaurante/Pedido.java
@@ -0,0 +1,71 @@
+package br.ufpe.cin.restaurante;
+
+import java.math.BigDecimal;
+
+public class Pedido {
+ private String codigo;
+ private Cliente cliente;
+ private Produto[] produtos;
+ private String data;
+ private int quantidade;
+ private BigDecimal valor;
+
+ public Pedido(String codigo, Cliente cliente, Produto[] produtos,
+ String data, int quantidade, BigDecimal valor) {
+ this.cliente = cliente;
+ this.codigo = codigo;
+ this.data = data;
+ this.produtos = produtos;
+ this.quantidade = quantidade;
+ this.valor = valor;
+ }
+
+ public Cliente getCliente() {
+ return cliente;
+ }
+
+ public void setCliente(Cliente cliente) {
+ this.cliente = cliente;
+ }
+
+ public Produto[] getProdutos() {
+ return produtos;
+ }
+
+ public void setProdutos(Produto[] produtos) {
+ this.produtos = produtos;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public int getQuantidade() {
+ return quantidade;
+ }
+
+ public void setQuantidade(int quantidade) {
+ this.quantidade = quantidade;
+ }
+
+ public BigDecimal getValor() {
+ return valor;
+ }
+
+ public void setValor(BigDecimal valor) {
+ this.valor = valor;
+ }
+
+ public void setCodigo(String codigo) {
+ this.codigo = codigo;
+ }
+
+ public String getCodigo() {
+ return codigo;
+ }
+
+}
diff --git a/example-apps/src/IP/br/ufpe/cin/restaurante/Produto.java b/example-apps/src/IP/br/ufpe/cin/restaurante/Produto.java
new file mode 100644
index 0000000..abb763b
--- /dev/null
+++ b/example-apps/src/IP/br/ufpe/cin/restaurante/Produto.java
@@ -0,0 +1,60 @@
+package br.ufpe.cin.restaurante;
+
+import java.math.BigDecimal;
+
+public class Produto {
+ private String codigo;
+ private String nome;
+ private String descricao;
+ private char tamanho;
+ private BigDecimal valor;
+
+ public Produto(String codigo, String nome, String descricao, char tamanho, BigDecimal valor){
+ this.codigo = codigo;
+ this.nome = nome;
+ this.descricao = descricao;
+ this.tamanho = tamanho;
+ this.valor = valor;
+ }
+
+ public String getCodigo() {
+ return codigo;
+ }
+
+ public String getNome() {
+ return nome;
+ }
+
+ public void setNome(String nome) {
+ this.nome = nome;
+ }
+
+ public String getDescricao() {
+ return descricao;
+ }
+
+ public void setDescricao(String descricao) {
+ this.descricao = descricao;
+ }
+
+ public char getTamanho() {
+ return tamanho;
+ }
+
+ public void setTamanho(char tamanho) {
+ this.tamanho = tamanho;
+ }
+
+ public BigDecimal getValor() {
+ return valor;
+ }
+
+ public void setValor(BigDecimal valor) {
+ this.valor = valor;
+ }
+
+ public void setCodigo(String codigo) {
+ this.codigo = codigo;
+ }
+
+}
diff --git a/example-apps/src/PG_Projeto_2/pgprojeto2/Bounding.java b/example-apps/src/PG_Projeto_2/pgprojeto2/Bounding.java
new file mode 100644
index 0000000..6797903
--- /dev/null
+++ b/example-apps/src/PG_Projeto_2/pgprojeto2/Bounding.java
@@ -0,0 +1,43 @@
+package pgprojeto2;
+
+public class Bounding {
+ double x_topo;
+ double x_base;
+ double y_topo;
+ double y_base;
+ double z_topo;
+ double z_base;
+ public Bounding(Objeto objeto){
+ x_base = objeto.pontos_vista[0].x;
+ y_base = objeto.pontos_vista[0].x;
+ z_base = objeto.pontos_vista[0].x;
+ x_topo = x_base;
+ y_topo = y_base;
+ z_topo = z_base;
+ for (int i = 0; i < objeto.pontos_vista.length; i++) {
+ //setando x_base e x_topo
+ if(objeto.pontos_vista[i].x < x_base){
+ x_base = objeto.pontos_vista[i].x;
+ }
+ if(objeto.pontos_vista[i].x > x_topo){
+ x_topo = objeto.pontos_vista[i].x;
+ }
+ //setando y_base e y_topo como os respect valores menores e maiores dos pontos nas coord
+ if(objeto.pontos_vista[i].y < y_base){
+ y_base = objeto.pontos_vista[i].y;
+ }
+ if(objeto.pontos_vista[i].y > y_topo){
+ y_topo = objeto.pontos_vista[i].y;
+ }
+ //setando z_base e z_topo
+ if(objeto.pontos_vista[i].z < z_base){
+ z_base = objeto.pontos_vista[i].z;
+ }
+ if(objeto.pontos_vista[i].z > z_topo){
+ z_topo = objeto.pontos_vista[i].z;
+ }
+
+
+ }
+ }
+}
diff --git a/example-apps/src/PG_Projeto_2/pgprojeto2/Box.java b/example-apps/src/PG_Projeto_2/pgprojeto2/Box.java
new file mode 100644
index 0000000..c06f877
--- /dev/null
+++ b/example-apps/src/PG_Projeto_2/pgprojeto2/Box.java
@@ -0,0 +1,12 @@
+package pgprojeto2;
+import java.awt.image.BufferedImage;
+
+
+public class Box {
+ BufferedImage[] imagem;
+ Box(BufferedImage[] imagem){
+ this.imagem = imagem;
+ }
+
+
+}
diff --git a/example-apps/src/PG_Projeto_2/pgprojeto2/Camera.java b/example-apps/src/PG_Projeto_2/pgprojeto2/Camera.java
new file mode 100644
index 0000000..a8de973
--- /dev/null
+++ b/example-apps/src/PG_Projeto_2/pgprojeto2/Camera.java
@@ -0,0 +1,16 @@
+package pgprojeto2;
+
+public class Camera {
+ Ponto C, V, N, U;
+ double d, hx, hy;
+
+ public Camera(Ponto C, Ponto V, Ponto N, Ponto U, double d, double hx, double hy) {
+ this.C = C;
+ this.V = V;
+ this.N = N;
+ this.U = U;
+ this.d = d;
+ this.hx = hx;
+ this.hy = hy;
+ }
+}
diff --git a/example-apps/src/PG_Projeto_2/pgprojeto2/Core.java b/example-apps/src/PG_Projeto_2/pgprojeto2/Core.java
new file mode 100644
index 0000000..c60783e
--- /dev/null
+++ b/example-apps/src/PG_Projeto_2/pgprojeto2/Core.java
@@ -0,0 +1,561 @@
+package pgprojeto2;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.image.BufferedImage;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+
+public class Core extends JFrame {
+ static Core core;
+ static boolean objeto_temporario = false;
+ static boolean superficie_temporaria = false;
+ static Object atual;
+
+ private static final long serialVersionUID = 1L;
+
+ public Core(Camera camera, Objeto objeto, Luz lux, Box box, Bounding box2) {
+ iniciaInterface(camera, objeto, lux, box, box2);
+ }
+
+ private void iniciaInterface(Camera camera, Objeto objeto, Luz lux, Box box, Bounding box2) {
+ setTitle("Projeto 2 PG");
+ add(new Superficie(camera, objeto, lux, box, box2));
+ setSize(800, 600);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setLocationRelativeTo(null);
+ setResizable(false);
+ }
+
+ private static Camera leitura_camera(BufferedReader paramCamera)
+ throws NumberFormatException, IOException {
+ Ponto C, V, N, U;
+ double d = 0, hx = 0, hy = 0, norma;
+ String x, y, z, linha;
+ String[] temp;
+ // pega as informações da camera:
+ if (paramCamera.ready()) {
+ // lê as coordenadas do vetor C:
+ linha = paramCamera.readLine();
+ temp = linha.split(" ");
+ x = temp[0];
+ y = temp[1];
+ z = temp[2];
+ C = new Ponto(Double.valueOf(x), Double.valueOf(y),
+ Double.valueOf(z));
+ // lê as coordenadas do vetor N:
+ linha = paramCamera.readLine();
+ temp = linha.split(" ");
+ x = temp[0];
+ y = temp[1];
+ z = temp[2];
+ N = new Ponto(Double.valueOf(x), Double.valueOf(y),
+ Double.valueOf(z));
+ // lê as coordenadas do vetor V:
+ linha = paramCamera.readLine();
+ temp = linha.split(" ");
+ x = temp[0];
+ y = temp[1];
+ z = temp[2];
+ V = new Ponto(Double.valueOf(x), Double.valueOf(y),
+ Double.valueOf(z));
+ // lê d, hx e hy:
+ linha = paramCamera.readLine();
+ temp = linha.split(" ");
+ d = Double.valueOf(temp[0]);
+ hx = Double.valueOf(temp[1]);
+ hy = Double.valueOf(temp[2]);
+
+ // fecha o arquivo:
+ paramCamera.close();
+
+ // normaliza N:
+ norma = Math.sqrt(Operador.produto_interno(N, N));
+ N.x = N.x / norma;
+ N.y = N.y / norma;
+ N.z = N.z / norma;
+ // ortogonaliza V:
+ double coef = (Operador.produto_interno(V, N) / Operador
+ .produto_interno(N, N));
+
+ V.x = V.x - (coef * N.x);
+ V.y = V.y - (coef * N.y);
+ V.z = V.z - (coef * N.z);
+ // normaliza V:
+ norma = Math.sqrt(Operador.produto_interno(V, V));
+ V.x = V.x / norma;
+ V.y = V.y / norma;
+ V.z = V.z / norma;
+ // calcula U:
+ U = Operador.produto_vetorial(N, V);
+
+ Camera infoCam = new Camera(C, V, N, U, d, hx, hy);
+
+ return infoCam;
+ } else {
+ System.out.println("erro abertura de arquivo");
+ return null;
+ }
+
+ }
+
+ private static Objeto leitura_objeto(Camera camera,
+ BufferedReader paramObjeto) throws IOException {
+ Ponto pontos_visao[] = null, pontos[] = null;
+ int qnt_pontos, qnt_triangulos, triangulos[][] = null;
+ Ponto normais_triangulos[] = null, normais_vertices[] = null;
+ double esq, dir, cima, baixo, perto, longe;
+ String x, y, z, linha, temp[];
+ if (paramObjeto.ready()) {
+ // lê as quantidades de pontos e de triangulos:
+ linha = paramObjeto.readLine();
+ qnt_pontos = Integer
+ .valueOf(linha.substring(0, linha.indexOf(' ')));
+ qnt_triangulos = Integer
+ .valueOf(linha.substring(linha.indexOf(' ') + 1));
+
+ // inicia os respectivos arrays:
+ pontos = new Ponto[qnt_pontos];
+ pontos_visao = new Ponto[qnt_pontos];
+ triangulos = new int[qnt_triangulos][3];
+ // lê todos os pontos:
+ for (int c = 0; c < qnt_pontos; c++) {
+ linha = paramObjeto.readLine();
+ temp = linha.split(" ");
+ if (linha.charAt(0) == ' ') {
+ x = temp[1];
+ y = temp[2];
+ z = temp[3];
+ } else {
+ x = temp[0];
+ y = temp[1];
+ z = temp[2];
+ }
+ pontos[c] = new Ponto(Double.valueOf(x), Double.valueOf(y),
+ Double.valueOf(z));
+ pontos[c].indice = c;
+ }
+ // lê todos os triangulos:
+ for (int c = 0; c < qnt_triangulos; c++) {
+ do {
+ linha = paramObjeto.readLine();
+ } while (linha.isEmpty());
+
+ temp = linha.split(" ");
+ if (linha.charAt(0) == ' ') {
+ x = temp[1];
+ y = temp[2];
+ z = temp[3];
+ } else {
+ x = temp[0];
+ y = temp[1];
+ z = temp[2];
+ }// guarda o indice de cada vertice no array de pontos:
+ triangulos[c][0] = Integer.valueOf(x) - 1;
+ triangulos[c][1] = Integer.valueOf(y) - 1;
+ triangulos[c][2] = Integer.valueOf(z) - 1;
+ }
+
+ // converte os pontos para coordenadas de visão:
+ for (int c = 0; c < qnt_pontos; c++) {
+ // calcula P - C:
+ pontos[c].x -= camera.C.x;
+ pontos[c].y -= camera.C.y;
+ pontos[c].z -= camera.C.z;
+
+ // multiplica P-C pela matriz de mudança de base:
+ double x_visao = (pontos[c].x * camera.U.x)
+ + (pontos[c].y * camera.U.y)
+ + (pontos[c].z * camera.U.z);
+ double y_visao = (pontos[c].x * camera.V.x)
+ + (pontos[c].y * camera.V.y)
+ + (pontos[c].z * camera.V.z);
+ double z_visao = (pontos[c].x * camera.N.x)
+ + (pontos[c].y * camera.N.y)
+ + (pontos[c].z * camera.N.z);
+
+ pontos_visao[c] = new Ponto(x_visao, y_visao, z_visao);
+ pontos_visao[c].indice = c;
+ }
+
+ //inicializa ptos extremos
+ esq = pontos_visao[0].x;
+ dir = esq;
+ cima = pontos_visao[0].y;
+ baixo = cima;
+ perto = pontos_visao[0].z;
+ longe = perto;
+
+ for (int c = 0; c < qnt_pontos; c++) {
+ if (pontos_visao[c].x < esq) {
+ esq = pontos_visao[c].x;
+ } else if (pontos_visao[c].x > dir) {
+ dir = pontos_visao[c].x;
+ } else if (pontos_visao[c].y < baixo) {
+ baixo = pontos_visao[c].y;
+ } else if (pontos_visao[c].y > cima) {
+ cima = pontos_visao[c].y;
+ } else if (pontos_visao[c].z < perto) {
+ perto = pontos_visao[c].z;
+ } else if (pontos_visao[c].z > longe) {
+ longe = pontos_visao[c].z;
+ }
+ }
+
+ // pontos em coordenadas de tela:
+ for (int c = 0; c < qnt_pontos; c++) {
+ double x_temp, y_temp, z_temp;
+ x_temp = pontos_visao[c].x;
+ y_temp = pontos_visao[c].y;
+ z_temp = pontos_visao[c].z;
+
+ pontos[c].x = (camera.d / camera.hx) * (x_temp / z_temp);
+ pontos[c].y = (camera.d / camera.hy) * (y_temp / z_temp);
+ // coordenadas em 2D, temos z = 0:
+ pontos[c].z = 0;
+ pontos[c].indice = c;
+ }
+ paramObjeto.close();
+
+ Ponto v1 = new Ponto(0.0, 0.0, 0.0), v2 = new Ponto(1.0, 1.0, 1.0);
+ normais_triangulos = new Ponto[qnt_triangulos];
+ normais_vertices = new Ponto[qnt_pontos];
+ // inicia as normais de todos os vertices como 0:
+ for (int c = 0; c < qnt_pontos; c++) {
+ normais_vertices[c] = new Ponto(0.0, 0.0, 0.0);
+ }
+
+ // calcula a normal de todos os triangulos:
+ for (int c = 0; c < qnt_triangulos; c++) {
+ Ponto p1 = pontos_visao[triangulos[c][0]];
+ Ponto p2 = pontos_visao[triangulos[c][1]];
+ Ponto p3 = pontos_visao[triangulos[c][2]];
+
+ // calcula o vetor v1:
+ v1.x = p2.x - p1.x;
+ v1.y = p2.y - p1.y;
+ v1.z = p2.z - p1.z;
+ // calcula o vetor v2:
+ v2.x = p3.x - p1.x;
+ v2.y = p3.y - p1.y;
+ v2.z = p3.z - p1.z;
+
+ // calcula a normal, que é o produto vetorial entre v1 e v2:
+ normais_triangulos[c] = Operador.produto_vetorial(v1, v2);
+
+ // normaliza a normal do triangulo:
+ Operador.normalizar(normais_triangulos[c]);
+
+ //de forma mais eficiente, pela soma das normais dos vizinhos
+ // soma a normal do triangulo às normais dos vertices vizinhos que o formam
+ normais_vertices[triangulos[c][0]].x += normais_triangulos[c].x;
+ normais_vertices[triangulos[c][0]].y += normais_triangulos[c].y;
+ normais_vertices[triangulos[c][0]].z += normais_triangulos[c].z;
+
+ normais_vertices[triangulos[c][1]].x += normais_triangulos[c].x;
+ normais_vertices[triangulos[c][1]].y += normais_triangulos[c].y;
+ normais_vertices[triangulos[c][1]].z += normais_triangulos[c].z;
+
+ normais_vertices[triangulos[c][2]].x += normais_triangulos[c].x;
+ normais_vertices[triangulos[c][2]].y += normais_triangulos[c].y;
+ normais_vertices[triangulos[c][2]].z += normais_triangulos[c].z;
+ }
+
+ // normaliza as normais dos vértices:
+ for (int c = 0; c < qnt_pontos; c++) {
+ Operador.normalizar(normais_vertices[c]);
+ }
+
+ Objeto info = new Objeto(pontos_visao, pontos,
+ normais_triangulos, normais_vertices, triangulos);
+ return info;
+ } else {
+ System.out.println("nao abriu o objeto");
+ return null;
+ }
+ }
+
+ private static Luz leitura_luz(BufferedReader pIluminacao)
+ throws NumberFormatException, IOException {
+ String x, y, z, linha, temp[];
+ if (pIluminacao.ready()) {
+ Ponto pl, ia;
+ double ka, kd, ks, n;
+ double[] ip = new double[3];
+ double[] od = new double[3];
+ double[] id = new double[3];
+ // lê as coordenadas do ponto de luz:
+ linha = pIluminacao.readLine();
+ temp = linha.split(" ");
+ x = temp[0];
+ y = temp[1];
+ z = temp[2];
+ pl = new Ponto(Double.valueOf(x), Double.valueOf(y),
+ Double.valueOf(z));
+ // lê Ka:
+ linha = pIluminacao.readLine();
+ ka = Double.valueOf(linha);
+ // lê o vetor de cor ambiental Ia:
+ linha = pIluminacao.readLine();
+ temp = linha.split(" ");
+ x = temp[0];
+ y = temp[1];
+ z = temp[2];
+ ia = new Ponto(Double.valueOf(x), Double.valueOf(y),
+ Double.valueOf(z));
+ // lê Kd:
+ linha = pIluminacao.readLine();
+ kd = Double.valueOf(linha);
+ // lê o Od:
+ linha = pIluminacao.readLine();
+ temp = linha.split(" ");
+ x = temp[0];
+ y = temp[1];
+ z = temp[2];
+ od[0] = Double.valueOf(x);
+ od[1] = Double.valueOf(y);
+ od[2] = Double.valueOf(z);
+ // lê Ks:
+ linha = pIluminacao.readLine();
+ ks = Double.valueOf(linha);
+ // lê a cor da fonte de luz Il:
+ linha = pIluminacao.readLine();
+ temp = linha.split(" ");
+ x = temp[0];
+ y = temp[1];
+ z = temp[2];
+ ip[0] = Double.valueOf(x);
+ ip[1] = Double.valueOf(y);
+ ip[2] = Double.valueOf(z);
+ // lê a constante de rugosidade n:
+ linha = pIluminacao.readLine();
+ n = Double.valueOf(linha);
+
+ Luz lux_info = new Luz(pl, ia, ka, kd, ks, n, ip, od, id);
+ return lux_info;
+ } else {
+ System.out.println("nao abriu a iluminacao");
+ return null;
+ }
+ }
+
+ public static Box inic_box(BufferedImage[] imagem){
+ Box box = new Box(imagem);
+ return box;
+ }
+
+ public static Bounding inic_box2(Objeto objeto){
+ Bounding box = new Bounding(objeto);
+ return box;
+ }
+
+ public static void main(String[] args) throws NumberFormatException,
+ IOException {
+ final Camera camera = null;
+ final Objeto objeto = null;
+ final Luz lux = null;
+ final Box box = null;
+ final Bounding box2 = null;
+
+ final BufferedReader pCamera = null;
+ final BufferedReader pIluminacao = null;
+ final BufferedReader pObjeto = null;
+
+ //lendo imagem da textura
+ final BufferedImage[] pTextura = null;
+
+ JFrame novo = new JFrame();
+ novo.setTitle("Arquivos de Configuração");
+ novo.setSize(1000, 100);
+ novo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ novo.setLocationRelativeTo(null);
+ novo.setResizable(false);
+ novo.setLocation(0, 0);
+
+ JPanel panel = new JPanel();
+
+ JButton but = new JButton("Vai Objeto");
+ JButton butTex = new JButton("Selecionar Textura");
+
+ final JLabel cam = new JLabel("Camera");
+ JLabel objet = new JLabel("Objeto");
+ JLabel tex = new JLabel("Textura");
+
+ final JTextField cameraTxt = new JTextField(25);
+ final JTextField objTxt = new JTextField(25);
+ final JTextField textTxt = new JTextField("", 25);
+ textTxt.setEditable(false);
+
+ final JFileChooser chooser = new JFileChooser();
+ chooser.setMultiSelectionEnabled(true);
+
+ cameraTxt.setSize(100, 100);
+
+ panel.add(cam);
+ panel.add(cameraTxt);
+ panel.add(objet);
+ panel.add(objTxt);
+ panel.add(tex);
+ panel.add(textTxt);
+ panel.add(but);
+ panel.add(butTex);
+
+ novo.add(panel);
+
+ novo.setVisible(true);
+
+ butTex.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ // TODO Auto-generated method stub
+ try{
+ button2();
+ if(chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION){
+ return;
+ }
+ File[] files = chooser.getSelectedFiles();
+ String url = "";
+ for (int i = 0; i < files.length; i++) {
+ StringBuffer buffer = new StringBuffer("");
+ buffer.append(files[i].toString());
+ url = buffer.substring(0);
+ }
+ textTxt.setText(url);
+ // textTxt.setText("teste");
+ // } catch (FileNotFoundException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ } catch (NumberFormatException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ // } catch (IOException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ }
+ }
+ });
+
+ // caso clique no botão 1
+ but.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ try {
+ button1(pCamera, pIluminacao, pObjeto, pTextura, textTxt.getText(), cameraTxt.getText(),
+ objTxt.getText(), camera, objeto, box, box2, lux);
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NumberFormatException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ });
+
+ }
+
+ public static String button2(){
+ String entradaImagem = "dd";
+ return entradaImagem;
+
+ }
+
+ public static void button1(BufferedReader cameraParam,
+ BufferedReader iluninacaoParam, BufferedReader objetoParam, BufferedImage[] texturaParam, String urlImage,
+ String cameraIn, String objetoIn, Camera camera,
+ Objeto objeto, Box box, Bounding box2, Luz luz) throws NumberFormatException,
+ IOException {
+
+ String entradaCamera = "entradas\\Cameras\\" + cameraIn + ".cfg";
+ String entradaObjeto = "entradas\\Objetos\\" + objetoIn + ".byu";
+
+ cameraParam = new BufferedReader(new FileReader(entradaCamera));
+ iluninacaoParam = new BufferedReader(new FileReader("entradas\\iluminacao.txt"));
+ objetoParam = new BufferedReader(new FileReader(entradaObjeto));
+
+ if(!urlImage.equalsIgnoreCase("")){ //modificacao 00:13 dia 19
+ String[] urls = urlImage.split("C:");
+ int numImagens = urls.length-1;
+ texturaParam = new BufferedImage[numImagens];
+
+ for (int i = 1; i < urls.length; i++) {
+ String temp = urls[i];
+ StringBuffer buffer = new StringBuffer("");
+ buffer.append("C:");
+ buffer.append(temp);
+ urls[i] = buffer.substring(0);
+ texturaParam[i-1] = ImageIO.read(new File(urls[i]));;
+ }
+ }
+
+
+ camera = leitura_camera(cameraParam);
+
+ objeto = leitura_objeto(camera, objetoParam);
+ luz = leitura_luz(iluninacaoParam);
+
+ if(texturaParam != null){
+ box = inic_box(texturaParam);
+ box2 = inic_box2(objeto);
+ }
+
+ luz.Pl.x -= camera.C.x;
+ luz.Pl.y -= camera.C.y;
+ luz.Pl.z -= camera.C.z;
+
+ // if(pTextura != null){
+ // int txW = pTextura.getWidth();
+ // int txH = pTextura.getHeight();
+ // int[] pixels = pTextura.getRGB(0, 0, txH, txW, null, 0, txW);
+ // Color cor = new Color(pixels[0]);
+ //
+ // lux.Od[0] = (double)cor.getRed()/255;
+ // lux.Od[1] = (double)cor.getGreen()/255;
+ // lux.Od[2] = (double)cor.getBlue()/255;
+ // }
+
+ // multiplica P-C pela matriz de mudança de base:
+ double x_visao = (luz.Pl.x * camera.U.x) + (luz.Pl.y * camera.U.y)
+ + (luz.Pl.z * camera.U.z);
+ double y_visao = (luz.Pl.x * camera.V.x) + (luz.Pl.y * camera.V.y)
+ + (luz.Pl.z * camera.V.z);
+ double z_visao = (luz.Pl.x * camera.N.x) + (luz.Pl.y * camera.N.y)
+ + (luz.Pl.z * camera.N.z);
+
+ luz.Pl.x = x_visao;
+ luz.Pl.y = y_visao;
+ luz.Pl.z = z_visao;
+
+ if (objeto_temporario){
+ core.dispose();
+ } else if (superficie_temporaria){
+ core.dispose();
+ superficie_temporaria = false;
+ }
+
+ objeto_temporario = true;
+ core = new Core(camera, objeto, luz, box, box2);
+ SwingUtilities.invokeLater(new Runnable() {
+
+ public void run() {
+ core.setLocation(300, 0);
+ core.setVisible(true);
+
+ }
+ });
+ }
+}
diff --git a/example-apps/src/PG_Projeto_2/pgprojeto2/Luz.java b/example-apps/src/PG_Projeto_2/pgprojeto2/Luz.java
new file mode 100644
index 0000000..088cda8
--- /dev/null
+++ b/example-apps/src/PG_Projeto_2/pgprojeto2/Luz.java
@@ -0,0 +1,22 @@
+package pgprojeto2;
+
+public class Luz {
+ Ponto Pl, Ia;
+ double ka, kd, ks, n;
+ double[] Ip;
+ double[] Od;
+ double[] Id;
+
+ Luz(Ponto Pl, Ponto Ia, double ka, double kd, double ks, double n,
+ double[] Ip, double[] Od, double[] Id) {
+ this.Pl = Pl;
+ this.Ia = Ia;
+ this.ka = ka;
+ this.kd = kd;
+ this.ks = ks;
+ this.n = n;
+ this.Ip = Ip;
+ this.Od = Od;
+ this.Id = Id;
+ }
+}
diff --git a/example-apps/src/PG_Projeto_2/pgprojeto2/Objeto.java b/example-apps/src/PG_Projeto_2/pgprojeto2/Objeto.java
new file mode 100644
index 0000000..4662e8f
--- /dev/null
+++ b/example-apps/src/PG_Projeto_2/pgprojeto2/Objeto.java
@@ -0,0 +1,17 @@
+package pgprojeto2;
+
+class Objeto{
+ Ponto pontos_vista[], pontos_tela[], normais_triangulos[], normais_vertices[];
+ int triangulos[][];
+
+ public Objeto(Ponto[] pontos_visao, Ponto[] pontos_tela,
+ Ponto[] normais_triangulos, Ponto[] normais_vertices,
+ int[][] triangulos) {
+ this.pontos_vista = pontos_visao;
+ this.pontos_tela = pontos_tela;
+ this.normais_triangulos = normais_triangulos;
+ this.normais_vertices = normais_vertices;
+ this.triangulos = triangulos;
+ }
+
+}
diff --git a/example-apps/src/PG_Projeto_2/pgprojeto2/Operador.java b/example-apps/src/PG_Projeto_2/pgprojeto2/Operador.java
new file mode 100644
index 0000000..d2a0f55
--- /dev/null
+++ b/example-apps/src/PG_Projeto_2/pgprojeto2/Operador.java
@@ -0,0 +1,113 @@
+package pgprojeto2;
+
+public class Operador {
+
+ static double produto_interno(Ponto u, Ponto v) {
+ return (u.x * v.x) + (u.y * v.y) + (u.z * v.z);
+ }
+
+ static void normalizar(Ponto v){
+ double produto_interno = produto_interno(v, v);
+ double norma = Math.sqrt(produto_interno);
+ v.x /= norma;
+ v.y /= norma;
+ v.z /= norma;
+ }
+
+ static Ponto produto_vetorial(Ponto u, Ponto v) {
+ double i, j, k;
+ i = (u.y*v.z) - (u.z*v.y);
+ j = (u.z*v.x) - (u.x*v.z);
+ k = (u.x*v.y) - (u.y*v.x);
+
+ return new Ponto(i, j, k);
+ }
+
+ static double[] produto_fosco(double[] c1, double[] c2) {
+ double[] retorno = { c1[0] * c2[0], c1[1] * c2[1], c1[2] * c2[2] };
+ return retorno;
+ }
+
+ static double[] calcula_alfa_beta_gama(Ponto p, Ponto p1, Ponto p2, Ponto p3) {
+
+ double x = p.x, y = p.y, x1 = p1.x, x2 = p2.x, x3 = p3.x, y1 = p1.y, y2 = p2.y, y3 = p3.y;
+ double alfa, beta, gama;
+
+ double denom = ((x1 - x3) * (y2 - y3) - (y1 - y3) * (x2 - x3));
+ alfa = ((y2 - y3) * (x - x3) - ((x3 - x2) * (y3 - y))) / denom;
+ beta = (((y3 - y1) * (x - x3)) - ((x1 - x3) * (y3 - y))) / denom;
+ gama = 1.0 - alfa - beta;
+
+ double[] retorno = { alfa, beta, gama };
+ return retorno;
+ }
+
+ public static boolean inverter_normal(Ponto a, Ponto Normal, Ponto ponto_plano, Ponto centro){
+ double x = a.x - ponto_plano.x;
+ double y = a.y - ponto_plano.y;
+ double z = a.z - ponto_plano.z;
+
+ double lado_a = produto_interno(Normal, new Ponto(x, y, z));
+ //lado_a fica sendo um sinal indicando o lado:
+ lado_a = Math.signum(lado_a);
+
+ x = centro.x - ponto_plano.x;
+ y = centro.y - ponto_plano.y;
+ z = centro.z - ponto_plano.z;
+
+ double lado_centro = produto_interno(Normal, new Ponto(x, y, z));
+ //lado_centro fica sendo um sinal indicando o lado:
+ lado_centro = Math.signum(lado_centro);
+
+ if (lado_a == lado_centro){ //ambos estão no mesmo lado:
+ return true; //mande inverter a normal
+ } else if (lado_centro == 0){ //o centro do objeto pertence ao plano:
+ if (lado_a < 0){ //se o centro do objeto pertencer ao plano, forçe a normal a estar do lado positivo do plano
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false; //a normal já está apontando "para fora" do objeto, nao inverta
+ }
+ }
+
+ public static boolean quaseProximo(double a, double b) {
+ return Math.round(a) == Math.round(b);
+ }
+
+ public static int encontraLado(double ax, double ay, double bx, double by,
+ double cx, double cy) {
+ if (quaseProximo(bx - ax, 0)) { // vertical line
+ if (cx < bx) {
+ return by > ay ? 1 : -1;
+ }
+ if (cx > bx) {
+ return by > ay ? -1 : 1;
+ }
+ return 0;
+ }
+ if (quaseProximo(by - ay, 0)) { // horizontal line
+ if (cy < by) {
+ return bx > ax ? -1 : 1;
+ }
+ if (cy > by) {
+ return bx > ax ? 1 : -1;
+ }
+ return 0;
+ }
+ double coefic = (by - ay) / (bx - ax);
+ double intersectY = ay - ax * coefic;
+ double solocaoC = (coefic * cx) + intersectY;
+ if (coefic != 0) {
+ if (cy > solocaoC) {
+ return bx > ax ? 1 : -1;
+ }
+ if (cy < solocaoC) {
+ return bx > ax ? -1 : 1;
+ }
+ return 0;
+ }
+ return 0;
+ }
+}
diff --git a/example-apps/src/PG_Projeto_2/pgprojeto2/Ponto.java b/example-apps/src/PG_Projeto_2/pgprojeto2/Ponto.java
new file mode 100644
index 0000000..5e5ad71
--- /dev/null
+++ b/example-apps/src/PG_Projeto_2/pgprojeto2/Ponto.java
@@ -0,0 +1,25 @@
+package pgprojeto2;
+
+public class Ponto {
+ // implements Comparable
+ double x, y, z, s, t;
+ int indice;
+ int i, j;
+ double Od[];
+
+ Ponto(double x, double y, double z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ Od = new double[3];
+ Od[0] = 0.0; Od[1] = 0.0; Od[1] = 0.0;
+ }
+
+ public int compareTo(Ponto p) {
+ return (int) Math.signum(y - ((Ponto) p).y);
+ }
+
+ public String para_string(){
+ return "(" + this.x + ", " + this.y + ", " + this.z + ")";
+ }
+}
diff --git a/example-apps/src/PG_Projeto_2/pgprojeto2/Superficie.java b/example-apps/src/PG_Projeto_2/pgprojeto2/Superficie.java
new file mode 100644
index 0000000..3e1e636
--- /dev/null
+++ b/example-apps/src/PG_Projeto_2/pgprojeto2/Superficie.java
@@ -0,0 +1,463 @@
+package pgprojeto2;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Insets;
+import java.util.Arrays;
+
+import javax.swing.JPanel;
+
+public class Superficie extends JPanel {
+ Camera camera;
+ Objeto objeto;
+ Luz lux;
+ Box box; //bounding box
+ int pixels[];
+ int objIndex;
+ Bounding box2;
+
+ double z_buffer[][];
+ boolean is_superficie;
+ Graphics2D plataforma2d;
+
+ private static final long serialVersionUID = 2L;
+
+ public Superficie(Camera camera, Objeto objeto, Luz lux, Box box, Bounding box2) {
+ this.camera = camera;
+ this.objeto = objeto;
+ this.lux = lux;
+ this.box = box;
+ this.box2 = box2;
+ this.objIndex = 0;
+ }
+
+ public int[] mapping(Ponto P){
+ //fator fx
+ double fx, fy, fz;
+ if((P.x - box2.x_base) > 0){
+ fx = (double) (P.x - box2.x_base)/(box2.x_topo - box2.x_base);
+ }
+ else{
+ fx = Double.MIN_VALUE;
+ }
+ //fator fy
+ if((P.y - box2.y_base) > 0){
+ fy = (double) (P.y - box2.y_base)/(box2.y_topo - box2.y_base);
+ }
+ else{
+ fy = Double.MIN_VALUE;
+ }
+ //fator fz
+ if((P.z - box2.z_base) > 0){
+ fz = (double) (P.z - box2.z_base)/(box2.z_topo - box2.z_base);
+ }
+ else{
+ fz = Double.MIN_VALUE;
+ }
+
+ //pega a quantidade de imagens no box
+ int qtdImagens = box.imagem.length;
+
+ //converte o fz para inteiro multiplicado pela qtde de imagens (indica qual imagem a ser mapeada)
+ fz = Math.ceil(fz*qtdImagens);
+
+// System.out.println(fx);
+// System.out.println(fy);
+// System.out.println(fz);
+
+ int fzInt = (int) fz;
+
+ if(fzInt == 0) fzInt = 1; //caso fz seja 0
+ if(fzInt > qtdImagens) fzInt = qtdImagens;
+
+ int resY = box.imagem[fzInt-1].getHeight(); int resX = box.imagem[fzInt-1].getWidth();
+
+ fy = Math.ceil(fy*resY); fx = Math.ceil(fx*resX);
+
+ //acessa valor de fy inteiro pela resolucao da imagem fzInt
+ int fyInt = (int) fy;
+ //acessa valor de fx inteiro pela resolucao da imagem fzInt no comprimento
+ int fxInt = (int) fx;
+
+ int[] F = {fxInt, fyInt, fzInt};
+
+ return F;
+ }
+
+ public void zoom(){
+ if(camera.d > 0){
+ camera.C.z -= 10;
+ camera.N.z -= 10;
+ camera.U.z -= 10;
+ camera.V.z -= 10;
+ camera.d -= 10;
+ }
+ }
+
+ // public void mappingText(){
+ // int pixels[] = box.imagem.getRGB(0, 0, box.comp, box.alt, null, 0, box.comp);
+ // //indice do ponto corrente no objeto
+ // int objIndex = 0;
+ // //enquanto nao terminou de varrer para todos os ptos de visao
+ // while(objIndex < objeto.pontos_vista.length){
+ // for (int i = 0; i < box.comp; i++) {
+ // for (int j = 0; j < box.alt; j++) {
+ // // fx *= box.imagem.getWidth();
+ // //
+ // // //fator fy
+ // // double fy = (double) (box.pontos[i][j].y - box.y_base())/(box.y_topo() - box.y_base());
+ // // fy *= box.imagem.getHeight();
+ //
+ // //posicao correspondente do pixel do ponto na textura
+ // //int posTexelX = (int) (objeto.pontos_visao[objIndex].x*fx);
+ // //int posTexelY = (int) (objeto.pontos_visao[objIndex].y*fy);
+ //
+ // //capturado o inteiro do componente na matriz de pixels da imagem
+ // // int index = (int)(box.comp*fx + fy);
+ // // if(index < pixels.length){
+ // int componente = pixels[box.comp*j + i];
+ // Color cor = new Color(componente);
+ //
+ // //setando componentes RGB para o Od do pto
+ // if(objIndex >= objeto.pontos_vista.length){
+ // break;
+ // }
+ // objeto.pontos_vista[objIndex].Od[0] = (double) cor.getRed()/255;
+ // objeto.pontos_vista[objIndex].Od[1] = (double) cor.getGreen()/255;
+ // objeto.pontos_vista[objIndex].Od[2] = (double) cor.getBlue()/255;
+ // objIndex++;
+ //
+ // }
+ // }
+ // }
+ // }
+
+ private void scanline(int c, Ponto P1, Ponto P2, Ponto P3, double y,
+ double x_min, double x_max) {
+ Ponto P;
+
+ for (int x = (int) Math.round(x_min); x <= Math.round(x_max); x++) {
+ double[] temp = Operador.calcula_alfa_beta_gama(new Ponto(x, y, 0),
+ P1, P2, P3);
+ double alfa = temp[0];
+ double beta = temp[1];
+ double gama = temp[2];
+
+ // pega os pontos de visao:
+ Ponto P1_visao, P2_visao, P3_visao;
+
+ P1_visao = objeto.pontos_vista[P1.indice];
+ P2_visao = objeto.pontos_vista[P2.indice];
+ P3_visao = objeto.pontos_vista[P3.indice];
+
+ // calcula o ponto em coordenadas de visao:
+
+ P = new Ponto(alfa * P1_visao.x + beta * P2_visao.x + gama
+ * P3_visao.x, alfa * P1_visao.y + beta * P2_visao.y + gama
+ * P3_visao.y, alfa * P1_visao.z + beta * P2_visao.z + gama
+ * P3_visao.z);
+
+
+ //recebendo fatores de transformacao de textura na bounding box
+
+ //Baricentro
+ double Bari_X = ((P1_visao.x ) + (P2_visao.x ) + (P3_visao.x )) / 3;
+ double Bari_Y = ((P1_visao.y ) + (P2_visao.y ) + (P3_visao.y )) / 3;
+ double Bari_Z = ((P1_visao.z ) + (P2_visao.z ) + (P3_visao.z )) / 3;
+
+ Ponto bari = new Ponto(Bari_X, Bari_Y, Bari_Z);
+
+ double p1Dist_X = Math.pow((( alfa) - 0.33), 2);
+ double p1Dist_Y = Math.pow((( beta) - 0.33), 2);
+ double p1Dist_Z = Math.pow((( gama) - 0.33), 2);
+
+ double result = Math.sqrt(p1Dist_X + p1Dist_Y + p1Dist_Z);
+
+ //calculando Od da textura para cada ponto no scan
+ if(box != null){
+ int[] F = mapping(P);
+ //pega a cor da fz-esima imagem, acessando a cor RGB na posicao fx, fy
+ if(F[0] > box.imagem[F[2]-1].getWidth()){
+ F[0] = box.imagem[F[2]-1].getWidth();
+ }
+ if(F[1] > box.imagem[F[2]-1].getHeight()){
+ F[1] = box.imagem[F[2]-1].getHeight();
+ }
+ Color cor = new Color(box.imagem[F[2]-1].getRGB(F[0]-1, F[1]-1));
+ P.Od[0] = (double) cor.getRed()/255;
+ P.Od[1] = (double) cor.getGreen()/255;
+ P.Od[2] = (double) cor.getBlue()/255;
+ }
+//
+// if (result >= 0 && result <= 0.1) {
+// P.Od[0] = 1.0;
+// P.Od[1] = 0.0;
+// P.Od[2] = 0.0;
+// }else if (result >= 0.2 && result <= 0.3) {
+// P.Od[0] = 0.0;
+// P.Od[1] = 1.0;
+// P.Od[2] = 0.0;
+// }else if(result > 0.3){
+// P.Od[0] = 0.0;
+// P.Od[1] = 0.0;
+// P.Od[2] = 1.0;
+// }
+
+ // continua se esse ponto for mais na frente do que o que já havia
+ // sido pintado:
+ if (x >= 0 && y >= 0 && x < z_buffer.length
+ && y < z_buffer[0].length) {
+ if (P.z < z_buffer[(int) x][(int) y] && P.z > 0) {
+ // System.out.println(" : " + alfa + beta + gama);
+ // atualiza o z-buffer:
+ z_buffer[(int) x][(int) y] = P.z;
+ Ponto N = null;
+
+ // cria os vetores N1, N2 e N3:
+ Ponto N1 = objeto.normais_vertices[P1.indice];
+ Ponto N2 = objeto.normais_vertices[P2.indice];
+ Ponto N3 = objeto.normais_vertices[P3.indice];
+
+ // calcula o vetor N:
+ N = new Ponto(alfa * N1.x + beta * N2.x + gama * N3.x, alfa
+ * N1.y + beta * N2.y + gama * N3.y, alfa * N1.z
+ + beta * N2.z + gama * N3.z);
+
+ // normaliza N:
+ Operador.normalizar(N);
+
+ Ponto V = new Ponto((-1) * P.x, (-1) * P.y, (-1) * P.z);
+ // Se N não estiver apontando para o observador:
+
+ if (Operador.produto_interno(V, N) < 0) {
+ // inverte N:
+ N.x *= -1;
+ N.y *= -1;
+ N.z *= -1;
+ }
+
+ double[] cor = pincel(P, N);
+ plataforma2d.setColor(new Color((int) cor[0], (int) cor[1],
+ (int) cor[2]));
+ plataforma2d.drawLine((int) x, (int) y, (int) x, (int) y);
+
+ }
+ }
+ }
+ }
+
+ private void doDrawing(Graphics g) {
+ plataforma2d = (Graphics2D) g;
+
+ Dimension size = getSize();
+ // objeto parametrizado para laterais da janela:
+ Insets insets = getInsets();
+ //largura e altura da TELA:
+ int w = size.width - insets.left - insets.right;
+ int h = size.height - insets.top - insets.bottom;
+ // ------------------------------------------------------------------------
+ // ajusta as coordenadas de tela:
+ for (int c = 0; c < objeto.pontos_tela.length; c++) { // objeto.pontos_tela.length
+ objeto.pontos_tela[c].x = (int) ((objeto.pontos_tela[c].x + 1) * w / 2);
+ objeto.pontos_tela[c].y = (int) ((1 - objeto.pontos_tela[c].y) * h / 2);
+ }
+
+ // ------------------------------------------------------------------------
+ // inicializa o z-buffer:
+ z_buffer = new double[w + 10][h + 10];
+ for (int c = 0; c < w; c++) {
+ for (int i = 0; i < h; i++) {
+ z_buffer[c][i] = Double.MAX_VALUE;
+ }
+ }
+
+ // ---------------- SCANNER
+ // -----------------------------------------------
+ int limite;
+ limite = objeto.triangulos.length;
+
+ for (int c = 0; c < limite; c++) {
+ boolean reta_change = false;
+ Ponto P1 = null, P2, P3;
+ double x_min, x_max, y_max, y_min;
+ Ponto[] vertices = new Ponto[3];
+ // inicializa um array de vertices, diz se eh uma superficie
+ vertices[0] = objeto.pontos_tela[objeto.triangulos[c][0]];
+ vertices[1] = objeto.pontos_tela[objeto.triangulos[c][1]];
+ vertices[2] = objeto.pontos_tela[objeto.triangulos[c][2]];
+ // ordena pelo y em ordem crescente
+ Arrays.sort(vertices);
+ // P1 é o vértice de menor y:
+ P1 = vertices[0];
+
+ if (Operador.encontraLado(P1.x, (-1) * P1.y, vertices[1].x, (-1)
+ * vertices[1].y, vertices[2].x, (-1) * vertices[2].y) > 0) {
+ P2 = vertices[1];
+ P3 = vertices[2];
+ } else if (Operador.encontraLado(P1.x, (-1) * P1.y, vertices[1].x, (-1)
+ * vertices[1].y, vertices[2].x, (-1) * vertices[2].y) < 0) {
+ P2 = vertices[2];
+ P3 = vertices[1];
+ } else {
+ if (vertices[1].x < P1.x && vertices[2].x < P1.x) { // P1 à direita de P2 e P3
+ P2 = vertices[1];
+ P3 = vertices[2];
+ } else if (vertices[1].x > P1.x && vertices[2].x > P1.x) { // P1 à esq de P2 e P3
+ P2 = vertices[2];
+ P3 = vertices[1];
+
+ } else { //se nao calcula P2 e P3 pelo valor de x na coluna
+ if (vertices[1].x < vertices[2].x) {
+ P2 = vertices[1];
+ P3 = vertices[2];
+ } else {
+ P2 = vertices[2];
+ P3 = vertices[1];
+ }
+ }
+ }
+ //verifica se ptos formam um triangulo
+ boolean not_triangle = ((int) P1.x == (int) P2.x && (int) P1.y == (int) P2.y)
+ || ((int) P1.x == (int) P3.x && (int) P1.y == (int) P3.y)
+ || ((int) P2.x == (int) P3.x && (int) P2.y == (int) P3.y);
+
+ if (!not_triangle) {
+ y_max = vertices[2].y;
+ y_min = P1.y;
+
+ double a1, a2, a3;
+ a1 = ((double) ((int) P2.y - (int) P1.y) / (double) ((int) P2.x - (int) P1.x));
+ // calcula a2:
+ a2 = ((double) ((int) P3.y - (int) P1.y) / (double) ((int) P3.x - (int) P1.x));
+ // calcula a3:
+ a3 = ((double) ((int) P3.y - (int) P2.y) / (double) ((int) P3.x - (int) P2.x));
+ // valores de x_min e x_max inicio
+ x_min = x_max = P1.x;
+
+ if (Math.abs(P1.y - P2.y) == 0) { // P1 e P2 estao na mesma
+ // linha horizontal:
+ reta_change = true;
+ x_min = Math.min(P1.x, P2.x);
+ x_max = Math.max(P1.x, P2.x);
+ a1 = a3;
+ } else if (Math.abs(P1.y - P3.y) == 0) { // P1 e P3 estao na mesma linha
+ reta_change = true;
+ x_min = Math.min(P1.x, P3.x);
+ x_max = Math.max(P1.x, P3.x);
+ a2 = a3;
+ }
+
+ for (int y = (int) y_min; y <= (int) y_max; y++) {
+ // verifica se o ponto do meio foi alcançado
+ scanline(c, P1, P2, P3, y, x_min, x_max);
+ if (!reta_change && (y == (int) P2.y || y == (int) P3.y)) {
+ if (Math.abs(y - P2.y) == 0) {
+ a1 = a3;
+ } else {
+ a2 = a3;
+ }
+ reta_change = true;
+ }
+ if (a1 != Double.POSITIVE_INFINITY
+ && a1 != Double.NEGATIVE_INFINITY && a1 != 0
+ && a1 != Double.NaN) {
+ x_min += 1 / a1;
+ }
+
+ if (a2 != Double.POSITIVE_INFINITY
+ && a2 != Double.NEGATIVE_INFINITY && a2 != 0
+ && a2 != Double.NaN) {
+ x_max += 1 / a2;
+ }
+ }
+ }
+ }
+ }
+
+ private double[] pincel(Ponto ponto, Ponto normal) {
+
+ double[] id = new double[3];
+ double[] is = new double[3];
+ double[] retorno = new double[3];
+ Ponto vetorL = new Ponto(0, 0, 0);
+ double[] ia2 = new double[3];
+
+ Ponto opostoP = new Ponto((-1) * ponto.x, (-1) * ponto.y, (-1) * ponto.z);
+ Operador.normalizar(opostoP);
+
+ // IA
+ ia2[0] = lux.ka * lux.Ia.x;
+ ia2[1] = lux.ka * lux.Ia.y;
+ ia2[2] = lux.ka * lux.Ia.z;
+
+ // vetorL = Ponto de luz - ponto (PL - P)
+ vetorL.x = lux.Pl.x - ponto.x;
+ vetorL.y = lux.Pl.y - ponto.y;
+ vetorL.z = lux.Pl.z - ponto.z;
+
+ // normaliza vetorL
+ Operador.normalizar(vetorL);
+
+ // Calcular Id
+ if (Operador.produto_interno(vetorL, normal) > 0) {
+
+ if(box != null){ //com textura, usa Od do ponto do objeto
+ id[0] = Operador.produto_fosco(lux.Ip, ponto.Od)[0]
+ * (lux.kd * Operador.produto_interno(vetorL, normal));
+ id[1] = Operador.produto_fosco(lux.Ip, ponto.Od)[1]
+ * (lux.kd * Operador.produto_interno(vetorL, normal));
+ id[2] = Operador.produto_fosco(lux.Ip, ponto.Od)[2]
+ * (lux.kd * Operador.produto_interno(vetorL, normal));
+
+ }
+ else{ //sem textura, usa Od dos atributos da camera
+ id[0] = Operador.produto_fosco(lux.Ip, lux.Od)[0]
+ * (lux.kd * Operador.produto_interno(vetorL, normal));
+ id[1] = Operador.produto_fosco(lux.Ip, lux.Od)[1]
+ * (lux.kd * Operador.produto_interno(vetorL, normal));
+ id[2] = Operador.produto_fosco(lux.Ip, lux.Od)[2]
+ * (lux.kd * Operador.produto_interno(vetorL, normal));
+ }
+ }
+
+ double coef = (Operador.produto_interno(vetorL, normal) / Operador
+ .produto_interno(normal, normal));
+
+ Ponto vetorR = new Ponto(0, 0, 0);
+ vetorR.x = (coef * normal.x) * 2;
+ vetorR.y = (coef * normal.y) * 2;
+ vetorR.z = (coef * normal.z) * 2;
+
+ vetorR.x -= vetorL.x;
+ vetorR.y -= vetorL.y;
+ vetorR.z -= vetorL.z;
+
+ Operador.normalizar(vetorR);
+
+ double rugosidade = Operador.produto_interno(vetorR, opostoP); //coeficiente de rugosidade
+
+ rugosidade = Math.max(rugosidade, 0);
+
+ rugosidade = Math.pow(rugosidade, lux.n);
+ rugosidade *= lux.ks;
+
+ //calculo do indice de specularidade
+ is[0] = lux.Ip[0] * rugosidade;
+ is[1] = lux.Ip[1] * rugosidade;
+ is[2] = lux.Ip[2] * rugosidade;
+
+ retorno[0] = Math.min(is[0] + id[0] + ia2[0], 255);
+ retorno[1] = Math.min(is[1] + id[1] + ia2[1], 255);
+ retorno[2] = Math.min(is[2] + id[2] + ia2[2], 255);
+
+ return retorno;
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+
+ super.paintComponent(g);
+ doDrawing(g);
+ }
+}
diff --git a/example-apps/src/Projeto-GDI/projetogdi/controler/CadastroCliente.java b/example-apps/src/Projeto-GDI/projetogdi/controler/CadastroCliente.java
new file mode 100644
index 0000000..4067dcf
--- /dev/null
+++ b/example-apps/src/Projeto-GDI/projetogdi/controler/CadastroCliente.java
@@ -0,0 +1,71 @@
+package projetogdi.controler;
+
+import projetogdi.models.Cliente;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class CadastroCliente {
+
+ static String username = "system";
+ static String password = "senha aqui";
+
+ // pra testar conexao:
+
+ /*public static void main(String[] args){
+ try {
+ Connection con = connectToDatabase(username,password);
+ Statement stmt = con.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT nome FROM tb_cliente");
+
+ while (rs.next()) {
+ // int x = rs.getInt("a");
+ String s = rs.getString("nome");
+ System.out.println(s);
+ // float f = rs.getFloat("c");
+ }
+ stmt.close();
+ con.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }*/
+
+ public static Connection connectToDatabase(String username, String password) throws ClassNotFoundException {
+
+ Connection con = null;
+ try {
+ Class.forName("oracle.jdbc.driver.OracleDriver");
+ con = DriverManager.getConnection(
+ "jdbc:oracle:thin:hr/hr@localhost:1521/XE",
+ username,
+ password);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return con;
+ }
+
+ public void cadastrar(Cliente c) throws SQLException, ClassNotFoundException{
+ Connection con = connectToDatabase(username, password);
+ Statement stmt = con.createStatement();
+ // INSERT INTO tb_cliente VALUES ('cpf','nome',v_telefone(tp_telefone('telefone1'),tp_telefone('telefone2'),tp_telefone('telefone3')),1);
+ String[] telefones = c.getTelefones();
+ String tel = telefones[0];
+ String insercao = "INSERT INTO tb_cliente VALUES('"+c.getCpf()+"','"+c.getNome()+"',v_telefone(tp_telefone('"+tel+"')";
+ // outros 2 telefones, se houver
+ for(int i=1;i<3 && tel != null;i++){
+ tel = telefones[i];
+ if(tel == null) break;
+ insercao += ",tp_telefone('"+tel+"')";
+ }
+ insercao += "),"+c.getIdProduto()+")";
+ System.out.println(insercao);
+ stmt.executeQuery(insercao);
+ stmt.close();
+ con.close();
+ }
+
+}
diff --git a/example-apps/src/Projeto-GDI/projetogdi/models/Cliente.java b/example-apps/src/Projeto-GDI/projetogdi/models/Cliente.java
new file mode 100644
index 0000000..bde0b4c
--- /dev/null
+++ b/example-apps/src/Projeto-GDI/projetogdi/models/Cliente.java
@@ -0,0 +1,32 @@
+package projetogdi.models;
+
+public class Cliente {
+
+ private String nome, cpf;
+ private String[] telefones;
+ private int idProduto;
+
+ public Cliente(String cpf, String nome, String[] telefones, int idProduto){
+ this.nome = nome;
+ this.cpf = cpf;
+ this.telefones = telefones;
+ this.idProduto = idProduto;
+ }
+
+ public String getNome(){
+ return this.nome;
+ }
+
+ public String getCpf(){
+ return this.cpf;
+ }
+
+ public String[] getTelefones(){
+ return this.telefones;
+ }
+
+ public int getIdProduto(){
+ return this.idProduto;
+ }
+
+}
diff --git a/example-apps/src/Projeto-GDI/projetogdi/views/TelaCadastro.java b/example-apps/src/Projeto-GDI/projetogdi/views/TelaCadastro.java
new file mode 100644
index 0000000..095a358
--- /dev/null
+++ b/example-apps/src/Projeto-GDI/projetogdi/views/TelaCadastro.java
@@ -0,0 +1,145 @@
+package projetogdi.views;
+
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import projetogdi.models.Cliente;
+import projetogdi.controler.CadastroCliente;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+
+import java.awt.Font;
+import java.sql.SQLException;
+
+import javax.swing.JFormattedTextField;
+import javax.swing.JSpinner;
+
+public class TelaCadastro {
+
+ private JFrame frmProjetoGdi;
+ private JTextField clientName;
+ private JTextField clientCPF;
+ private static CadastroCliente cad;
+
+ /**
+ * Create the application.
+ */
+ public TelaCadastro() {
+ initialize();
+ }
+
+ // Controlador só precisa ser inicializado uma vez
+ static {
+ cad = new CadastroCliente();
+ }
+
+ public void setVisible(boolean v){
+ this.frmProjetoGdi.setVisible(v);
+ }
+
+ /**
+ * Initialize the contents of the frame.
+ */
+ private void initialize() {
+ frmProjetoGdi = new JFrame();
+ frmProjetoGdi.setTitle("Projeto GDI Nunca Mais!");
+ frmProjetoGdi.setBounds(100, 100, 600, 352);
+ frmProjetoGdi.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ frmProjetoGdi.getContentPane().setLayout(null);
+ frmProjetoGdi.setVisible(true);
+
+ clientName = new JTextField();
+ clientName.setBounds(10, 53, 178, 20);
+ frmProjetoGdi.getContentPane().add(clientName);
+ clientName.setColumns(15);
+
+ JLabel lblBuscarCliente = new JLabel("Cadastrar Cliente");
+ lblBuscarCliente.setFont(new Font("Tahoma", Font.PLAIN, 18));
+ lblBuscarCliente.setBounds(10, 11, 227, 14);
+ frmProjetoGdi.getContentPane().add(lblBuscarCliente);
+
+
+ JLabel lblNome = new JLabel("Nome");
+ lblNome.setBounds(10, 36, 46, 14);
+ frmProjetoGdi.getContentPane().add(lblNome);
+
+ clientCPF = new JTextField();
+ clientCPF.setColumns(15);
+ clientCPF.setBounds(10, 101, 178, 20);
+ frmProjetoGdi.getContentPane().add(clientCPF);
+
+ JLabel lblCpf = new JLabel("CPF");
+ lblCpf.setBounds(10, 84, 46, 14);
+ frmProjetoGdi.getContentPane().add(lblCpf);
+
+ JLabel lblTelefone = new JLabel("Telefone 1");
+ lblTelefone.setBounds(10, 132, 178, 14);
+ frmProjetoGdi.getContentPane().add(lblTelefone);
+
+ final JFormattedTextField clientTel1 = new JFormattedTextField();
+ clientTel1.setBounds(10, 157, 178, 20);
+ frmProjetoGdi.getContentPane().add(clientTel1);
+
+ final JFormattedTextField clientTel2 = new JFormattedTextField();
+ clientTel2.setBounds(204, 157, 178, 20);
+ frmProjetoGdi.getContentPane().add(clientTel2);
+
+ JLabel lblTelefone_2 = new JLabel("Telefone 2");
+ lblTelefone_2.setBounds(204, 132, 178, 14);
+ frmProjetoGdi.getContentPane().add(lblTelefone_2);
+
+ final JFormattedTextField clientTel3 = new JFormattedTextField();
+ clientTel3.setBounds(396, 157, 178, 20);
+ frmProjetoGdi.getContentPane().add(clientTel3);
+
+ JLabel lblTelefone_3 = new JLabel("Telefone 3");
+ lblTelefone_3.setBounds(396, 132, 178, 14);
+ frmProjetoGdi.getContentPane().add(lblTelefone_3);
+
+ final JSpinner productID = new JSpinner();
+ productID.setBounds(10, 213, 178, 20);
+ frmProjetoGdi.getContentPane().add(productID);
+
+ JLabel lblTelefone_1 = new JLabel("ID do produto");
+ lblTelefone_1.setBounds(10, 188, 178, 14);
+ frmProjetoGdi.getContentPane().add(lblTelefone_1);
+
+ JButton btnCadastarCliente = new JButton("Cadastar Cliente");
+ btnCadastarCliente.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ String[] telefones = new String[3];
+ telefones[0] = clientTel1.getText();
+ if (clientTel2.getText() != ""){
+ telefones[1] = clientTel2.getText();
+ }
+ if (clientTel3.getText() != ""){
+ telefones[2] = clientTel3.getText();
+ }
+
+ Object o = productID.getValue();
+ Number n = (Number) o;
+ int idProduto = n.intValue();
+
+ Cliente novoCliente = new Cliente(clientCPF.getText(),clientName.getText(),telefones,idProduto);
+
+ try {
+ cad.cadastrar(novoCliente);
+ } catch (SQLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (ClassNotFoundException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ }
+ });
+ btnCadastarCliente.setBounds(10, 268, 178, 23);
+ frmProjetoGdi.getContentPane().add(btnCadastarCliente);
+
+ }
+}
diff --git a/example-apps/src/Projeto-GDI/projetogdi/views/TelaConsultas.java b/example-apps/src/Projeto-GDI/projetogdi/views/TelaConsultas.java
new file mode 100644
index 0000000..869a554
--- /dev/null
+++ b/example-apps/src/Projeto-GDI/projetogdi/views/TelaConsultas.java
@@ -0,0 +1,63 @@
+package projetogdi.views;
+
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+public class TelaConsultas {
+
+ private JFrame frmProjetoGdi;
+ private JTextField clientName;
+ private JTextField clientCPF;
+
+ /**
+ * Create the application.
+ */
+ public TelaConsultas() {
+ initialize();
+ }
+
+ /**
+ * Initialize the contents of the frame.
+ */
+ private void initialize() {
+ frmProjetoGdi = new JFrame();
+ frmProjetoGdi.setTitle("Projeto GDI Nunca Mais!");
+ frmProjetoGdi.setBounds(100, 100, 600, 400);
+ frmProjetoGdi.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ frmProjetoGdi.getContentPane().setLayout(null);
+ frmProjetoGdi.setVisible(true);
+
+ clientName = new JTextField();
+ clientName.setBounds(10, 32, 178, 20);
+ clientName.setText("Por nome...");
+ frmProjetoGdi.getContentPane().add(clientName);
+ clientName.setColumns(15);
+
+ JButton bucar = new JButton("Buscar");
+ bucar.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ }
+ });
+ bucar.setBounds(198, 31, 89, 23);
+ frmProjetoGdi.getContentPane().add(bucar);
+
+ JLabel lblBuscarCliente = new JLabel("Buscar Cliente");
+ lblBuscarCliente.setBounds(10, 11, 125, 14);
+ frmProjetoGdi.getContentPane().add(lblBuscarCliente);
+
+ clientCPF = new JTextField();
+ clientCPF.setText("Por CPF...");
+ clientCPF.setColumns(15);
+ clientCPF.setBounds(10, 64, 178, 20);
+ frmProjetoGdi.getContentPane().add(clientCPF);
+
+ JButton button = new JButton("Buscar");
+ button.setBounds(198, 63, 89, 23);
+ frmProjetoGdi.getContentPane().add(button);
+
+ }
+}
diff --git a/example-apps/src/Projeto-GDI/projetogdi/views/TelaPrincipal.java b/example-apps/src/Projeto-GDI/projetogdi/views/TelaPrincipal.java
new file mode 100644
index 0000000..0ec7bf5
--- /dev/null
+++ b/example-apps/src/Projeto-GDI/projetogdi/views/TelaPrincipal.java
@@ -0,0 +1,68 @@
+package projetogdi.views;
+
+import java.awt.EventQueue;
+import projetogdi.views.TelaCadastro;
+import projetogdi.views.TelaConsultas;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+import javax.swing.JButton;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+public class TelaPrincipal extends JFrame {
+
+ private static final long serialVersionUID = 1L;
+ private JPanel contentPane;
+
+ /**
+ * Launch the application.
+ */
+ public static void main(String[] args) {
+ EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ try {
+ TelaPrincipal frame = new TelaPrincipal();
+ frame.setVisible(true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ static class AcaoBtnCadastrar implements ActionListener{
+
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ new TelaCadastro();
+ }
+
+ }
+
+ /**
+ * Create the frame.
+ */
+ public TelaPrincipal() {
+
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setBounds(100, 100, 800, 600);
+ contentPane = new JPanel();
+ contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+ setContentPane(contentPane);
+ contentPane.setLayout(null);
+ JButton btnBuscarCliente = new JButton("Buscar Cliente");
+ btnBuscarCliente.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ new TelaConsultas();
+ }
+ });
+ btnBuscarCliente.setBounds(265, 68, 236, 80);
+ contentPane.add(btnBuscarCliente);
+
+ JButton btnCadastrarCliente= new JButton("Cadastrar Cliente");
+ btnCadastrarCliente.addActionListener(new AcaoBtnCadastrar());
+ btnCadastrarCliente.setBounds(265, 218, 236, 80);
+ contentPane.add(btnCadastrarCliente);
+ }
+}
diff --git a/example-apps/src/restaurante/Cliente.java b/example-apps/src/restaurante/Cliente.java
new file mode 100644
index 0000000..2fe1743
--- /dev/null
+++ b/example-apps/src/restaurante/Cliente.java
@@ -0,0 +1,59 @@
+package restaurante;
+
+public class Cliente {
+
+ private String cpf;
+ private String telefone;
+ private String endereco;
+ private String nome;
+ private String observacoes;
+
+ public Cliente(String cpf, String telefone, String nome, String endereco, String observacoes){
+ this.cpf = cpf;
+ this.endereco = endereco;
+ this.nome = nome;
+ this.observacoes = observacoes;
+ this.telefone = telefone;
+ }
+
+ public String getTelefone() {
+ return telefone;
+ }
+
+ public String getCpf() {
+ return cpf;
+ }
+
+ public void setCpf(String cpf) {
+ this.cpf = cpf;
+ }
+
+ public String getEndereco() {
+ return endereco;
+ }
+
+ public void setEndereco(String endereco) {
+ this.endereco = endereco;
+ }
+
+ public String getNome() {
+ return nome;
+ }
+
+ public void setNome(String nome) {
+ this.nome = nome;
+ }
+
+ public String getObservacoes() {
+ return observacoes;
+ }
+
+ public void setObservacoes(String observacoes) {
+ this.observacoes = observacoes;
+ }
+
+ public void setTelefone(String telefone) {
+ this.telefone = telefone;
+ }
+
+}
diff --git a/example-apps/src/restaurante/ClienteJaCadastradoException.java b/example-apps/src/restaurante/ClienteJaCadastradoException.java
new file mode 100644
index 0000000..299242a
--- /dev/null
+++ b/example-apps/src/restaurante/ClienteJaCadastradoException.java
@@ -0,0 +1,13 @@
+package restaurante;
+
+public class ClienteJaCadastradoException extends Exception{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6490933969455438764L;
+
+ public ClienteJaCadastradoException(){
+ super("O cliente ja esta cadastrado.");
+ }
+}
diff --git a/example-apps/src/restaurante/ClienteNaoCadastradoException.java b/example-apps/src/restaurante/ClienteNaoCadastradoException.java
new file mode 100644
index 0000000..5bee475
--- /dev/null
+++ b/example-apps/src/restaurante/ClienteNaoCadastradoException.java
@@ -0,0 +1,13 @@
+package restaurante;
+
+public class ClienteNaoCadastradoException extends Exception{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4855606300053472516L;
+
+ public ClienteNaoCadastradoException(){
+ super("Cliente nao cadastrado.");
+ }
+}
diff --git a/example-apps/src/restaurante/IRepositorio.java b/example-apps/src/restaurante/IRepositorio.java
new file mode 100644
index 0000000..f0ce69a
--- /dev/null
+++ b/example-apps/src/restaurante/IRepositorio.java
@@ -0,0 +1,13 @@
+package restaurante;
+
+import java.util.Iterator;
+
+public interface IRepositorio {
+ void inserir(T valor) throws ClienteJaCadastradoException,
+ ProdutoJaCadastradoException;
+
+ void remover(T valor) throws ClienteNaoCadastradoException,
+ PedidoNaoExistenteException, ProdutoNaoCadastradoException;
+
+ Iterator procurar(T valor);
+}
diff --git a/example-apps/src/restaurante/Pedido.java b/example-apps/src/restaurante/Pedido.java
new file mode 100644
index 0000000..02ed068
--- /dev/null
+++ b/example-apps/src/restaurante/Pedido.java
@@ -0,0 +1,71 @@
+package restaurante;
+
+import java.math.BigDecimal;
+
+public class Pedido {
+ private String codigo;
+ private Cliente cliente;
+ private Produto[] produtos;
+ private String data;
+ private int quantidade;
+ private BigDecimal valor;
+
+ public Pedido(String codigo, Cliente cliente, Produto[] produtos,
+ String data, int quantidade, BigDecimal valor) {
+ this.cliente = cliente;
+ this.codigo = codigo;
+ this.data = data;
+ this.produtos = produtos;
+ this.quantidade = quantidade;
+ this.valor = valor;
+ }
+
+ public Cliente getCliente() {
+ return cliente;
+ }
+
+ public void setCliente(Cliente cliente) {
+ this.cliente = cliente;
+ }
+
+ public Produto[] getProdutos() {
+ return produtos;
+ }
+
+ public void setProdutos(Produto[] produtos) {
+ this.produtos = produtos;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public int getQuantidade() {
+ return quantidade;
+ }
+
+ public void setQuantidade(int quantidade) {
+ this.quantidade = quantidade;
+ }
+
+ public BigDecimal getValor() {
+ return valor;
+ }
+
+ public void setValor(BigDecimal valor) {
+ this.valor = valor;
+ }
+
+ public void setCodigo(String codigo) {
+ this.codigo = codigo;
+ }
+
+ public String getCodigo() {
+ return codigo;
+ }
+
+}
diff --git a/example-apps/src/restaurante/PedidoNaoExistenteException.java b/example-apps/src/restaurante/PedidoNaoExistenteException.java
new file mode 100644
index 0000000..8663c34
--- /dev/null
+++ b/example-apps/src/restaurante/PedidoNaoExistenteException.java
@@ -0,0 +1,13 @@
+package restaurante;
+
+public class PedidoNaoExistenteException extends Exception{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 9143022182046227046L;
+
+ public PedidoNaoExistenteException(){
+ super("Pedido nao existente.");
+ }
+}
diff --git a/example-apps/src/restaurante/Produto.java b/example-apps/src/restaurante/Produto.java
new file mode 100644
index 0000000..aecd6a5
--- /dev/null
+++ b/example-apps/src/restaurante/Produto.java
@@ -0,0 +1,60 @@
+package restaurante;
+
+import java.math.BigDecimal;
+
+public class Produto {
+ private String codigo;
+ private String nome;
+ private String descricao;
+ private char tamanho;
+ private BigDecimal valor;
+
+ public Produto(String codigo, String nome, String descricao, char tamanho, BigDecimal valor){
+ this.codigo = codigo;
+ this.nome = nome;
+ this.descricao = descricao;
+ this.tamanho = tamanho;
+ this.valor = valor;
+ }
+
+ public String getCodigo() {
+ return codigo;
+ }
+
+ public String getNome() {
+ return nome;
+ }
+
+ public void setNome(String nome) {
+ this.nome = nome;
+ }
+
+ public String getDescricao() {
+ return descricao;
+ }
+
+ public void setDescricao(String descricao) {
+ this.descricao = descricao;
+ }
+
+ public char getTamanho() {
+ return tamanho;
+ }
+
+ public void setTamanho(char tamanho) {
+ this.tamanho = tamanho;
+ }
+
+ public BigDecimal getValor() {
+ return valor;
+ }
+
+ public void setValor(BigDecimal valor) {
+ this.valor = valor;
+ }
+
+ public void setCodigo(String codigo) {
+ this.codigo = codigo;
+ }
+
+}
diff --git a/example-apps/src/restaurante/ProdutoJaCadastradoException.java b/example-apps/src/restaurante/ProdutoJaCadastradoException.java
new file mode 100644
index 0000000..72a37bd
--- /dev/null
+++ b/example-apps/src/restaurante/ProdutoJaCadastradoException.java
@@ -0,0 +1,13 @@
+package restaurante;
+
+public class ProdutoJaCadastradoException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3967223092703092831L;
+
+ public ProdutoJaCadastradoException() {
+ super("Produto ja cadastrado.");
+ }
+}
diff --git a/example-apps/src/restaurante/ProdutoNaoCadastradoException.java b/example-apps/src/restaurante/ProdutoNaoCadastradoException.java
new file mode 100644
index 0000000..24e8d14
--- /dev/null
+++ b/example-apps/src/restaurante/ProdutoNaoCadastradoException.java
@@ -0,0 +1,13 @@
+package restaurante;
+
+public class ProdutoNaoCadastradoException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7251989337883106223L;
+
+ public ProdutoNaoCadastradoException() {
+ super("Produto nao cadastrado.");
+ }
+}
diff --git a/example-apps/src/restaurante/RepositorioClientesArray.java b/example-apps/src/restaurante/RepositorioClientesArray.java
new file mode 100644
index 0000000..c0da82b
--- /dev/null
+++ b/example-apps/src/restaurante/RepositorioClientesArray.java
@@ -0,0 +1,61 @@
+package restaurante;
+
+import java.util.Iterator;
+
+public class RepositorioClientesArray implements IRepositorio {
+ private Cliente[] clientes;
+ private int indice;
+
+ public RepositorioClientesArray(int tamanhoArray) {
+ this.clientes = new Cliente[tamanhoArray];
+ this.indice = 0;
+ }
+
+ public void inserir(Cliente cliente)
+ throws ClienteJaCadastradoException {
+ if (this.procurar(cliente.getTelefone()) == null) {
+ clientes[indice] = cliente;
+ indice++;
+ } else {
+ throw new ClienteJaCadastradoException();
+ }
+ }
+
+ public void remover(Cliente cliente) throws ClienteNaoCadastradoException {
+ if (this.procurar(cliente.getTelefone()) == null) {
+ throw new ClienteNaoCadastradoException();
+ } else {
+ clientes[this.getPosicao(cliente)] = clientes[indice - 1];
+ clientes[indice - 1] = null;
+ indice--;
+
+ }
+ }
+
+ private Cliente procurar(String telefone) {
+ Cliente retorno = null;
+ boolean achou = false;
+ for (int i = 0; i < indice && !achou; i++) {
+ if (clientes[i].getTelefone().equals(telefone)) {
+ retorno = clientes[i];
+ }
+ }
+ return retorno;
+ }
+
+ private int getPosicao(Cliente cliente) {
+ int resposta = 0;
+ for (int i = 0; i < indice; i++) {
+ if (clientes[i].getTelefone() == cliente.getTelefone()) {
+ resposta = i;
+ }
+ }
+ return resposta;
+ }
+
+ @Override
+ public Iterator procurar(Cliente valor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/example-apps/src/restaurante/RepositorioPedidosArray.java b/example-apps/src/restaurante/RepositorioPedidosArray.java
new file mode 100644
index 0000000..f1e2fdb
--- /dev/null
+++ b/example-apps/src/restaurante/RepositorioPedidosArray.java
@@ -0,0 +1,59 @@
+package restaurante;
+
+import java.util.Iterator;
+
+
+public class RepositorioPedidosArray {
+ private Pedido[] pedidos;
+ private int indice;
+ // implements IRepositorio
+
+ public RepositorioPedidosArray(int tamanhoArray) {
+ this.pedidos = new Pedido[tamanhoArray];
+ this.indice = 0;
+ }
+
+ public void inserir(Pedido pedido) {
+ this.pedidos[indice] = pedido;
+ this.indice++;
+ }
+
+ public void remover(Pedido pedido)
+ throws PedidoNaoExistenteException {
+ if (this.procurar(pedido.getCodigo()) == null) {
+ throw new PedidoNaoExistenteException();
+ } else {
+ pedidos[this.getPosicao(pedido)] = pedidos[indice - 1];
+ pedidos[indice - 1] = null;
+ indice--;
+
+ }
+ }
+
+ private Pedido procurar(String codigo) {
+ Pedido retorno = null;
+ boolean achou = false;
+ for (int i = 0; i < indice && !achou; i++) {
+ if (pedidos[i].getCodigo().equals(codigo)) {
+ retorno = pedidos[i];
+ }
+ }
+ return retorno;
+ }
+
+ private int getPosicao(Pedido pedido) {
+ int posicao = 0;
+ for (int i = 0; i < indice; i++) {
+ if (pedidos[i].getCodigo() == pedido.getCodigo()) {
+ posicao = i;
+ }
+ }
+ return posicao;
+ }
+
+ // @Override
+ public Iterator procurar(Pedido valor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/example-apps/src/restaurante/RepositorioProdutosArray.java b/example-apps/src/restaurante/RepositorioProdutosArray.java
new file mode 100644
index 0000000..b392b5b
--- /dev/null
+++ b/example-apps/src/restaurante/RepositorioProdutosArray.java
@@ -0,0 +1,63 @@
+package restaurante;
+
+import java.util.Iterator;
+
+public class RepositorioProdutosArray implements IRepositorio{
+
+ private Produto[] produtos;
+ private int indice;
+
+ public RepositorioProdutosArray(int tamanhoArray) {
+ this.produtos = new Produto[tamanhoArray];
+ this.indice = 0;
+ }
+
+ public void inserir(Produto produto)
+ throws ProdutoJaCadastradoException {
+ if (this.procurar(produto.getCodigo()) == null) {
+ produtos[indice] = produto;
+ indice++;
+ } else {
+ throw new ProdutoJaCadastradoException();
+ }
+ }
+
+ public void remover(Produto produto)
+ throws ProdutoNaoCadastradoException {
+ if (this.procurar(produto.getCodigo()) == null) {
+ throw new ProdutoNaoCadastradoException();
+ } else {
+ produtos[this.getPosicao(produto)] = produtos[indice - 1];
+ produtos[indice - 1] = null;
+ indice--;
+
+ }
+ }
+
+ private Produto procurar(String codigo) {
+ Produto retorno = null;
+ boolean achou = false;
+ for (int i = 0; i < indice && !achou; i++) {
+ if (produtos[i].getCodigo().equals(codigo)) {
+ retorno = produtos[i];
+ }
+ }
+ return retorno;
+ }
+
+ private int getPosicao(Produto produto) {
+ int resposta = 0;
+ for (int i = 0; i < indice; i++) {
+ if (produtos[i].getCodigo() == produto.getCodigo()) {
+ resposta = i;
+ }
+ }
+ return resposta;
+ }
+
+ @Override
+ public Iterator procurar(Produto valor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/rwset_bugs b/rwset_bugs
new file mode 100644
index 0000000..5c10125
--- /dev/null
+++ b/rwset_bugs
@@ -0,0 +1,38 @@
+Bugs
+
+File: src/depend/Main.java
+Class: Main
+Method: static SimpleGraph analyze(String, String, String, String)
+Line: 173
+Description: rwset is unable to find classes located in subpackages in the format 'pkg1.subpkg1.Class'.
+Detected by: tests 1,2,3,4,5 from TestProjetoIPEmpacotado.java and tests 2,3 from TestProjetoGDI.java
+
+File: src/depend/util/parser/Util.java
+Class: Util
+Method: static void printTypeArgs(List, Object, StringBuffer)
+Line: 291
+Description: rwset doesn't provide support for 'implements' clause.
+
+File: src/depend/util/parser/Util.java
+Class: Util
+Method: static String[] getLineAndWALAClassName(String, String)
+Line: 79
+Description: rwset doesn't provide support for multiple classes declared in a single compilation unit.
+Detected by: test 1 from projetogdi
+
+File: src/depend/Main.java
+Class: Main
+Method: static SimpleGraph analyze(String, String, String, String)
+Line: 173
+Description: rwsets doesn't provide support for 'extends' clause but it's unclear if this is the unique cause of the error.
+Detected by: test 1, 2 from projetopg
+
+File: src/depend/MethodDependencyAnalysis.java
+Class: MethodDependencyAnalysis
+Method: void updateRWSet(IMethod)
+Line: 318
+Description: Throws NullPointerException. Cause is unknown.
+Detected by: test 3 from projetopg
+
+In addition, rwsets is unable to use the empty string "" to filter packages (i.e. take all packages of the application as possible dependencies). This limitation isn't detected by any test.
+
diff --git a/src-tests/rwsets/AllTests.java b/src-tests/rwsets/AllTests.java
index 6e97b0f..d4383aa 100644
--- a/src-tests/rwsets/AllTests.java
+++ b/src-tests/rwsets/AllTests.java
@@ -8,12 +8,19 @@
// Add test classes here
rwsets.coffeemaker.TestCoffeeMaker.class,
rwsets.core.Sanity.class,
+<<<<<<< HEAD
+ rwsets.projetoip.TestProjetoIP.class,
+ rwsets.projetoipempacotado.TestProjetoIPEmpacotado.class,
+ rwsets.projetopg.Test_PG_Projeto_2_Jar.class,
+ rwsets.projetogdi.TestProjetoGDI.class
+=======
rwsets.soot.SootTests.class
/* if688-2014.2-group-2 */
rwsets.escola.GeeoIpTest.class,
rwsets.hardware.HardwareTest.class,
rwsets.logica.LogicaTest.class,
rwsets.manuip.ManuIpTest.class
+>>>>>>> professor/master
})
public class AllTests { }
\ No newline at end of file
diff --git a/src-tests/rwsets/Helper.java b/src-tests/rwsets/Helper.java
index 6a0e9b6..016d508 100644
--- a/src-tests/rwsets/Helper.java
+++ b/src-tests/rwsets/Helper.java
@@ -8,22 +8,73 @@
public class Helper {
+ /**
+ * Directory constants.
+ */
+ public static final String USER_DIR = System.getProperty("user.dir");
+ public static final String RESOURCES_DIR = USER_DIR + "/dat";
+ public static final String TEST_DIR = USER_DIR + "/src-tests";
+ public static final String EXCLUSION_FILE = RESOURCES_DIR + "/ExclusionAllJava.txt";
+ public static final String EXCLUSION_FILE_FOR_CALLGRAPH = RESOURCES_DIR + "/ExclusionForCallGraph.txt";
+ public static final String CLASS_NOT_FOUND = "A classe n�o foi encontrada";
+
+ /**
+ * Reads a plain-text file and returns a string with its content,
+ * converting any sequence of '\n' characters into a single '\n' charater.
+ * @param fileName The path to the input file.
+ * @return The String that corresponds to the content of the file.
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
public static String readFile(String fileName) throws FileNotFoundException, IOException {
StringBuffer sb = new StringBuffer();
+
FileReader fr = new FileReader(new File(fileName));
+
BufferedReader br = new BufferedReader(fr);
+
String tmp;
- while ((tmp = br.readLine())!=null) {
+
+ while ((tmp = br.readLine()) != null) {
sb.append(tmp);
sb.append("\n");
}
+
br.close();
+
fr.close();
+
return sb.toString();
}
+<<<<<<< HEAD
+
+ /**
+ * Uses reflection to obtain the current test name
+ * Possibly not the best approach (?)
+ * @return The current test name.
+ */
+ private static String getCurrentTestName() {
+ StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+
+ String testName = stackTrace[3].getClassName().replace(".", "/") + "." + stackTrace[3].getMethodName();
+
+ return testName;
+ }
+
+ /**
+ * Obtains path of the results file
+ * @return The path of the results file.
+ */
+ public static String getExpectedResultsFilePath() {
+ return String.format("%s/%s.data", TEST_DIR, getCurrentTestName());
+ }
+
+}
+=======
}
+>>>>>>> professor/master
diff --git a/src-tests/rwsets/projetogdi/TestProjetoGDI.java b/src-tests/rwsets/projetogdi/TestProjetoGDI.java
new file mode 100644
index 0000000..8fb606b
--- /dev/null
+++ b/src-tests/rwsets/projetogdi/TestProjetoGDI.java
@@ -0,0 +1,123 @@
+package rwsets.projetogdi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static rwsets.Helper.CLASS_NOT_FOUND;
+import static rwsets.Helper.EXCLUSION_FILE;
+import static rwsets.Helper.EXCLUSION_FILE_FOR_CALLGRAPH;
+import static rwsets.Helper.USER_DIR;
+import static rwsets.Helper.getExpectedResultsFilePath;
+import static rwsets.Helper.readFile;
+
+import japa.parser.ParseException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.ibm.wala.shrikeCT.InvalidClassFileException;
+import com.ibm.wala.util.CancelException;
+import com.ibm.wala.util.WalaException;
+
+import depend.util.graph.SimpleGraph;
+
+public class TestProjetoGDI {
+ private static final String APPS_DIR = USER_DIR + "/example-apps";
+ private static final String APPS_JAR_DIR = APPS_DIR;
+ private static final String APPS_SRC_DIR = APPS_DIR + "/src";
+ private static final String JAR_FILE = APPS_JAR_DIR
+ + "/projetoGDI.jar";
+ private static final String PACKAGE_FILTER = "projetogdi";
+
+ @Before
+ public void setup() {
+ assertTrue(new File(JAR_FILE).exists());
+ assertTrue(new File(EXCLUSION_FILE).exists());
+ assertTrue(new File(EXCLUSION_FILE_FOR_CALLGRAPH).exists());
+ }
+
+ private static SimpleGraph analyze(String classFilePath, String classFileLine)
+ throws IOException, WalaException, CancelException, ParseException,
+ InvalidClassFileException {
+ return depend.Main.analyze(JAR_FILE, PACKAGE_FILTER, classFilePath,
+ classFileLine);
+ }
+
+ /**
+ * Known issue: doesn't provide support for multiple classes in single compilation unit.
+ * @throws IOException
+ * @throws WalaException
+ * @throws CancelException
+ * @throws ParseException
+ * @throws InvalidClassFileException
+ */
+ @Test
+ public void test1() throws IOException, WalaException, CancelException,
+ ParseException, InvalidClassFileException {
+ String classFileLine = "TelaPrincipal frame = new TelaPrincipal();";
+ String classFilePath = APPS_SRC_DIR
+ + "/Projeto-GDI/projetogdi/views/TelaPrincipal.java";
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+ String expectedResultsFile = getExpectedResultsFilePath();
+ PrintWriter fileWriter = new PrintWriter(
+ new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+ /**
+ * @throws IOException
+ * @throws WalaException
+ * @throws CancelException
+ * @throws ParseException
+ * @throws InvalidClassFileException
+ */
+ @Test
+ public void test2() throws IOException, WalaException, CancelException,
+ ParseException, InvalidClassFileException {
+ String classFileLine = "initialize();";
+ String classFilePath = APPS_SRC_DIR
+ + "/Projeto-GDI/projetogdi/views/TelaCadastro.java";
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+ String expectedResultsFile = getExpectedResultsFilePath();
+ PrintWriter fileWriter = new PrintWriter(
+ new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+ /**
+ * @throws IOException
+ * @throws WalaException
+ * @throws CancelException
+ * @throws ParseException
+ * @throws InvalidClassFileException
+ */
+ @Test
+ public void test3() throws IOException, WalaException, CancelException,
+ ParseException, InvalidClassFileException {
+ String classFileLine = "stmt.executeQuery(insercao);";
+ String classFilePath = APPS_SRC_DIR
+ + "/Projeto-GDI/projetogdi/controler/CadastroCliente.java";
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+ String expectedResultsFile = getExpectedResultsFilePath();
+ PrintWriter fileWriter = new PrintWriter(
+ new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+}
diff --git a/src-tests/rwsets/projetogdi/TestProjetoGDI.test2.data b/src-tests/rwsets/projetogdi/TestProjetoGDI.test2.data
new file mode 100644
index 0000000..5e4ea02
--- /dev/null
+++ b/src-tests/rwsets/projetogdi/TestProjetoGDI.test2.data
@@ -0,0 +1,11 @@
+digraph "DirectedGraph" {
+ graph [concentrate = true];
+ center=true;
+ fontsize=6;
+ node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial];
+ edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial];
+"void projetogdi/views/TelaCadastro.()"[color="red", fontsize="6", fontname="Arial"];
+"void projetogdi/views/TelaCadastro.initialize()" -> "void projetogdi/views/TelaCadastro.initialize()" [label="javax/swing/JFrame projetogdi/views/TelaCadastro.frmProjetoGdi : 48" ]
+"void projetogdi/views/TelaCadastro.initialize()" -> "void projetogdi/views/TelaCadastro.initialize()" [label="javax/swing/JTextField projetogdi/views/TelaCadastro.clientCPF : 70" ]
+"void projetogdi/views/TelaCadastro.initialize()" -> "void projetogdi/views/TelaCadastro.initialize()" [label="javax/swing/JTextField projetogdi/views/TelaCadastro.clientName : 55" ]
+}
diff --git a/src-tests/rwsets/projetogdi/TestProjetoGDI.test3.data b/src-tests/rwsets/projetogdi/TestProjetoGDI.test3.data
new file mode 100644
index 0000000..67adc51
--- /dev/null
+++ b/src-tests/rwsets/projetogdi/TestProjetoGDI.test3.data
@@ -0,0 +1,14 @@
+digraph "DirectedGraph" {
+ graph [concentrate = true];
+ center=true;
+ fontsize=6;
+ node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial];
+ edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial];
+"void projetogdi/controler/CadastroCliente.cadastrar(projetogdi/models/Cliente)"[color="red", fontsize="6", fontname="Arial"];
+"void projetogdi/controler/CadastroCliente.()" -> "void projetogdi/controler/CadastroCliente.cadastrar(projetogdi/models/Cliente)" [label="java/lang/String projetogdi/controler/CadastroCliente.password : 13" ]
+"void projetogdi/controler/CadastroCliente.()" -> "void projetogdi/controler/CadastroCliente.cadastrar(projetogdi/models/Cliente)" [label="java/lang/String projetogdi/controler/CadastroCliente.username : 12" ]
+"void projetogdi/models/Cliente.(java/lang/String,java/lang/String,Ljava/lang/String,int)" -> "Ljava/lang/String projetogdi/models/Cliente.getTelefones()" [label="Ljava/lang/String projetogdi/models/Cliente.telefones : 12" ]
+"void projetogdi/models/Cliente.(java/lang/String,java/lang/String,Ljava/lang/String,int)" -> "int projetogdi/models/Cliente.getIdProduto()" [label="int projetogdi/models/Cliente.idProduto : 13" ]
+"void projetogdi/models/Cliente.(java/lang/String,java/lang/String,Ljava/lang/String,int)" -> "java/lang/String projetogdi/models/Cliente.getCpf()" [label="java/lang/String projetogdi/models/Cliente.cpf : 11" ]
+"void projetogdi/models/Cliente.(java/lang/String,java/lang/String,Ljava/lang/String,int)" -> "java/lang/String projetogdi/models/Cliente.getNome()" [label="java/lang/String projetogdi/models/Cliente.nome : 10" ]
+}
diff --git a/src-tests/rwsets/projetoip/TestProjetoIP.java b/src-tests/rwsets/projetoip/TestProjetoIP.java
new file mode 100644
index 0000000..0183df5
--- /dev/null
+++ b/src-tests/rwsets/projetoip/TestProjetoIP.java
@@ -0,0 +1,100 @@
+package rwsets.projetoip;
+
+import japa.parser.ParseException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import rwsets.Helper;
+
+import com.ibm.wala.shrikeCT.InvalidClassFileException;
+import com.ibm.wala.util.CancelException;
+import com.ibm.wala.util.WalaException;
+import depend.util.graph.SimpleGraph;
+
+public class TestProjetoIP {
+
+ private static final String USER_DIR = System.getProperty("user.dir");
+ private static final String APPS_DIR = USER_DIR+"/example-apps";
+ private static final String APPS_JAR_DIR = APPS_DIR;
+ private static final String APPS_SRC_DIR = APPS_DIR+"/src";
+ private static final String RESOURCES_DIR = USER_DIR+"/dat";
+ private static final String TEST_DIR = USER_DIR+"/src-tests";
+ private static final String JAR_FILE = APPS_JAR_DIR+"/projetoip.jar";
+ private static final String EXCLUSION_FILE = RESOURCES_DIR+"/ExclusionAllJava.txt";
+ private static final String EXCLUSION_FILE_FOR_CALLGRAPH = RESOURCES_DIR+"/ExclusionForCallGraph.txt";
+
+ @Before
+ public void setup(){
+ Assert.assertTrue(new File(JAR_FILE).exists());
+ Assert.assertTrue(new File(EXCLUSION_FILE).exists());
+ Assert.assertTrue(new File(EXCLUSION_FILE_FOR_CALLGRAPH).exists());
+ }
+
+ /**
+ * @throws IOException
+ * @throws WalaException
+ * @throws CancelException
+ * @throws ParseException
+ * @throws InvalidClassFileException
+ */
+ @Test
+ public void testPedidoGetPosicao() throws IOException, WalaException, CancelException, ParseException, InvalidClassFileException{
+
+ String line = "if (pedidos[i].getCodigo() == pedido.getCodigo()) {";
+ String compUnitFile = APPS_SRC_DIR+"/restaurante/RepositorioPedidosArray.java";
+ String filter = "restaurante";
+
+ Assert.assertTrue((new File(compUnitFile)).exists());
+ Assert.assertTrue((new File(JAR_FILE)).exists());
+
+ SimpleGraph sgTest0 = depend.Main.analyze(JAR_FILE, filter, compUnitFile,line);
+ String expectedResultFile = TEST_DIR + "/rwsets/projetoip/TestProjetoIP.testPedidoGetPosicao.data";
+
+ if(new File(expectedResultFile).createNewFile()){
+ PrintWriter pw = new PrintWriter(new FileWriter(expectedResultFile));
+ pw.print(sgTest0.toDotString());
+ pw.close();
+ }
+
+ Assert.assertEquals(Helper.readFile(expectedResultFile),sgTest0.toDotString());
+
+ }
+
+ /**
+ * Known issue: doesn't provide support for 'implements' clause.
+ * @throws InvalidClassFileException
+ * @throws ParseException
+ * @throws CancelException
+ * @throws WalaException
+ * @throws IOException
+ */
+ @Test
+ public void testRemoverProduto() throws IOException, WalaException, CancelException, ParseException, InvalidClassFileException{
+
+ String line = "public void remover(Produto produto)";
+ String compUnitFile = APPS_SRC_DIR+"/restaurante/RepositorioProdutosArray.java";
+ String filter = "restaurante";
+
+ Assert.assertTrue((new File(compUnitFile)).exists());
+ Assert.assertTrue((new File(JAR_FILE)).exists());
+
+ SimpleGraph sgTest0 = depend.Main.analyze(JAR_FILE, filter, compUnitFile,line);
+ String expectedResultFile = TEST_DIR + "/rwsets/projetoip/TestProjetoIP.testRemoverProduto.data";
+
+ if(new File(expectedResultFile).createNewFile()){
+ PrintWriter pw = new PrintWriter(new FileWriter(expectedResultFile));
+ pw.print(sgTest0.toDotString());
+ pw.close();
+ }
+
+ Assert.assertEquals(Helper.readFile(expectedResultFile),sgTest0.toDotString());
+
+ }
+
+}
diff --git a/src-tests/rwsets/projetoip/TestProjetoIP.testPedidoGetPosicao.data b/src-tests/rwsets/projetoip/TestProjetoIP.testPedidoGetPosicao.data
new file mode 100644
index 0000000..f932922
--- /dev/null
+++ b/src-tests/rwsets/projetoip/TestProjetoIP.testPedidoGetPosicao.data
@@ -0,0 +1,17 @@
+digraph "DirectedGraph" {
+ graph [concentrate = true];
+ center=true;
+ fontsize=6;
+ node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial];
+ edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial];
+"int restaurante/RepositorioPedidosArray.getPosicao(restaurante/Pedido)"[color="red", fontsize="6", fontname="Arial"];
+"void restaurante/Pedido.(java/lang/String,restaurante/Cliente,Lrestaurante/Produto,java/lang/String,int,java/math/BigDecimal)" -> "java/lang/String restaurante/Pedido.getCodigo()" [label="java/lang/String restaurante/Pedido.codigo : 16" ]
+"void restaurante/Pedido.setCodigo(java/lang/String)" -> "java/lang/String restaurante/Pedido.getCodigo()" [label="java/lang/String restaurante/Pedido.codigo : 64" ]
+"void restaurante/RepositorioPedidosArray.(int)" -> "int restaurante/RepositorioPedidosArray.getPosicao(restaurante/Pedido)" [label="Lrestaurante/Pedido restaurante/RepositorioPedidosArray.pedidos : 12" ]
+"void restaurante/RepositorioPedidosArray.(int)" -> "int restaurante/RepositorioPedidosArray.getPosicao(restaurante/Pedido)" [label="int restaurante/RepositorioPedidosArray.indice : 13" ]
+"void restaurante/RepositorioPedidosArray.inserir(restaurante/Pedido)" -> "int restaurante/RepositorioPedidosArray.getPosicao(restaurante/Pedido)" [label="Lrestaurante/Pedido restaurante/RepositorioPedidosArray.pedidos : 17" ]
+"void restaurante/RepositorioPedidosArray.inserir(restaurante/Pedido)" -> "int restaurante/RepositorioPedidosArray.getPosicao(restaurante/Pedido)" [label="int restaurante/RepositorioPedidosArray.indice : 18" ]
+"void restaurante/RepositorioPedidosArray.remover(restaurante/Pedido)" -> "int restaurante/RepositorioPedidosArray.getPosicao(restaurante/Pedido)" [label="Lrestaurante/Pedido restaurante/RepositorioPedidosArray.pedidos : 26" ]
+"void restaurante/RepositorioPedidosArray.remover(restaurante/Pedido)" -> "int restaurante/RepositorioPedidosArray.getPosicao(restaurante/Pedido)" [label="Lrestaurante/Pedido restaurante/RepositorioPedidosArray.pedidos : 27" ]
+"void restaurante/RepositorioPedidosArray.remover(restaurante/Pedido)" -> "int restaurante/RepositorioPedidosArray.getPosicao(restaurante/Pedido)" [label="int restaurante/RepositorioPedidosArray.indice : 28" ]
+}
diff --git a/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.java b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.java
new file mode 100644
index 0000000..181139b
--- /dev/null
+++ b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.java
@@ -0,0 +1,208 @@
+package rwsets.projetoipempacotado;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static rwsets.Helper.CLASS_NOT_FOUND;
+import static rwsets.Helper.EXCLUSION_FILE;
+import static rwsets.Helper.EXCLUSION_FILE_FOR_CALLGRAPH;
+import static rwsets.Helper.USER_DIR;
+import static rwsets.Helper.getExpectedResultsFilePath;
+import static rwsets.Helper.readFile;
+import japa.parser.ParseException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.ibm.wala.shrikeCT.InvalidClassFileException;
+import com.ibm.wala.util.CancelException;
+import com.ibm.wala.util.WalaException;
+
+import depend.util.graph.SimpleGraph;
+
+public class TestProjetoIPEmpacotado {
+ private static final String APPS_DIR = USER_DIR + "/example-apps";
+ private static final String APPS_JAR_DIR = APPS_DIR;
+ private static final String APPS_SRC_DIR = APPS_DIR + "/src";
+ private static final String JAR_FILE = APPS_JAR_DIR + "/projetoipempacotado.jar";
+ private static final String PACKAGE_FILTER = "br/ufpe/cin";
+
+ @Before
+ public void setup() {
+ assertTrue(new File(JAR_FILE).exists());
+ assertTrue(new File(EXCLUSION_FILE).exists());
+ assertTrue(new File(EXCLUSION_FILE_FOR_CALLGRAPH).exists());
+ }
+
+ private static SimpleGraph analyze(String classFilePath, String classFileLine) {
+ try {
+ return depend.Main.analyze(JAR_FILE, PACKAGE_FILTER, classFilePath, classFileLine);
+ } catch (IOException | WalaException | CancelException | ParseException | InvalidClassFileException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Known issue: breaks for subpackages
+ * RWSets generates invalid class name in depend/util/parser/Util.getLineAndWALAClassName:(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;, a workaround is necessary
+ * @throws IOException
+ * @throws WalaException
+ * @throws CancelException
+ * @throws ParseException
+ * @throws InvalidClassFileException
+ */
+ @Test
+ public void test1() throws IOException {
+ String classFileLine = "if (pedidos[i].getCodigo() == pedido.getCodigo()) {";
+ String classFilePath = APPS_SRC_DIR + "/IP/br/ufpe/cin/dados/RepositorioPedidosArray.java";
+
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+
+ String expectedResultsFile = getExpectedResultsFilePath();
+
+ PrintWriter fileWriter = new PrintWriter(new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+ @Test
+ public void test2() throws IOException {
+ String classFileLine = "if (this.procurar(pedido.getCodigo()) == null) {";
+ String classFilePath = APPS_SRC_DIR + "/IP/br/ufpe/cin/dados/RepositorioPedidosArray.java";
+
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+
+ String expectedResultsFile = getExpectedResultsFilePath();
+
+ PrintWriter fileWriter = new PrintWriter(new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+ @Test
+ public void test3() throws IOException {
+ String classFileLine = "return null;";
+ String classFilePath = APPS_SRC_DIR + "/IP/br/ufpe/cin/dados/RepositorioPedidosArray.java";
+
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+
+ String expectedResultsFile = getExpectedResultsFilePath();
+
+ PrintWriter fileWriter = new PrintWriter(new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+ @Test
+ public void test4() throws IOException {
+ String classFileLine = "if (pedidos[i].getCodigo().equals(codigo)) {";
+ String classFilePath = APPS_SRC_DIR + "/IP/br/ufpe/cin/dados/RepositorioPedidosArray.java";
+
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+
+ String expectedResultsFile = getExpectedResultsFilePath();
+
+ PrintWriter fileWriter = new PrintWriter(new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+ @Test
+ public void test5() throws IOException {
+ String classFileLine = "retorno = pedidos[i];";
+ String classFilePath = APPS_SRC_DIR + "/IP/br/ufpe/cin/dados/RepositorioPedidosArray.java";
+
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+
+ String expectedResultsFile = getExpectedResultsFilePath();
+
+ PrintWriter fileWriter = new PrintWriter(new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+ @Test
+ /**
+ * Known issue: doesn't provide support for 'implements' clause
+ * Exception is thrown at line 291 of depend/util/parser/Util.printTypeArgs:(Ljava/util/List;Ljava/lang/Object;Ljava/lang/StringBuffer;)V
+ * @throws IOException
+ * @throws WalaException
+ * @throws CancelException
+ * @throws ParseException
+ * @throws InvalidClassFileException
+ */
+ public void test6() throws IOException {
+ String classFileLine = "if (produtos[i].getCodigo() == produto.getCodigo()) {";
+ String classFilePath = APPS_SRC_DIR + "/IP/br/ufpe/cin/dados/RepositorioProdutosArray.java";
+
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+
+ String expectedResultsFile = getExpectedResultsFilePath();
+
+ PrintWriter fileWriter = new PrintWriter(new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+ @Test
+ /**
+ * Known issue: doesn't provide support for 'implements' clause
+ * Exception is thrown at line 291 of depend/util/parser/Util.printTypeArgs:(Ljava/util/List;Ljava/lang/Object;Ljava/lang/StringBuffer;)V
+ * @throws IOException
+ * @throws WalaException
+ * @throws CancelException
+ * @throws ParseException
+ * @throws InvalidClassFileException
+ */
+ public void test7() throws IOException {
+ String classFileLine = "retorno = produtos[i];";
+ String classFilePath = APPS_SRC_DIR + "/IP/br/ufpe/cin/dados/RepositorioProdutosArray.java";
+
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+
+ String expectedResultsFile = getExpectedResultsFilePath();
+
+ PrintWriter fileWriter = new PrintWriter(new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+}
\ No newline at end of file
diff --git a/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test1.data b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test1.data
new file mode 100644
index 0000000..1db26b8
--- /dev/null
+++ b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test1.data
@@ -0,0 +1,17 @@
+digraph "DirectedGraph" {
+ graph [concentrate = true];
+ center=true;
+ fontsize=6;
+ node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial];
+ edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial];
+"int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)"[color="red", fontsize="6", fontname="Arial"];
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 14" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 15" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 19" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 20" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 28" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 29" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 30" ]
+"void br/ufpe/cin/restaurante/Pedido.(java/lang/String,br/ufpe/cin/restaurante/Cliente,Lbr/ufpe/cin/restaurante/Produto,java/lang/String,int,java/math/BigDecimal)" -> "java/lang/String br/ufpe/cin/restaurante/Pedido.getCodigo()" [label="java/lang/String br/ufpe/cin/restaurante/Pedido.codigo : 16" ]
+"void br/ufpe/cin/restaurante/Pedido.setCodigo(java/lang/String)" -> "java/lang/String br/ufpe/cin/restaurante/Pedido.getCodigo()" [label="java/lang/String br/ufpe/cin/restaurante/Pedido.codigo : 64" ]
+}
diff --git a/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test2.data b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test2.data
new file mode 100644
index 0000000..0f243c0
--- /dev/null
+++ b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test2.data
@@ -0,0 +1,31 @@
+digraph "DirectedGraph" {
+ graph [concentrate = true];
+ center=true;
+ fontsize=6;
+ node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial];
+ edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial];
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)"[color="red", fontsize="6", fontname="Arial"];
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 14" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 15" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 14" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 15" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 14" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 15" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 19" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 20" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 19" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 20" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 19" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 20" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 28" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 29" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 30" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 28" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 29" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "int br/ufpe/cin/dados/RepositorioPedidosArray.getPosicao(br/ufpe/cin/restaurante/Pedido)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 30" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 28" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 29" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 30" ]
+"void br/ufpe/cin/restaurante/Pedido.(java/lang/String,br/ufpe/cin/restaurante/Cliente,Lbr/ufpe/cin/restaurante/Produto,java/lang/String,int,java/math/BigDecimal)" -> "java/lang/String br/ufpe/cin/restaurante/Pedido.getCodigo()" [label="java/lang/String br/ufpe/cin/restaurante/Pedido.codigo : 16" ]
+"void br/ufpe/cin/restaurante/Pedido.setCodigo(java/lang/String)" -> "java/lang/String br/ufpe/cin/restaurante/Pedido.getCodigo()" [label="java/lang/String br/ufpe/cin/restaurante/Pedido.codigo : 64" ]
+}
diff --git a/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test3.data b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test3.data
new file mode 100644
index 0000000..bec2915
--- /dev/null
+++ b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test3.data
@@ -0,0 +1,8 @@
+digraph "DirectedGraph" {
+ graph [concentrate = true];
+ center=true;
+ fontsize=6;
+ node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial];
+ edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial];
+"java/util/Iterator br/ufpe/cin/dados/RepositorioPedidosArray.procurar(br/ufpe/cin/restaurante/Pedido)"[color="red", fontsize="6", fontname="Arial"];
+}
diff --git a/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test4.data b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test4.data
new file mode 100644
index 0000000..c6dfe13
--- /dev/null
+++ b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test4.data
@@ -0,0 +1,17 @@
+digraph "DirectedGraph" {
+ graph [concentrate = true];
+ center=true;
+ fontsize=6;
+ node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial];
+ edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial];
+"br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)"[color="red", fontsize="6", fontname="Arial"];
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 14" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 15" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 19" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 20" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 28" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 29" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 30" ]
+"void br/ufpe/cin/restaurante/Pedido.(java/lang/String,br/ufpe/cin/restaurante/Cliente,Lbr/ufpe/cin/restaurante/Produto,java/lang/String,int,java/math/BigDecimal)" -> "java/lang/String br/ufpe/cin/restaurante/Pedido.getCodigo()" [label="java/lang/String br/ufpe/cin/restaurante/Pedido.codigo : 16" ]
+"void br/ufpe/cin/restaurante/Pedido.setCodigo(java/lang/String)" -> "java/lang/String br/ufpe/cin/restaurante/Pedido.getCodigo()" [label="java/lang/String br/ufpe/cin/restaurante/Pedido.codigo : 64" ]
+}
diff --git a/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test5.data b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test5.data
new file mode 100644
index 0000000..c6dfe13
--- /dev/null
+++ b/src-tests/rwsets/projetoipempacotado/TestProjetoIPEmpacotado.test5.data
@@ -0,0 +1,17 @@
+digraph "DirectedGraph" {
+ graph [concentrate = true];
+ center=true;
+ fontsize=6;
+ node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial];
+ edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial];
+"br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)"[color="red", fontsize="6", fontname="Arial"];
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 14" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.(int)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 15" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 19" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.inserir(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 20" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 28" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="Lbr/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.pedidos : 29" ]
+"void br/ufpe/cin/dados/RepositorioPedidosArray.remover(br/ufpe/cin/restaurante/Pedido)" -> "br/ufpe/cin/restaurante/Pedido br/ufpe/cin/dados/RepositorioPedidosArray.procurar(java/lang/String)" [label="int br/ufpe/cin/dados/RepositorioPedidosArray.indice : 30" ]
+"void br/ufpe/cin/restaurante/Pedido.(java/lang/String,br/ufpe/cin/restaurante/Cliente,Lbr/ufpe/cin/restaurante/Produto,java/lang/String,int,java/math/BigDecimal)" -> "java/lang/String br/ufpe/cin/restaurante/Pedido.getCodigo()" [label="java/lang/String br/ufpe/cin/restaurante/Pedido.codigo : 16" ]
+"void br/ufpe/cin/restaurante/Pedido.setCodigo(java/lang/String)" -> "java/lang/String br/ufpe/cin/restaurante/Pedido.getCodigo()" [label="java/lang/String br/ufpe/cin/restaurante/Pedido.codigo : 64" ]
+}
diff --git a/src-tests/rwsets/projetopg/Test_PG_Projeto_2_Jar.java b/src-tests/rwsets/projetopg/Test_PG_Projeto_2_Jar.java
new file mode 100644
index 0000000..f5665fb
--- /dev/null
+++ b/src-tests/rwsets/projetopg/Test_PG_Projeto_2_Jar.java
@@ -0,0 +1,130 @@
+package rwsets.projetopg;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static rwsets.Helper.CLASS_NOT_FOUND;
+import static rwsets.Helper.EXCLUSION_FILE;
+import static rwsets.Helper.EXCLUSION_FILE_FOR_CALLGRAPH;
+import static rwsets.Helper.USER_DIR;
+import static rwsets.Helper.getExpectedResultsFilePath;
+import static rwsets.Helper.readFile;
+import japa.parser.ParseException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.ibm.wala.shrikeCT.InvalidClassFileException;
+import com.ibm.wala.util.CancelException;
+import com.ibm.wala.util.WalaException;
+
+import depend.util.graph.SimpleGraph;
+
+public class Test_PG_Projeto_2_Jar {
+ private static final String APPS_DIR = USER_DIR + "/example-apps";
+ private static final String APPS_JAR_DIR = APPS_DIR;
+ private static final String APPS_SRC_DIR = APPS_DIR + "/src";
+ private static final String JAR_FILE = APPS_JAR_DIR + "/PG_Projeto_2.jar";
+ private static final String PACKAGE_FILTER = "pgprojeto2";
+
+ @Before
+ public void setup() {
+ assertTrue(new File(JAR_FILE).exists());
+ assertTrue(new File(EXCLUSION_FILE).exists());
+ assertTrue(new File(EXCLUSION_FILE_FOR_CALLGRAPH).exists());
+ }
+
+ private static SimpleGraph analyze(String classFilePath, String classFileLine) {
+ try {
+ return depend.Main.analyze(JAR_FILE, PACKAGE_FILTER, classFilePath, classFileLine);
+ } catch (IOException | WalaException | CancelException | ParseException | InvalidClassFileException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Unexpected result: can't find class 'Core'
+ * @throws IOException
+ * @throws WalaException
+ * @throws CancelException
+ * @throws ParseException
+ * @throws InvalidClassFileException
+ */
+ @Test
+ public void test1() throws IOException {
+ String classFileLine = "luz = leitura_luz(iluninacaoParam);";
+ String classFilePath = APPS_SRC_DIR + "/PG_Projeto_2/pgprojeto2/Core.java";
+
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+
+ String expectedResultsFile = getExpectedResultsFilePath();
+
+ PrintWriter fileWriter = new PrintWriter(new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+ /**
+ * Unexpected result: can't find class 'Superficie'
+ * @throws IOException
+ * @throws WalaException
+ * @throws CancelException
+ * @throws ParseException
+ * @throws InvalidClassFileException
+ */
+ @Test
+ public void test2() throws IOException {
+ String classFileLine = "int resY = box.imagem[fzInt-1].getHeight(); int resX = box.imagem[fzInt-1].getWidth();";
+ String classFilePath = APPS_SRC_DIR + "/PG_Projeto_2/pgprojeto2/Superficie.java";
+
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+
+ String expectedResultsFile = getExpectedResultsFilePath();
+
+ PrintWriter fileWriter = new PrintWriter(new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+ /**
+ * Unexpected result: throws null pointer exception
+ * @throws IOException
+ * @throws WalaException
+ * @throws CancelException
+ * @throws ParseException
+ * @throws InvalidClassFileException
+ */
+ @Test
+ public void test3() throws IOException {
+ String classFileLine = "this.C = C;";
+ String classFilePath = APPS_SRC_DIR + "/PG_Projeto_2/pgprojeto2/Camera.java";
+
+ assertTrue(CLASS_NOT_FOUND, new File(classFilePath).exists());
+
+ SimpleGraph graph = analyze(classFilePath, classFileLine);
+
+ String expectedResultsFile = getExpectedResultsFilePath();
+
+ PrintWriter fileWriter = new PrintWriter(new FileWriter(expectedResultsFile));
+ fileWriter.print(graph.toDotString());
+ fileWriter.close();
+
+ assertTrue(new File(expectedResultsFile).exists());
+ assertEquals(readFile(expectedResultsFile), graph.toDotString());
+ }
+
+}