Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
commit
6c6109b554
@ -151,20 +151,20 @@ public class CayenneAdvancedOperationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTwoAuthor_whenInObjS_thenWeGetAuthors() {
|
public void givenTwoAuthor_whenInObjS_thenWeGetAuthors() {
|
||||||
String [] args = {"Paul Xavier", "pAuL Smith", "Vicky Sarra"};
|
List<String> names = Arrays.asList("Paul Xavier", "pAuL Smith", "Vicky Sarra");
|
||||||
List<Author> authors = ObjectSelect.query(Author.class)
|
List<Author> authors = ObjectSelect.query(Author.class)
|
||||||
.where(Author.NAME.in(Arrays.asList(args)))
|
.where(Author.NAME.in(names))
|
||||||
.select(context);
|
.select(context);
|
||||||
|
|
||||||
assertEquals(authors.size(), 3);
|
assertEquals(authors.size(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTwoAuthor_whenNinObjS_thenWeGetAuthors() {
|
public void givenTwoAuthor_whenNinObjS_thenWeGetAuthors() {
|
||||||
String [] args = {"Paul Xavier", "pAuL Smith"};
|
List<String> names = Arrays.asList("Paul Xavier", "pAuL Smith");
|
||||||
List<Author> authors = ObjectSelect.query(Author.class)
|
List<Author> authors = ObjectSelect.query(Author.class)
|
||||||
.where(Author.NAME.nin(Arrays.asList(args)))
|
.where(Author.NAME.nin(names))
|
||||||
.select(context);
|
.select(context);
|
||||||
Author author = authors.get(0);
|
Author author = authors.get(0);
|
||||||
|
|
||||||
assertEquals(authors.size(), 1);
|
assertEquals(authors.size(), 1);
|
||||||
|
5
deeplearning4j/README.md
Normal file
5
deeplearning4j/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
### Sample deeplearning4j Project
|
||||||
|
This is a sample project for the [deeplearning4j](https://deeplearning4j.org) library.
|
||||||
|
|
||||||
|
### Relevant Articles:
|
||||||
|
- [A Guide to deeplearning4j](http://www.baeldung.com/a-guide-to-deeplearning4j/)
|
33
deeplearning4j/pom.xml
Normal file
33
deeplearning4j/pom.xml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.baeldung.deeplearning4j</groupId>
|
||||||
|
<artifactId>deeplearning4j</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>deeplearning4j</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<dl4j.version>0.9.1</dl4j.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.nd4j</groupId>
|
||||||
|
<artifactId>nd4j-native-platform</artifactId>
|
||||||
|
<version>${dl4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.deeplearning4j</groupId>
|
||||||
|
<artifactId>deeplearning4j-core</artifactId>
|
||||||
|
<version>${dl4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,80 @@
|
|||||||
|
package com.baeldung.deeplearning4j;
|
||||||
|
|
||||||
|
import org.datavec.api.records.reader.RecordReader;
|
||||||
|
import org.datavec.api.records.reader.impl.csv.CSVRecordReader;
|
||||||
|
import org.datavec.api.split.FileSplit;
|
||||||
|
import org.datavec.api.util.ClassPathResource;
|
||||||
|
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator;
|
||||||
|
import org.deeplearning4j.eval.Evaluation;
|
||||||
|
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
|
||||||
|
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
|
||||||
|
import org.deeplearning4j.nn.conf.layers.DenseLayer;
|
||||||
|
import org.deeplearning4j.nn.conf.layers.OutputLayer;
|
||||||
|
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
|
||||||
|
import org.deeplearning4j.nn.weights.WeightInit;
|
||||||
|
import org.nd4j.linalg.activations.Activation;
|
||||||
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
|
import org.nd4j.linalg.dataset.DataSet;
|
||||||
|
import org.nd4j.linalg.dataset.SplitTestAndTrain;
|
||||||
|
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
|
||||||
|
import org.nd4j.linalg.dataset.api.preprocessor.DataNormalization;
|
||||||
|
import org.nd4j.linalg.dataset.api.preprocessor.NormalizerStandardize;
|
||||||
|
import org.nd4j.linalg.lossfunctions.LossFunctions;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class IrisClassifier {
|
||||||
|
|
||||||
|
private static final int CLASSES_COUNT = 3;
|
||||||
|
private static final int FEATURES_COUNT = 4;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException, InterruptedException {
|
||||||
|
|
||||||
|
DataSet allData;
|
||||||
|
try (RecordReader recordReader = new CSVRecordReader(0, ',')) {
|
||||||
|
recordReader.initialize(new FileSplit(new ClassPathResource("iris.txt").getFile()));
|
||||||
|
|
||||||
|
DataSetIterator iterator = new RecordReaderDataSetIterator(recordReader, 150, FEATURES_COUNT, CLASSES_COUNT);
|
||||||
|
allData = iterator.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
allData.shuffle(42);
|
||||||
|
|
||||||
|
DataNormalization normalizer = new NormalizerStandardize();
|
||||||
|
normalizer.fit(allData);
|
||||||
|
normalizer.transform(allData);
|
||||||
|
|
||||||
|
SplitTestAndTrain testAndTrain = allData.splitTestAndTrain(0.65);
|
||||||
|
DataSet trainingData = testAndTrain.getTrain();
|
||||||
|
DataSet testData = testAndTrain.getTest();
|
||||||
|
|
||||||
|
MultiLayerConfiguration configuration = new NeuralNetConfiguration.Builder()
|
||||||
|
.iterations(1000)
|
||||||
|
.activation(Activation.TANH)
|
||||||
|
.weightInit(WeightInit.XAVIER)
|
||||||
|
.learningRate(0.1)
|
||||||
|
.regularization(true).l2(0.0001)
|
||||||
|
.list()
|
||||||
|
.layer(0, new DenseLayer.Builder().nIn(FEATURES_COUNT).nOut(3)
|
||||||
|
.build())
|
||||||
|
.layer(1, new DenseLayer.Builder().nIn(3).nOut(3)
|
||||||
|
.build())
|
||||||
|
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
|
||||||
|
.activation(Activation.SOFTMAX)
|
||||||
|
.nIn(3).nOut(CLASSES_COUNT).build())
|
||||||
|
.backprop(true).pretrain(false)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
MultiLayerNetwork model = new MultiLayerNetwork(configuration);
|
||||||
|
model.init();
|
||||||
|
model.fit(trainingData);
|
||||||
|
|
||||||
|
INDArray output = model.output(testData.getFeatureMatrix());
|
||||||
|
|
||||||
|
Evaluation eval = new Evaluation(CLASSES_COUNT);
|
||||||
|
eval.eval(testData.getLabels(), output);
|
||||||
|
System.out.println(eval.stats());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
150
deeplearning4j/src/main/resources/iris.txt
Normal file
150
deeplearning4j/src/main/resources/iris.txt
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
5.1,3.5,1.4,0.2,0
|
||||||
|
4.9,3.0,1.4,0.2,0
|
||||||
|
4.7,3.2,1.3,0.2,0
|
||||||
|
4.6,3.1,1.5,0.2,0
|
||||||
|
5.0,3.6,1.4,0.2,0
|
||||||
|
5.4,3.9,1.7,0.4,0
|
||||||
|
4.6,3.4,1.4,0.3,0
|
||||||
|
5.0,3.4,1.5,0.2,0
|
||||||
|
4.4,2.9,1.4,0.2,0
|
||||||
|
4.9,3.1,1.5,0.1,0
|
||||||
|
5.4,3.7,1.5,0.2,0
|
||||||
|
4.8,3.4,1.6,0.2,0
|
||||||
|
4.8,3.0,1.4,0.1,0
|
||||||
|
4.3,3.0,1.1,0.1,0
|
||||||
|
5.8,4.0,1.2,0.2,0
|
||||||
|
5.7,4.4,1.5,0.4,0
|
||||||
|
5.4,3.9,1.3,0.4,0
|
||||||
|
5.1,3.5,1.4,0.3,0
|
||||||
|
5.7,3.8,1.7,0.3,0
|
||||||
|
5.1,3.8,1.5,0.3,0
|
||||||
|
5.4,3.4,1.7,0.2,0
|
||||||
|
5.1,3.7,1.5,0.4,0
|
||||||
|
4.6,3.6,1.0,0.2,0
|
||||||
|
5.1,3.3,1.7,0.5,0
|
||||||
|
4.8,3.4,1.9,0.2,0
|
||||||
|
5.0,3.0,1.6,0.2,0
|
||||||
|
5.0,3.4,1.6,0.4,0
|
||||||
|
5.2,3.5,1.5,0.2,0
|
||||||
|
5.2,3.4,1.4,0.2,0
|
||||||
|
4.7,3.2,1.6,0.2,0
|
||||||
|
4.8,3.1,1.6,0.2,0
|
||||||
|
5.4,3.4,1.5,0.4,0
|
||||||
|
5.2,4.1,1.5,0.1,0
|
||||||
|
5.5,4.2,1.4,0.2,0
|
||||||
|
4.9,3.1,1.5,0.1,0
|
||||||
|
5.0,3.2,1.2,0.2,0
|
||||||
|
5.5,3.5,1.3,0.2,0
|
||||||
|
4.9,3.1,1.5,0.1,0
|
||||||
|
4.4,3.0,1.3,0.2,0
|
||||||
|
5.1,3.4,1.5,0.2,0
|
||||||
|
5.0,3.5,1.3,0.3,0
|
||||||
|
4.5,2.3,1.3,0.3,0
|
||||||
|
4.4,3.2,1.3,0.2,0
|
||||||
|
5.0,3.5,1.6,0.6,0
|
||||||
|
5.1,3.8,1.9,0.4,0
|
||||||
|
4.8,3.0,1.4,0.3,0
|
||||||
|
5.1,3.8,1.6,0.2,0
|
||||||
|
4.6,3.2,1.4,0.2,0
|
||||||
|
5.3,3.7,1.5,0.2,0
|
||||||
|
5.0,3.3,1.4,0.2,0
|
||||||
|
7.0,3.2,4.7,1.4,1
|
||||||
|
6.4,3.2,4.5,1.5,1
|
||||||
|
6.9,3.1,4.9,1.5,1
|
||||||
|
5.5,2.3,4.0,1.3,1
|
||||||
|
6.5,2.8,4.6,1.5,1
|
||||||
|
5.7,2.8,4.5,1.3,1
|
||||||
|
6.3,3.3,4.7,1.6,1
|
||||||
|
4.9,2.4,3.3,1.0,1
|
||||||
|
6.6,2.9,4.6,1.3,1
|
||||||
|
5.2,2.7,3.9,1.4,1
|
||||||
|
5.0,2.0,3.5,1.0,1
|
||||||
|
5.9,3.0,4.2,1.5,1
|
||||||
|
6.0,2.2,4.0,1.0,1
|
||||||
|
6.1,2.9,4.7,1.4,1
|
||||||
|
5.6,2.9,3.6,1.3,1
|
||||||
|
6.7,3.1,4.4,1.4,1
|
||||||
|
5.6,3.0,4.5,1.5,1
|
||||||
|
5.8,2.7,4.1,1.0,1
|
||||||
|
6.2,2.2,4.5,1.5,1
|
||||||
|
5.6,2.5,3.9,1.1,1
|
||||||
|
5.9,3.2,4.8,1.8,1
|
||||||
|
6.1,2.8,4.0,1.3,1
|
||||||
|
6.3,2.5,4.9,1.5,1
|
||||||
|
6.1,2.8,4.7,1.2,1
|
||||||
|
6.4,2.9,4.3,1.3,1
|
||||||
|
6.6,3.0,4.4,1.4,1
|
||||||
|
6.8,2.8,4.8,1.4,1
|
||||||
|
6.7,3.0,5.0,1.7,1
|
||||||
|
6.0,2.9,4.5,1.5,1
|
||||||
|
5.7,2.6,3.5,1.0,1
|
||||||
|
5.5,2.4,3.8,1.1,1
|
||||||
|
5.5,2.4,3.7,1.0,1
|
||||||
|
5.8,2.7,3.9,1.2,1
|
||||||
|
6.0,2.7,5.1,1.6,1
|
||||||
|
5.4,3.0,4.5,1.5,1
|
||||||
|
6.0,3.4,4.5,1.6,1
|
||||||
|
6.7,3.1,4.7,1.5,1
|
||||||
|
6.3,2.3,4.4,1.3,1
|
||||||
|
5.6,3.0,4.1,1.3,1
|
||||||
|
5.5,2.5,4.0,1.3,1
|
||||||
|
5.5,2.6,4.4,1.2,1
|
||||||
|
6.1,3.0,4.6,1.4,1
|
||||||
|
5.8,2.6,4.0,1.2,1
|
||||||
|
5.0,2.3,3.3,1.0,1
|
||||||
|
5.6,2.7,4.2,1.3,1
|
||||||
|
5.7,3.0,4.2,1.2,1
|
||||||
|
5.7,2.9,4.2,1.3,1
|
||||||
|
6.2,2.9,4.3,1.3,1
|
||||||
|
5.1,2.5,3.0,1.1,1
|
||||||
|
5.7,2.8,4.1,1.3,1
|
||||||
|
6.3,3.3,6.0,2.5,2
|
||||||
|
5.8,2.7,5.1,1.9,2
|
||||||
|
7.1,3.0,5.9,2.1,2
|
||||||
|
6.3,2.9,5.6,1.8,2
|
||||||
|
6.5,3.0,5.8,2.2,2
|
||||||
|
7.6,3.0,6.6,2.1,2
|
||||||
|
4.9,2.5,4.5,1.7,2
|
||||||
|
7.3,2.9,6.3,1.8,2
|
||||||
|
6.7,2.5,5.8,1.8,2
|
||||||
|
7.2,3.6,6.1,2.5,2
|
||||||
|
6.5,3.2,5.1,2.0,2
|
||||||
|
6.4,2.7,5.3,1.9,2
|
||||||
|
6.8,3.0,5.5,2.1,2
|
||||||
|
5.7,2.5,5.0,2.0,2
|
||||||
|
5.8,2.8,5.1,2.4,2
|
||||||
|
6.4,3.2,5.3,2.3,2
|
||||||
|
6.5,3.0,5.5,1.8,2
|
||||||
|
7.7,3.8,6.7,2.2,2
|
||||||
|
7.7,2.6,6.9,2.3,2
|
||||||
|
6.0,2.2,5.0,1.5,2
|
||||||
|
6.9,3.2,5.7,2.3,2
|
||||||
|
5.6,2.8,4.9,2.0,2
|
||||||
|
7.7,2.8,6.7,2.0,2
|
||||||
|
6.3,2.7,4.9,1.8,2
|
||||||
|
6.7,3.3,5.7,2.1,2
|
||||||
|
7.2,3.2,6.0,1.8,2
|
||||||
|
6.2,2.8,4.8,1.8,2
|
||||||
|
6.1,3.0,4.9,1.8,2
|
||||||
|
6.4,2.8,5.6,2.1,2
|
||||||
|
7.2,3.0,5.8,1.6,2
|
||||||
|
7.4,2.8,6.1,1.9,2
|
||||||
|
7.9,3.8,6.4,2.0,2
|
||||||
|
6.4,2.8,5.6,2.2,2
|
||||||
|
6.3,2.8,5.1,1.5,2
|
||||||
|
6.1,2.6,5.6,1.4,2
|
||||||
|
7.7,3.0,6.1,2.3,2
|
||||||
|
6.3,3.4,5.6,2.4,2
|
||||||
|
6.4,3.1,5.5,1.8,2
|
||||||
|
6.0,3.0,4.8,1.8,2
|
||||||
|
6.9,3.1,5.4,2.1,2
|
||||||
|
6.7,3.1,5.6,2.4,2
|
||||||
|
6.9,3.1,5.1,2.3,2
|
||||||
|
5.8,2.7,5.1,1.9,2
|
||||||
|
6.8,3.2,5.9,2.3,2
|
||||||
|
6.7,3.3,5.7,2.5,2
|
||||||
|
6.7,3.0,5.2,2.3,2
|
||||||
|
6.3,2.5,5.0,1.9,2
|
||||||
|
6.5,3.0,5.2,2.0,2
|
||||||
|
6.2,3.4,5.4,2.3,2
|
||||||
|
5.9,3.0,5.1,1.8,2
|
@ -601,6 +601,16 @@
|
|||||||
<artifactId>wurmloch-crdt</artifactId>
|
<artifactId>wurmloch-crdt</artifactId>
|
||||||
<version>${crdt.version}</version>
|
<version>${crdt.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.docx4j</groupId>
|
||||||
|
<artifactId>docx4j</artifactId>
|
||||||
|
<version>3.3.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
109
libraries/src/main/java/com/baeldung/docx/Docx4jExample.java
Normal file
109
libraries/src/main/java/com/baeldung/docx/Docx4jExample.java
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
package com.baeldung.docx;
|
||||||
|
|
||||||
|
import org.docx4j.dml.wordprocessingDrawing.Inline;
|
||||||
|
import org.docx4j.jaxb.Context;
|
||||||
|
import org.docx4j.model.table.TblFactory;
|
||||||
|
import org.docx4j.openpackaging.exceptions.Docx4JException;
|
||||||
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
||||||
|
import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage;
|
||||||
|
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
|
||||||
|
import org.docx4j.wml.BooleanDefaultTrue;
|
||||||
|
import org.docx4j.wml.Color;
|
||||||
|
import org.docx4j.wml.Drawing;
|
||||||
|
import org.docx4j.wml.ObjectFactory;
|
||||||
|
import org.docx4j.wml.P;
|
||||||
|
import org.docx4j.wml.R;
|
||||||
|
import org.docx4j.wml.RPr;
|
||||||
|
import org.docx4j.wml.Tbl;
|
||||||
|
import org.docx4j.wml.Tc;
|
||||||
|
import org.docx4j.wml.Text;
|
||||||
|
import org.docx4j.wml.Tr;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBElement;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class Docx4jExample {
|
||||||
|
|
||||||
|
void createDocumentPackage(String outputPath, String imagePath) throws Exception {
|
||||||
|
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
|
||||||
|
MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
|
||||||
|
mainDocumentPart.addStyledParagraphOfText("Title", "Hello World!");
|
||||||
|
mainDocumentPart.addParagraphOfText("Welcome To Baeldung!");
|
||||||
|
|
||||||
|
ObjectFactory factory = Context.getWmlObjectFactory();
|
||||||
|
P p = factory.createP();
|
||||||
|
R r = factory.createR();
|
||||||
|
Text t = factory.createText();
|
||||||
|
t.setValue("Welcome To Baeldung");
|
||||||
|
r.getContent().add(t);
|
||||||
|
p.getContent().add(r);
|
||||||
|
RPr rpr = factory.createRPr();
|
||||||
|
BooleanDefaultTrue b = new BooleanDefaultTrue();
|
||||||
|
rpr.setB(b);
|
||||||
|
rpr.setI(b);
|
||||||
|
rpr.setCaps(b);
|
||||||
|
Color red = factory.createColor();
|
||||||
|
red.setVal("green");
|
||||||
|
rpr.setColor(red);
|
||||||
|
r.setRPr(rpr);
|
||||||
|
mainDocumentPart.getContent().add(p);
|
||||||
|
|
||||||
|
File image = new File(imagePath);
|
||||||
|
byte[] fileContent = Files.readAllBytes(image.toPath());
|
||||||
|
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage
|
||||||
|
.createImagePart(wordPackage, fileContent);
|
||||||
|
Inline inline = imagePart.createImageInline(
|
||||||
|
"Baeldung Image", "Alt Text", 1, 2, false);
|
||||||
|
P Imageparagraph = addImageToParagraph(inline);
|
||||||
|
mainDocumentPart.getContent().add(Imageparagraph);
|
||||||
|
|
||||||
|
int writableWidthTwips = wordPackage.getDocumentModel()
|
||||||
|
.getSections().get(0).getPageDimensions()
|
||||||
|
.getWritableWidthTwips();
|
||||||
|
int columnNumber = 3;
|
||||||
|
Tbl tbl = TblFactory.createTable(3, 3, writableWidthTwips / columnNumber);
|
||||||
|
List<Object> rows = tbl.getContent();
|
||||||
|
for (Object row : rows) {
|
||||||
|
Tr tr = (Tr) row;
|
||||||
|
List<Object> cells = tr.getContent();
|
||||||
|
for (Object cell : cells) {
|
||||||
|
Tc td = (Tc) cell;
|
||||||
|
td.getContent().add(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mainDocumentPart.getContent().add(tbl);
|
||||||
|
File exportFile = new File(outputPath);
|
||||||
|
wordPackage.save(exportFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isTextExist(String testText) throws Docx4JException, JAXBException {
|
||||||
|
File doc = new File("helloWorld.docx");
|
||||||
|
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(doc);
|
||||||
|
MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart();
|
||||||
|
String textNodesXPath = "//w:t";
|
||||||
|
List<Object> paragraphs = mainDocumentPart.getJAXBNodesViaXPath(textNodesXPath, true);
|
||||||
|
for (Object obj : paragraphs) {
|
||||||
|
Text text = (Text) ((JAXBElement) obj).getValue();
|
||||||
|
String textValue = text.getValue();
|
||||||
|
if (textValue != null && textValue.contains(testText)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static P addImageToParagraph(Inline inline) {
|
||||||
|
ObjectFactory factory = new ObjectFactory();
|
||||||
|
P p = factory.createP();
|
||||||
|
R r = factory.createR();
|
||||||
|
p.getContent().add(r);
|
||||||
|
Drawing drawing = factory.createDrawing();
|
||||||
|
r.getContent().add(drawing);
|
||||||
|
drawing.getAnchorOrInline().add(inline);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
@ -52,7 +52,7 @@ public class MyJiraClient {
|
|||||||
myJiraClient.restClient.close();
|
myJiraClient.restClient.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createIssue(String projectKey, Long issueType, String issueSummary) {
|
private String createIssue(String projectKey, Long issueType, String issueSummary) {
|
||||||
|
|
||||||
IssueRestClient issueClient = restClient.getIssueClient();
|
IssueRestClient issueClient = restClient.getIssueClient();
|
||||||
|
|
||||||
@ -65,30 +65,30 @@ public class MyJiraClient {
|
|||||||
return restClient.getIssueClient().getIssue(issueKey).claim();
|
return restClient.getIssueClient().getIssue(issueKey).claim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void voteForAnIssue(Issue issue) {
|
private void voteForAnIssue(Issue issue) {
|
||||||
restClient.getIssueClient().vote(issue.getVotesUri()).claim();
|
restClient.getIssueClient().vote(issue.getVotesUri()).claim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotalVotesCount(String issueKey) {
|
private int getTotalVotesCount(String issueKey) {
|
||||||
BasicVotes votes = getIssue(issueKey).getVotes();
|
BasicVotes votes = getIssue(issueKey).getVotes();
|
||||||
return votes == null ? 0 : votes.getVotes();
|
return votes == null ? 0 : votes.getVotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addComment(Issue issue, String commentBody) {
|
private void addComment(Issue issue, String commentBody) {
|
||||||
restClient.getIssueClient().addComment(issue.getCommentsUri(), Comment.valueOf(commentBody));
|
restClient.getIssueClient().addComment(issue.getCommentsUri(), Comment.valueOf(commentBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Comment> getAllComments(String issueKey) {
|
private List<Comment> getAllComments(String issueKey) {
|
||||||
return StreamSupport.stream(getIssue(issueKey).getComments().spliterator(), false)
|
return StreamSupport.stream(getIssue(issueKey).getComments().spliterator(), false)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateIssueDescription(String issueKey, String newDescription) {
|
private void updateIssueDescription(String issueKey, String newDescription) {
|
||||||
IssueInput input = new IssueInputBuilder().setDescription(newDescription).build();
|
IssueInput input = new IssueInputBuilder().setDescription(newDescription).build();
|
||||||
restClient.getIssueClient().updateIssue(issueKey, input).claim();
|
restClient.getIssueClient().updateIssue(issueKey, input).claim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteIssue(String issueKey, boolean deleteSubtasks) {
|
private void deleteIssue(String issueKey, boolean deleteSubtasks) {
|
||||||
restClient.getIssueClient().deleteIssue(issueKey, deleteSubtasks).claim();
|
restClient.getIssueClient().deleteIssue(issueKey, deleteSubtasks).claim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
libraries/src/main/resources/image.jpg
Normal file
BIN
libraries/src/main/resources/image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 69 KiB |
@ -0,0 +1,19 @@
|
|||||||
|
package com.baeldung.docx;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class Docx4jReadAndWriteTest {
|
||||||
|
|
||||||
|
private static final String imagePath = "src/main/resources/image.jpg";
|
||||||
|
private static final String outputPath = "helloWorld.docx";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenWordPackage_whenTextExist_thenReturnTrue() throws Exception {
|
||||||
|
Docx4jExample docx4j = new Docx4jExample();
|
||||||
|
docx4j.createDocumentPackage(outputPath, imagePath);
|
||||||
|
assertTrue(docx4j.isTextExist("Hello World!"));
|
||||||
|
assertTrue(!docx4j.isTextExist("InexistantText"));
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,9 @@ import org.apache.http.client.HttpClient;
|
|||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -15,17 +17,16 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||||
|
|
||||||
public class JettyIntegrationTest {
|
public class JettyIntegrationTest {
|
||||||
private JettyServer jettyServer;
|
private static JettyServer jettyServer;
|
||||||
|
|
||||||
@Before
|
@BeforeClass
|
||||||
public void setup() throws Exception {
|
public static void setup() throws Exception {
|
||||||
jettyServer = new JettyServer();
|
jettyServer = new JettyServer();
|
||||||
jettyServer.start();
|
jettyServer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterClass
|
||||||
public void cleanup() throws Exception {
|
public static void cleanup() throws Exception {
|
||||||
Thread.sleep(2000);
|
|
||||||
jettyServer.stop();
|
jettyServer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
pom.xml
1
pom.xml
@ -248,6 +248,7 @@
|
|||||||
<module>mockserver</module>
|
<module>mockserver</module>
|
||||||
<module>undertow</module>
|
<module>undertow</module>
|
||||||
<module>vertx-and-rxjava</module>
|
<module>vertx-and-rxjava</module>
|
||||||
|
<module>deeplearning4j</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.baeldung.rxjava;
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
@ -16,9 +15,11 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.jayway.awaitility.Awaitility.await;
|
||||||
import static java.util.concurrent.Executors.newFixedThreadPool;
|
import static java.util.concurrent.Executors.newFixedThreadPool;
|
||||||
import static org.hamcrest.Matchers.hasItems;
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class SchedulersTest {
|
public class SchedulersTest {
|
||||||
private String result = "";
|
private String result = "";
|
||||||
@ -31,7 +32,8 @@ public class SchedulersTest {
|
|||||||
Scheduler scheduler = Schedulers.immediate();
|
Scheduler scheduler = Schedulers.immediate();
|
||||||
Scheduler.Worker worker = scheduler.createWorker();
|
Scheduler.Worker worker = scheduler.createWorker();
|
||||||
worker.schedule(() -> result += "action");
|
worker.schedule(() -> result += "action");
|
||||||
Assert.assertTrue(result.equals("action"));
|
|
||||||
|
assertTrue(result.equals("action"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -44,8 +46,9 @@ public class SchedulersTest {
|
|||||||
worker.unsubscribe();
|
worker.unsubscribe();
|
||||||
});
|
});
|
||||||
worker.schedule(() -> result += "Second_Action");
|
worker.schedule(() -> result += "Second_Action");
|
||||||
Thread.sleep(500);
|
|
||||||
Assert.assertTrue(result.equals("First_Action"));
|
await()
|
||||||
|
.until(() -> assertTrue(result.equals("First_Action")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore //it's not safe, not every time is running correctly
|
@Ignore //it's not safe, not every time is running correctly
|
||||||
@ -59,8 +62,9 @@ public class SchedulersTest {
|
|||||||
worker.schedule(() -> result += "_worker_");
|
worker.schedule(() -> result += "_worker_");
|
||||||
result += "_End";
|
result += "_End";
|
||||||
});
|
});
|
||||||
Thread.sleep(2000);
|
|
||||||
Assert.assertTrue(result.equals("RxNewThreadScheduler-1_Start_End_worker_"));
|
await()
|
||||||
|
.until(() -> assertTrue(result.equals("RxNewThreadScheduler-1_Start_End_worker_")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -75,9 +79,11 @@ public class SchedulersTest {
|
|||||||
.subscribe(s ->
|
.subscribe(s ->
|
||||||
result1 += Thread.currentThread().getName()
|
result1 += Thread.currentThread().getName()
|
||||||
);
|
);
|
||||||
Thread.sleep(500);
|
await()
|
||||||
Assert.assertTrue(result1.equals("RxNewThreadScheduler-1"));
|
.until(() -> {
|
||||||
Assert.assertTrue(result2.equals("RxNewThreadScheduler-2"));
|
assertTrue(result1.equals("RxNewThreadScheduler-1"));
|
||||||
|
assertTrue(result2.equals("RxNewThreadScheduler-2"));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -90,8 +96,9 @@ public class SchedulersTest {
|
|||||||
worker.schedule(() -> result += "_worker_");
|
worker.schedule(() -> result += "_worker_");
|
||||||
result += "_End";
|
result += "_End";
|
||||||
});
|
});
|
||||||
Thread.sleep(500);
|
|
||||||
Assert.assertTrue(result.equals("main_Start_worker__End"));
|
await()
|
||||||
|
.until(() -> assertTrue(result.equals("main_Start_worker__End")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -102,8 +109,9 @@ public class SchedulersTest {
|
|||||||
.subscribe(s ->
|
.subscribe(s ->
|
||||||
result += Thread.currentThread().getName()
|
result += Thread.currentThread().getName()
|
||||||
);
|
);
|
||||||
Thread.sleep(500);
|
|
||||||
Assert.assertTrue(result.equals("main"));
|
await()
|
||||||
|
.until(() -> assertTrue(result.equals("main")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -115,8 +123,9 @@ public class SchedulersTest {
|
|||||||
Observable.just(1, 3, 5, 7, 9)
|
Observable.just(1, 3, 5, 7, 9)
|
||||||
.subscribeOn(Schedulers.trampoline())
|
.subscribeOn(Schedulers.trampoline())
|
||||||
.subscribe(i -> result += "" + i);
|
.subscribe(i -> result += "" + i);
|
||||||
Thread.sleep(500);
|
|
||||||
Assert.assertTrue(result.equals("246813579"));
|
await()
|
||||||
|
.until(() -> assertTrue(result.equals("246813579")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -135,9 +144,9 @@ public class SchedulersTest {
|
|||||||
});
|
});
|
||||||
result += "_mainEnd";
|
result += "_mainEnd";
|
||||||
});
|
});
|
||||||
Thread.sleep(500);
|
|
||||||
Assert.assertTrue(result
|
await()
|
||||||
.equals("mainStart_mainEnd_middleStart_middleEnd_worker_"));
|
.until(() -> assertTrue(result.equals("mainStart_mainEnd_middleStart_middleEnd_worker_")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ThreadFactory threadFactory(String pattern) {
|
private ThreadFactory threadFactory(String pattern) {
|
||||||
@ -159,7 +168,6 @@ public class SchedulersTest {
|
|||||||
subscriber.onNext("Beta");
|
subscriber.onNext("Beta");
|
||||||
subscriber.onCompleted();
|
subscriber.onCompleted();
|
||||||
});
|
});
|
||||||
;
|
|
||||||
|
|
||||||
observable
|
observable
|
||||||
.subscribeOn(schedulerA)
|
.subscribeOn(schedulerA)
|
||||||
@ -169,8 +177,9 @@ public class SchedulersTest {
|
|||||||
Throwable::printStackTrace,
|
Throwable::printStackTrace,
|
||||||
() -> result += "_Completed"
|
() -> result += "_Completed"
|
||||||
);
|
);
|
||||||
Thread.sleep(2000);
|
|
||||||
Assert.assertTrue(result.equals("Sched-A-0Alfa_Sched-A-0Beta__Completed"));
|
await()
|
||||||
|
.until(() -> assertTrue(result.equals("Sched-A-0Alfa_Sched-A-0Beta__Completed")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -179,8 +188,9 @@ public class SchedulersTest {
|
|||||||
Observable.just("io")
|
Observable.just("io")
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.subscribe(i -> result += Thread.currentThread().getName());
|
.subscribe(i -> result += Thread.currentThread().getName());
|
||||||
Thread.sleep(500);
|
|
||||||
Assert.assertTrue(result.equals("RxIoScheduler-2"));
|
await()
|
||||||
|
.until(() -> assertTrue(result.equals("RxIoScheduler-2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -189,8 +199,9 @@ public class SchedulersTest {
|
|||||||
Observable.just("computation")
|
Observable.just("computation")
|
||||||
.subscribeOn(Schedulers.computation())
|
.subscribeOn(Schedulers.computation())
|
||||||
.subscribe(i -> result += Thread.currentThread().getName());
|
.subscribe(i -> result += Thread.currentThread().getName());
|
||||||
Thread.sleep(500);
|
|
||||||
Assert.assertTrue(result.equals("RxComputationScheduler-1"));
|
await()
|
||||||
|
.until(() -> assertTrue(result.equals("RxComputationScheduler-1")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -229,7 +240,7 @@ public class SchedulersTest {
|
|||||||
.delay(1, TimeUnit.SECONDS, schedulerA)
|
.delay(1, TimeUnit.SECONDS, schedulerA)
|
||||||
.subscribe(i -> result += Thread.currentThread().getName() + i + " ");
|
.subscribe(i -> result += Thread.currentThread().getName() + i + " ");
|
||||||
|
|
||||||
Thread.sleep(2000);
|
await()
|
||||||
Assert.assertTrue(result.equals("Sched1-A Sched1-B "));
|
.until(() -> assertTrue(result.equals("Sched1-A Sched1-B ")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import rx.schedulers.Timestamped;
|
|||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.jayway.awaitility.Awaitility.await;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class UtilityOperatorsTest {
|
public class UtilityOperatorsTest {
|
||||||
@ -40,9 +41,11 @@ public class UtilityOperatorsTest {
|
|||||||
+ Thread.currentThread().getName());
|
+ Thread.currentThread().getName());
|
||||||
});
|
});
|
||||||
|
|
||||||
Thread.sleep(2000);
|
await().until(() -> {
|
||||||
assertTrue(emittedTotal == 1500);
|
assertTrue(emittedTotal == 1500);
|
||||||
assertTrue(receivedTotal == 15000);
|
assertTrue(receivedTotal == 15000);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -63,9 +66,10 @@ public class UtilityOperatorsTest {
|
|||||||
+ Thread.currentThread().getName());
|
+ Thread.currentThread().getName());
|
||||||
});
|
});
|
||||||
|
|
||||||
Thread.sleep(2000);
|
await().until(() -> {
|
||||||
assertTrue(emittedTotal == 1500);
|
assertTrue(emittedTotal == 1500);
|
||||||
assertTrue(receivedTotal == 15000);
|
assertTrue(receivedTotal == 15000);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -86,9 +90,10 @@ public class UtilityOperatorsTest {
|
|||||||
+ Thread.currentThread().getName());
|
+ Thread.currentThread().getName());
|
||||||
});
|
});
|
||||||
|
|
||||||
Thread.sleep(2000);
|
await().until(() -> {
|
||||||
assertTrue(emittedTotal == 1500);
|
assertTrue(emittedTotal == 1500);
|
||||||
assertTrue(receivedTotal == 15000);
|
assertTrue(receivedTotal == 15000);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -210,7 +215,7 @@ public class UtilityOperatorsTest {
|
|||||||
value -> System.out.println("delay : " + value),
|
value -> System.out.println("delay : " + value),
|
||||||
t -> System.out.println("delay error"),
|
t -> System.out.println("delay error"),
|
||||||
() -> System.out.println("delay completed"));
|
() -> System.out.println("delay completed"));
|
||||||
Thread.sleep(8000);
|
//Thread.sleep(8000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user