Commit 4995ad98 authored by pysaumont's avatar pysaumont
Browse files

Fixes after AC review for chapter 15

parent fac86561
......@@ -66,7 +66,7 @@ public final class Assertion {
assertType(element, clazz, String.format("Wrong type: %s, expected: %s", element.getClass().getName(), clazz.getName()));
}
public static <A> void assertType(A element, Class<?> clazz, String message) {
assertCondition(element, e -> e.getClass().equals(clazz), message);
public static <A> Result<A> assertType(A element, Class<?> clazz, String message) {
return assertCondition(element, e -> e.getClass().equals(clazz), message);
}
}
......@@ -30,7 +30,6 @@ public class Person {
public static Result<Person> getAsPerson(String propertyName, PropertyReader propertyReader) {
Result<String> rString = propertyReader.getAsPropertyString(propertyName);
rString.forEach(System.out::println);
Result<PropertyReader> rPropReader = rString.map(PropertyReader::stringPropertyReader);
return rPropReader.flatMap(Person::readPerson);
}
......
package com.fpinjava.application.listing15_07;
package com.fpinjava.application.listing15_07_08;
import com.fpinjava.common.List;
import com.fpinjava.common.Result;
......
package com.fpinjava.application.listing15_07_08;
import com.fpinjava.common.Executable;
import com.fpinjava.common.List;
import com.fpinjava.common.Result;
import com.fpinjava.common.Tuple;
public class Test {
private final static Tuple<String, List<String>> format = new Tuple<>("First Name : %s\n" +
"\tLast Name : %s\n" +
"\tEmail : %s\n" +
"\tSalary : %s", List.list("firstname", "lastname", "email", "salary"));
public static void main(String... args) {
Executable program = ReadXmlFile.readXmlFile(Test::getXmlFilePath, Test::getRootElementName, format, Test::processList);
program.exec();
}
private static Result<String> getXmlFilePath() {
return Result.of("file.xml"); // <- adjust path
}
private static Result<String> getRootElementName() {
return Result.of("staff");
}
private static <T> void processList(List<T> list) {
list.forEach(System.out::println);
}
}
<?xml version="1.0"?>
<company>
<staff>
<firstname>Paul</firstname>
<lastname>Smith</lastname>
<email>paul.smith@acme.com</email>
<salary>100000</salary>
</staff>
<staff>
<firstname>Mary</firstname>
<lastname>Colson</lastname>
<email>mary.colson@acme.com</email>
<salary>200000</salary>
</staff>
</company>
......@@ -20,7 +20,7 @@ public class ReadXmlFile {
public static void main(String[] args) {
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("/media/SANSTITRE/fpinjava/fpinjava-parent/fpinjava-common/src/main/java/com/fpinjava/xml2/version_0/empty.xml");
File xmlFile = new File("/path/to/file.xml"); // Fix the path
try {
......
/**
* Test.
*
* @author pysaumont
* @date 06/03/2016 20:21
*/
public class Test {
public static void main(String[] args) {
System.out.println(inverse(0));
}
static double inverse(int x) {
return 1.0 / x * 2345;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment