Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 22 files changed
  • 0 commit comments
  • 1 contributor
Showing with 310 additions and 0 deletions.
  1. +9 −0 fj-16-argentum/.classpath
  2. +17 −0 fj-16-argentum/.project
  3. +12 −0 fj-16-argentum/.settings/org.eclipse.jdt.core.prefs
  4. BIN fj-16-argentum/bin/br/com/caelum/argentum/Candlestick.class
  5. BIN fj-16-argentum/bin/br/com/caelum/argentum/Negocio.class
  6. BIN fj-16-argentum/bin/br/com/caelum/argentum/NegocioTest.class
  7. BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/CandlestickFactory.class
  8. BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/CandlestickFactoryTest.class
  9. BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/LeitorXML.class
  10. BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/LeitorXMLTest.class
  11. BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/TesteCandlestickFactory.class
  12. BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/TesteCandlestickFactoryComUmNegocioApenas.class
  13. BIN fj-16-argentum/lib/xstream-1.4.2.jar
  14. +54 −0 fj-16-argentum/src/main/java/br/com/caelum/argentum/Candlestick.java
  15. +35 −0 fj-16-argentum/src/main/java/br/com/caelum/argentum/Negocio.java
  16. +30 −0 fj-16-argentum/src/main/java/br/com/caelum/argentum/reader/CandlestickFactory.java
  17. +17 −0 fj-16-argentum/src/main/java/br/com/caelum/argentum/reader/LeitorXML.java
  18. +30 −0 fj-16-argentum/src/main/java/br/com/caelum/argentum/reader/TesteCandlestickFactory.java
  19. +27 −0 ...gentum/src/main/java/br/com/caelum/argentum/reader/TesteCandlestickFactoryComUmNegocioApenas.java
  20. +26 −0 fj-16-argentum/src/test/java/br/com/caelum/argentum/NegocioTest.java
  21. +35 −0 fj-16-argentum/src/test/java/br/com/caelum/argentum/reader/CandlestickFactoryTest.java
  22. +18 −0 fj-16-argentum/src/test/java/br/com/caelum/argentum/reader/LeitorXMLTest.java
View
9 fj-16-argentum/.classpath
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="lib" path="lib/xstream-1.4.2.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
17 fj-16-argentum/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>fj-16-argentum</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
12 fj-16-argentum/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Tue May 01 18:23:41 BRT 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
View
BIN fj-16-argentum/bin/br/com/caelum/argentum/Candlestick.class
Binary file not shown.
View
BIN fj-16-argentum/bin/br/com/caelum/argentum/Negocio.class
Binary file not shown.
View
BIN fj-16-argentum/bin/br/com/caelum/argentum/NegocioTest.class
Binary file not shown.
View
BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/CandlestickFactory.class
Binary file not shown.
View
BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/CandlestickFactoryTest.class
Binary file not shown.
View
BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/LeitorXML.class
Binary file not shown.
View
BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/LeitorXMLTest.class
Binary file not shown.
View
BIN fj-16-argentum/bin/br/com/caelum/argentum/reader/TesteCandlestickFactory.class
Binary file not shown.
View
BIN ...rgentum/bin/br/com/caelum/argentum/reader/TesteCandlestickFactoryComUmNegocioApenas.class
Binary file not shown.
View
BIN fj-16-argentum/lib/xstream-1.4.2.jar
Binary file not shown.
View
54 fj-16-argentum/src/main/java/br/com/caelum/argentum/Candlestick.java
@@ -0,0 +1,54 @@
+package br.com.caelum.argentum;
+
+import java.util.Calendar;
+
+public final class Candlestick {
+ private final double abertura;
+ private final double fechamento;
+ private final double minimo;
+ private final double maximo;
+ private final double volume;
+ private final Calendar data;
+
+ public Candlestick(double abertura, double fechamento, double minimo,
+ double maximo, double volume, Calendar data) {
+ this.abertura = abertura;
+ this.fechamento = fechamento;
+ this.minimo = minimo;
+ this.maximo = maximo;
+ this.volume = volume;
+ this.data = data;
+ }
+
+ public double getAbertura() {
+ return abertura;
+ }
+
+ public double getFechamento() {
+ return fechamento;
+ }
+
+ public double getMinimo() {
+ return minimo;
+ }
+
+ public double getMaximo() {
+ return maximo;
+ }
+
+ public double getVolume() {
+ return volume;
+ }
+
+ public Calendar getData() {
+ return data;
+ }
+
+ public Boolean isAlta() {
+ return this.abertura < this.fechamento;
+ }
+
+ public Boolean isBaixa() {
+ return this.abertura > this.fechamento;
+ }
+}
View
35 fj-16-argentum/src/main/java/br/com/caelum/argentum/Negocio.java
@@ -0,0 +1,35 @@
+package br.com.caelum.argentum;
+
+import java.util.Calendar;
+
+public final class Negocio {
+ private final double preco;
+ private final int quantidade;
+ private final Calendar data;
+
+ public Negocio(double preco, int quantidade, Calendar data) {
+ if (data == null) {
+ throw new IllegalArgumentException("data não pode ser nula");
+ }
+
+ this.preco = preco;
+ this.quantidade = quantidade;
+ this.data = data;
+ }
+
+ public double getPreco() {
+ return preco;
+ }
+
+ public int getQuantidade() {
+ return quantidade;
+ }
+
+ public Calendar getData() {
+ return (Calendar) this.data.clone();
+ }
+
+ public double getVolume() {
+ return preco * quantidade;
+ }
+}
View
30 fj-16-argentum/src/main/java/br/com/caelum/argentum/reader/CandlestickFactory.java
@@ -0,0 +1,30 @@
+package br.com.caelum.argentum.reader;
+
+import java.util.List;
+import java.util.Calendar;
+
+import br.com.caelum.argentum.Candlestick;
+import br.com.caelum.argentum.Negocio;
+
+public class CandlestickFactory {
+ public Candlestick constroiCandleParaData(Calendar data, List<Negocio> negocios) {
+ double maximo = Double.MIN_VALUE;//negocios.get(0).getPreco();
+ double minimo = Double.MAX_VALUE;//negocios.get(0).getPreco();
+ double volume = 0;
+
+ for (Negocio negocio : negocios) {
+ volume += negocio.getVolume();
+
+ if (negocio.getPreco() > maximo) {
+ maximo = negocio.getPreco();
+ } else if (negocio.getPreco() < minimo) {
+ minimo = negocio.getPreco();
+ }
+ }
+
+ double abertura = negocios.isEmpty() ? 0 : negocios.get(0).getPreco();
+ double fechamento = negocios.isEmpty() ? 0 : negocios.get(negocios.size() - 1).getPreco();
+
+ return new Candlestick(abertura, fechamento, minimo, maximo, volume, data);
+ }
+}
View
17 fj-16-argentum/src/main/java/br/com/caelum/argentum/reader/LeitorXML.java
@@ -0,0 +1,17 @@
+package br.com.caelum.argentum.reader;
+
+import java.io.Reader;
+import java.util.List;
+
+import br.com.caelum.argentum.Negocio;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+
+public class LeitorXML {
+ public List<Negocio> carrega(Reader fonte) {
+ XStream stream = new XStream(new DomDriver());
+ stream.alias("negocio", Negocio.class);
+ return (List<Negocio>) stream.fromXML(fonte);
+ }
+}
View
30 fj-16-argentum/src/main/java/br/com/caelum/argentum/reader/TesteCandlestickFactory.java
@@ -0,0 +1,30 @@
+package br.com.caelum.argentum.reader;
+
+import java.lang.reflect.Array;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.List;
+
+import br.com.caelum.argentum.Candlestick;
+import br.com.caelum.argentum.Negocio;
+
+public class TesteCandlestickFactory {
+ public static void main(String[] args) {
+ Calendar hoje = Calendar.getInstance();
+
+ Negocio negocio1 = new Negocio(40.5, 100, hoje);
+ Negocio negocio2 = new Negocio(45.0, 100, hoje);
+ Negocio negocio3 = new Negocio(39.8, 100, hoje);
+ Negocio negocio4 = new Negocio(42.3, 100, hoje);
+
+ List<Negocio> negocios = Arrays.asList(negocio1, negocio2, negocio3, negocio4);
+ CandlestickFactory factory = new CandlestickFactory();
+ Candlestick candle = factory.constroiCandleParaData(hoje, negocios);
+
+ System.out.println(candle.getAbertura());
+ System.out.println(candle.getFechamento());
+ System.out.println(candle.getMinimo());
+ System.out.println(candle.getMaximo());
+ System.out.println(candle.getVolume());
+ }
+}
View
27 ...rc/main/java/br/com/caelum/argentum/reader/TesteCandlestickFactoryComUmNegocioApenas.java
@@ -0,0 +1,27 @@
+package br.com.caelum.argentum.reader;
+
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.List;
+
+import br.com.caelum.argentum.Candlestick;
+import br.com.caelum.argentum.Negocio;
+
+public class TesteCandlestickFactoryComUmNegocioApenas {
+ public static void main(String[] args) {
+ Calendar hoje = Calendar.getInstance();
+ //Negocio negocio1 = new Negocio(40.5, 100, hoje);
+
+ List<Negocio> negocios = Arrays.asList();
+
+ CandlestickFactory factory = new CandlestickFactory();
+ Candlestick candle = factory.constroiCandleParaData(hoje, negocios);
+
+ System.out.println(candle.getAbertura());
+ System.out.println(candle.getFechamento());
+ System.out.println(candle.getMinimo());
+ System.out.println(candle.getMaximo());
+ System.out.println(candle.getVolume());
+
+ }
+}
View
26 fj-16-argentum/src/test/java/br/com/caelum/argentum/NegocioTest.java
@@ -0,0 +1,26 @@
+package br.com.caelum.argentum;
+
+import java.util.Calendar;
+
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class NegocioTest {
+ @Test
+ public void testDataDoNegocioEhImutavel(){
+ Calendar c = Calendar.getInstance();
+ c.set(Calendar.DAY_OF_MONTH, 15);
+
+ Negocio n = new Negocio(10, 5, c);
+
+ n.getData().set(Calendar.DAY_OF_MONTH, 20);
+
+ Assert.assertEquals(15, n.getData().get(Calendar.DAY_OF_MONTH));
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testNegocioComDataNula(){
+ Negocio n = new Negocio(10, 5, null);
+ }
+}
View
35 fj-16-argentum/src/test/java/br/com/caelum/argentum/reader/CandlestickFactoryTest.java
@@ -0,0 +1,35 @@
+package br.com.caelum.argentum.reader;
+
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import br.com.caelum.argentum.Candlestick;
+import br.com.caelum.argentum.Negocio;
+
+public class CandlestickFactoryTest {
+ @Test
+ public void testSimplesSequenciaDeNegocios(){
+ Calendar hoje = Calendar.getInstance();
+
+ Negocio negocio1 = new Negocio(40.5, 100, hoje);
+ //Negocio negocio2 = new Negocio(45.0, 100, hoje);
+ //Negocio negocio3 = new Negocio(39.8, 100, hoje);
+ //Negocio negocio4 = new Negocio(42.3, 100, hoje);
+
+ List<Negocio> negocios = Arrays.asList(negocio1);
+ CandlestickFactory factory = new CandlestickFactory();
+ Candlestick candle = factory.constroiCandleParaData(hoje, negocios);
+
+ Assert.assertEquals(40.5, candle.getAbertura(), 0.00001);
+ Assert.assertEquals(40.5, candle.getFechamento(), 0.00001);
+ Assert.assertEquals(40.5, candle.getMinimo(), 0.00001);
+ Assert.assertEquals(40.5, candle.getMaximo(), 0.00001);
+ Assert.assertEquals(4050.0, candle.getVolume(), 0.00001);
+ }
+
+}
View
18 fj-16-argentum/src/test/java/br/com/caelum/argentum/reader/LeitorXMLTest.java
@@ -0,0 +1,18 @@
+package br.com.caelum.argentum.reader;
+
+import java.io.StringReader;
+import java.util.List;
+
+import org.junit.Test;
+
+import br.com.caelum.argentum.Negocio;
+
+public class LeitorXMLTest {
+ @Test
+ public void testLeitorDeXMLCarregaListaDeNegocio(){
+ String xmlDeTeste = "<list><negocio><preco>43.5</preco><quantidade>1000</quantidade><data><time>555454646</time></data></negocio></list>";
+
+ LeitorXML leitorXML = new LeitorXML();
+ List<Negocio> negocios = leitorXML.carrega(new StringReader(xmlDeTeste));
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.