Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
+3
-1
@@ -24,7 +24,9 @@
|
||||
- [Locality-Sensitive Hashing in Java Using Java-LSH](http://www.baeldung.com/locality-sensitive-hashing)
|
||||
- [Apache Commons Collections OrderedMap](http://www.baeldung.com/apache-commons-ordered-map)
|
||||
- [A Guide to Apache Commons DbUtils](http://www.baeldung.com/apache-commons-dbutils)
|
||||
|
||||
- [Introduction to Awaitility](http://www.baeldung.com/awaitlity-testing)
|
||||
- [Guide to the HyperLogLog Algorithm](http://www.baeldung.com/java-hyperloglog)
|
||||
- [Introduction to Neuroph](http://www.baeldung.com/intro-to-neuroph)
|
||||
|
||||
The libraries module contains examples related to small libraries that are relatively easy to use and does not require any separate module of its own.
|
||||
|
||||
|
||||
+47
-169
@@ -7,7 +7,6 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>libraries</artifactId>
|
||||
<name>libraries</name>
|
||||
<build>
|
||||
@@ -71,79 +70,51 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Vaadin -->
|
||||
<!-- Neuroph -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
<packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
|
||||
<excludes>
|
||||
<exclude>**/log4j.properties</exclude>
|
||||
</excludes>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.baeldung.neuroph.NeurophXOR</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.vaadin</groupId>
|
||||
<artifactId>vaadin-maven-plugin</artifactId>
|
||||
<version>${vaadin.plugin.version}</version>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.18.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>test</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>update-theme</goal>
|
||||
<goal>update-widgetset</goal>
|
||||
<goal>compile</goal>
|
||||
<goal>compile-theme</goal>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>test/java/com/baeldung/neuroph/XORTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<filesets>
|
||||
<fileset>
|
||||
<directory>src/main/webapp/VAADIN/themes</directory>
|
||||
<includes>
|
||||
<include>**/styles.css</include>
|
||||
<include>**/styles.scss.cache</include>
|
||||
</includes>
|
||||
</fileset>
|
||||
</filesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>2</scanIntervalSeconds>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- /Vaadin -->
|
||||
<!-- /Neuroph -->
|
||||
</plugins>
|
||||
</build>
|
||||
<!-- Vaadin -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>vaadin-addons</id>
|
||||
<url>http://maven.vaadin.com/vaadin-addons</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.vaadin</groupId>
|
||||
<artifactId>vaadin-bom</artifactId>
|
||||
<version>${vaadin.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<!-- /Vaadin -->
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.beykery/neuroph/2.92 -->
|
||||
<dependency>
|
||||
<groupId>org.beykery</groupId>
|
||||
<artifactId>neuroph</artifactId>
|
||||
<version>${neuroph.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
@@ -227,11 +198,16 @@
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons.io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-chain</groupId>
|
||||
<artifactId>commons-chain</artifactId>
|
||||
<version>${commons-chain.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbutils</groupId>
|
||||
<artifactId>commons-dbutils</artifactId>
|
||||
<version>${commons.dbutils.version}</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.flink</groupId>
|
||||
<artifactId>flink-core</artifactId>
|
||||
@@ -392,7 +368,6 @@
|
||||
<artifactId>quartz</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>one.util</groupId>
|
||||
<artifactId>streamex</artifactId>
|
||||
@@ -458,68 +433,6 @@
|
||||
<version>${org.hamcrest.java-hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Vaadin -->
|
||||
<dependency>
|
||||
<groupId>com.vaadin</groupId>
|
||||
<artifactId>vaadin-server</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vaadin</groupId>
|
||||
<artifactId>vaadin-client-compiled</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vaadin</groupId>
|
||||
<artifactId>vaadin-themes</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>3.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>htmlunit-driver</artifactId>
|
||||
<version>2.27</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-server</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-client</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-api</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-common</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-continuation</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-api</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<scope>test</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<!-- /Vaadin -->
|
||||
<dependency>
|
||||
<groupId>net.agkn</groupId>
|
||||
<artifactId>hll</artifactId>
|
||||
@@ -535,6 +448,16 @@
|
||||
<artifactId>byte-buddy-agent</artifactId>
|
||||
<version>${bytebuddy.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
<version>${bytebuddy.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy-agent</artifactId>
|
||||
<version>${bytebuddy.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<multiverse.version>0.7.0</multiverse.version>
|
||||
@@ -542,6 +465,7 @@
|
||||
<commons-lang.version>3.5</commons-lang.version>
|
||||
<commons-text.version>1.1</commons-text.version>
|
||||
<commons-beanutils.version>1.9.3</commons-beanutils.version>
|
||||
<commons-chain.version>1.2</commons-chain.version>
|
||||
<jasypt.version>1.9.2</jasypt.version>
|
||||
<javatuples.version>1.2</javatuples.version>
|
||||
<javaassist.version>3.21.0-GA</javaassist.version>
|
||||
@@ -558,6 +482,7 @@
|
||||
<commons.io.version>2.5</commons.io.version>
|
||||
<flink.version>1.2.0</flink.version>
|
||||
<jackson.version>2.8.5</jackson.version>
|
||||
<neuroph.version>2.92</neuroph.version>
|
||||
<serenity.version>1.4.0</serenity.version>
|
||||
<serenity.jbehave.version>1.24.0</serenity.jbehave.version>
|
||||
<serenity.jira.version>1.1.3-rc.5</serenity.jira.version>
|
||||
@@ -570,54 +495,7 @@
|
||||
<pact.version>3.5.0</pact.version>
|
||||
<awaitility.version>3.0.0</awaitility.version>
|
||||
<org.hamcrest.java-hamcrest.version>2.0.0.0</org.hamcrest.java-hamcrest.version>
|
||||
<!-- Vaadin -->
|
||||
<vaadin.version>7.7.10</vaadin.version>
|
||||
<vaadin.plugin.version>8.0.6</vaadin.plugin.version>
|
||||
<vaadin.theme>mytheme</vaadin.theme>
|
||||
<!-- /Vaadin -->
|
||||
<hll.version>1.6.0</hll.version>
|
||||
<bytebuddy.version>1.7.1</bytebuddy.version>
|
||||
</properties>
|
||||
<profiles>
|
||||
<!-- Vaadin -->
|
||||
<profile>
|
||||
<id>vaadin-prerelease</id>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>vaadin-prereleases</id>
|
||||
<url>http://maven.vaadin.com/vaadin-prereleases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vaadin-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>vaadin-prereleases</id>
|
||||
<url>http://maven.vaadin.com/vaadin-prereleases</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>vaadin-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</profile>
|
||||
<!-- Vaadin -->
|
||||
</profiles>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.commons.chain;
|
||||
|
||||
import org.apache.commons.chain.Command;
|
||||
import org.apache.commons.chain.Context;
|
||||
|
||||
import static com.baeldung.commons.chain.AtmConstants.AMOUNT_LEFT_TO_BE_WITHDRAWN;
|
||||
|
||||
public abstract class AbstractDenominationDispenser implements Command {
|
||||
|
||||
@Override
|
||||
public boolean execute(Context context) throws Exception {
|
||||
int amountLeftToBeWithdrawn = (int) context.get(AMOUNT_LEFT_TO_BE_WITHDRAWN);
|
||||
if (amountLeftToBeWithdrawn >= getDenominationValue()) {
|
||||
context.put(getDenominationString(), amountLeftToBeWithdrawn / getDenominationValue());
|
||||
context.put(AMOUNT_LEFT_TO_BE_WITHDRAWN, amountLeftToBeWithdrawn % getDenominationValue());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract String getDenominationString();
|
||||
|
||||
protected abstract int getDenominationValue();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.commons.chain;
|
||||
|
||||
import org.apache.commons.chain.impl.CatalogBase;
|
||||
|
||||
import static com.baeldung.commons.chain.AtmConstants.ATM_WITHDRAWAL_CHAIN;
|
||||
|
||||
public class AtmCatalog extends CatalogBase {
|
||||
|
||||
public AtmCatalog() {
|
||||
super();
|
||||
addCommand(ATM_WITHDRAWAL_CHAIN, new AtmWithdrawalChain());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.baeldung.commons.chain;
|
||||
|
||||
public class AtmConstants {
|
||||
public static final String TOTAL_AMOUNT_TO_BE_WITHDRAWN = "totalAmountToBeWithdrawn";
|
||||
public static final String AMOUNT_LEFT_TO_BE_WITHDRAWN = "amountLeftToBeWithdrawn";
|
||||
public static final String NO_OF_HUNDREDS_DISPENSED = "noOfHundredsDispensed";
|
||||
public static final String NO_OF_FIFTIES_DISPENSED = "noOfFiftiesDispensed";
|
||||
public static final String NO_OF_TENS_DISPENSED = "noOfTensDispensed";
|
||||
public static final String ATM_WITHDRAWAL_CHAIN = "atmWithdrawalChain";
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.baeldung.commons.chain;
|
||||
|
||||
import org.apache.commons.chain.impl.ContextBase;
|
||||
|
||||
public class AtmRequestContext extends ContextBase {
|
||||
|
||||
int totalAmountToBeWithdrawn;
|
||||
int noOfHundredsDispensed;
|
||||
int noOfFiftiesDispensed;
|
||||
int noOfTensDispensed;
|
||||
int amountLeftToBeWithdrawn;
|
||||
|
||||
public int getTotalAmountToBeWithdrawn() {
|
||||
return totalAmountToBeWithdrawn;
|
||||
}
|
||||
|
||||
public void setTotalAmountToBeWithdrawn(int totalAmountToBeWithdrawn) {
|
||||
this.totalAmountToBeWithdrawn = totalAmountToBeWithdrawn;
|
||||
}
|
||||
|
||||
public int getNoOfHundredsDispensed() {
|
||||
return noOfHundredsDispensed;
|
||||
}
|
||||
|
||||
public void setNoOfHundredsDispensed(int noOfHundredsDispensed) {
|
||||
this.noOfHundredsDispensed = noOfHundredsDispensed;
|
||||
}
|
||||
|
||||
public int getNoOfFiftiesDispensed() {
|
||||
return noOfFiftiesDispensed;
|
||||
}
|
||||
|
||||
public void setNoOfFiftiesDispensed(int noOfFiftiesDispensed) {
|
||||
this.noOfFiftiesDispensed = noOfFiftiesDispensed;
|
||||
}
|
||||
|
||||
public int getNoOfTensDispensed() {
|
||||
return noOfTensDispensed;
|
||||
}
|
||||
|
||||
public void setNoOfTensDispensed(int noOfTensDispensed) {
|
||||
this.noOfTensDispensed = noOfTensDispensed;
|
||||
}
|
||||
|
||||
public int getAmountLeftToBeWithdrawn() {
|
||||
return amountLeftToBeWithdrawn;
|
||||
}
|
||||
|
||||
public void setAmountLeftToBeWithdrawn(int amountLeftToBeWithdrawn) {
|
||||
this.amountLeftToBeWithdrawn = amountLeftToBeWithdrawn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.commons.chain;
|
||||
|
||||
import org.apache.commons.chain.impl.ChainBase;
|
||||
|
||||
public class AtmWithdrawalChain extends ChainBase {
|
||||
|
||||
public AtmWithdrawalChain() {
|
||||
super();
|
||||
addCommand(new HundredDenominationDispenser());
|
||||
addCommand(new FiftyDenominationDispenser());
|
||||
addCommand(new TenDenominationDispenser());
|
||||
addCommand(new AuditFilter());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.commons.chain;
|
||||
|
||||
import org.apache.commons.chain.Context;
|
||||
import org.apache.commons.chain.Filter;
|
||||
|
||||
public class AuditFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public boolean postprocess(Context context, Exception exception) {
|
||||
// Send notification to customer & bank.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Context context) throws Exception {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.commons.chain;
|
||||
|
||||
import static com.baeldung.commons.chain.AtmConstants.NO_OF_FIFTIES_DISPENSED;
|
||||
|
||||
public class FiftyDenominationDispenser extends AbstractDenominationDispenser {
|
||||
@Override
|
||||
protected String getDenominationString() {
|
||||
return NO_OF_FIFTIES_DISPENSED;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDenominationValue() {
|
||||
return 50;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.commons.chain;
|
||||
|
||||
import static com.baeldung.commons.chain.AtmConstants.NO_OF_HUNDREDS_DISPENSED;
|
||||
|
||||
public class HundredDenominationDispenser extends AbstractDenominationDispenser {
|
||||
@Override
|
||||
protected String getDenominationString() {
|
||||
return NO_OF_HUNDREDS_DISPENSED;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDenominationValue() {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.commons.chain;
|
||||
|
||||
import static com.baeldung.commons.chain.AtmConstants.NO_OF_TENS_DISPENSED;
|
||||
|
||||
public class TenDenominationDispenser extends AbstractDenominationDispenser {
|
||||
@Override
|
||||
protected String getDenominationString() {
|
||||
return NO_OF_TENS_DISPENSED;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDenominationValue() {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.baeldung.neuroph;
|
||||
|
||||
import org.neuroph.core.Layer;
|
||||
import org.neuroph.core.NeuralNetwork;
|
||||
import org.neuroph.core.Neuron;
|
||||
import org.neuroph.core.data.DataSet;
|
||||
import org.neuroph.core.data.DataSetRow;
|
||||
import org.neuroph.nnet.learning.BackPropagation;
|
||||
import org.neuroph.util.ConnectionFactory;
|
||||
import org.neuroph.util.NeuralNetworkType;
|
||||
|
||||
public class NeurophXOR {
|
||||
|
||||
public static NeuralNetwork assembleNeuralNetwork() {
|
||||
|
||||
Layer inputLayer = new Layer();
|
||||
inputLayer.addNeuron(new Neuron());
|
||||
inputLayer.addNeuron(new Neuron());
|
||||
|
||||
Layer hiddenLayerOne = new Layer();
|
||||
hiddenLayerOne.addNeuron(new Neuron());
|
||||
hiddenLayerOne.addNeuron(new Neuron());
|
||||
hiddenLayerOne.addNeuron(new Neuron());
|
||||
hiddenLayerOne.addNeuron(new Neuron());
|
||||
|
||||
Layer hiddenLayerTwo = new Layer();
|
||||
hiddenLayerTwo.addNeuron(new Neuron());
|
||||
hiddenLayerTwo.addNeuron(new Neuron());
|
||||
hiddenLayerTwo.addNeuron(new Neuron());
|
||||
hiddenLayerTwo.addNeuron(new Neuron());
|
||||
|
||||
Layer outputLayer = new Layer();
|
||||
outputLayer.addNeuron(new Neuron());
|
||||
|
||||
NeuralNetwork ann = new NeuralNetwork();
|
||||
|
||||
ann.addLayer(0, inputLayer);
|
||||
ann.addLayer(1, hiddenLayerOne);
|
||||
ConnectionFactory.fullConnect(ann.getLayerAt(0), ann.getLayerAt(1));
|
||||
ann.addLayer(2, hiddenLayerTwo);
|
||||
ConnectionFactory.fullConnect(ann.getLayerAt(1), ann.getLayerAt(2));
|
||||
ann.addLayer(3, outputLayer);
|
||||
ConnectionFactory.fullConnect(ann.getLayerAt(2), ann.getLayerAt(3));
|
||||
ConnectionFactory.fullConnect(ann.getLayerAt(0), ann.getLayerAt(ann.getLayersCount()-1), false);
|
||||
|
||||
ann.setInputNeurons(inputLayer.getNeurons());
|
||||
ann.setOutputNeurons(outputLayer.getNeurons());
|
||||
|
||||
ann.setNetworkType(NeuralNetworkType.MULTI_LAYER_PERCEPTRON);
|
||||
return ann;
|
||||
}
|
||||
|
||||
public static NeuralNetwork trainNeuralNetwork(NeuralNetwork ann) {
|
||||
int inputSize = 2;
|
||||
int outputSize = 1;
|
||||
DataSet ds = new DataSet(inputSize, outputSize);
|
||||
|
||||
DataSetRow rOne = new DataSetRow(new double[] {0, 1}, new double[] {1});
|
||||
ds.addRow(rOne);
|
||||
DataSetRow rTwo = new DataSetRow(new double[] {1, 1}, new double[] {0});
|
||||
ds.addRow(rTwo);
|
||||
DataSetRow rThree = new DataSetRow(new double[] {0, 0}, new double[] {0});
|
||||
ds.addRow(rThree);
|
||||
DataSetRow rFour = new DataSetRow(new double[] {1, 0}, new double[] {1});
|
||||
ds.addRow(rFour);
|
||||
|
||||
BackPropagation backPropagation = new BackPropagation();
|
||||
backPropagation.setMaxIterations(1000);
|
||||
|
||||
ann.learn(ds, backPropagation);
|
||||
return ann;
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
package com.baeldung.vaadin;
|
||||
|
||||
import com.vaadin.annotations.Theme;
|
||||
import com.vaadin.annotations.VaadinServletConfiguration;
|
||||
import com.vaadin.server.ExternalResource;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.server.VaadinRequest;
|
||||
import com.vaadin.server.VaadinServlet;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.CheckBox;
|
||||
import com.vaadin.ui.ComboBox;
|
||||
import com.vaadin.ui.DateField;
|
||||
import com.vaadin.ui.FormLayout;
|
||||
import com.vaadin.ui.Grid;
|
||||
import com.vaadin.ui.GridLayout;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.InlineDateField;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Link;
|
||||
import com.vaadin.ui.ListSelect;
|
||||
import com.vaadin.ui.NativeButton;
|
||||
import com.vaadin.ui.NativeSelect;
|
||||
import com.vaadin.ui.Panel;
|
||||
import com.vaadin.ui.PasswordField;
|
||||
import com.vaadin.ui.RichTextArea;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.TwinColSelect;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Theme("mytheme")
|
||||
public class VaadinUI extends UI {
|
||||
|
||||
@Override
|
||||
protected void init(VaadinRequest vaadinRequest) {
|
||||
final VerticalLayout verticalLayout = new VerticalLayout();
|
||||
verticalLayout.setSpacing(true);
|
||||
verticalLayout.setMargin(true);
|
||||
final GridLayout gridLayout = new GridLayout(3, 2);
|
||||
gridLayout.setSpacing(true);
|
||||
gridLayout.setMargin(true);
|
||||
final HorizontalLayout horizontalLayout = new HorizontalLayout();
|
||||
horizontalLayout.setSpacing(true);
|
||||
horizontalLayout.setMargin(true);
|
||||
final FormLayout formLayout = new FormLayout();
|
||||
formLayout.setSpacing(true);
|
||||
formLayout.setMargin(true);
|
||||
final GridLayout buttonLayout = new GridLayout(3, 5);
|
||||
buttonLayout.setMargin(true);
|
||||
buttonLayout.setSpacing(true);
|
||||
|
||||
final Label label = new Label();
|
||||
label.setId("Label");
|
||||
label.setValue("Label Value");
|
||||
label.setCaption("Label");
|
||||
gridLayout.addComponent(label);
|
||||
|
||||
final Link link = new Link("Baeldung",
|
||||
new ExternalResource("http://www.baeldung.com/"));
|
||||
link.setId("Link");
|
||||
link.setTargetName("_blank");
|
||||
gridLayout.addComponent(link);
|
||||
|
||||
final TextField textField = new TextField();
|
||||
textField.setId("TextField");
|
||||
textField.setCaption("TextField:");
|
||||
textField.setValue("TextField Value");
|
||||
textField.setIcon(FontAwesome.USER);
|
||||
gridLayout.addComponent(textField);
|
||||
|
||||
final TextArea textArea = new TextArea();
|
||||
textArea.setCaption("TextArea");
|
||||
textArea.setId("TextArea");
|
||||
textArea.setValue("TextArea Value");
|
||||
gridLayout.addComponent(textArea);
|
||||
|
||||
final DateField dateField = new DateField("DateField", new Date(0));
|
||||
dateField.setId("DateField");
|
||||
gridLayout.addComponent(dateField);
|
||||
|
||||
final PasswordField passwordField = new PasswordField();
|
||||
passwordField.setId("PasswordField");
|
||||
passwordField.setCaption("PasswordField:");
|
||||
passwordField.setValue("password");
|
||||
gridLayout.addComponent(passwordField);
|
||||
|
||||
final RichTextArea richTextArea = new RichTextArea();
|
||||
richTextArea.setCaption("Rich Text Area");
|
||||
richTextArea.setValue("<h1>RichTextArea</h1>");
|
||||
richTextArea.setSizeFull();
|
||||
|
||||
Panel richTextPanel = new Panel();
|
||||
richTextPanel.setContent(richTextArea);
|
||||
|
||||
final InlineDateField inlineDateField = new InlineDateField();
|
||||
inlineDateField.setValue(new Date(0));
|
||||
inlineDateField.setCaption("Inline Date Field");
|
||||
horizontalLayout.addComponent(inlineDateField);
|
||||
|
||||
Button normalButton = new Button("Normal Button");
|
||||
normalButton.setId("NormalButton");
|
||||
normalButton.addClickListener(e -> {
|
||||
label.setValue("CLICK");
|
||||
});
|
||||
buttonLayout.addComponent(normalButton);
|
||||
|
||||
Button tinyButton = new Button("Tiny Button");
|
||||
tinyButton.addStyleName("tiny");
|
||||
buttonLayout.addComponent(tinyButton);
|
||||
|
||||
Button smallButton = new Button("Small Button");
|
||||
smallButton.addStyleName("small");
|
||||
buttonLayout.addComponent(smallButton);
|
||||
|
||||
|
||||
Button largeButton = new Button("Large Button");
|
||||
largeButton.addStyleName("large");
|
||||
buttonLayout.addComponent(largeButton);
|
||||
|
||||
|
||||
Button hugeButton = new Button("Huge Button");
|
||||
hugeButton.addStyleName("huge");
|
||||
buttonLayout.addComponent(hugeButton);
|
||||
|
||||
|
||||
Button disabledButton = new Button("Disabled Button");
|
||||
disabledButton.setDescription("This button cannot be clicked");
|
||||
disabledButton.setEnabled(false);
|
||||
buttonLayout.addComponent(disabledButton);
|
||||
|
||||
|
||||
Button dangerButton = new Button("Danger Button");
|
||||
dangerButton.addStyleName("danger");
|
||||
buttonLayout.addComponent(dangerButton);
|
||||
|
||||
|
||||
Button friendlyButton = new Button("Friendly Button");
|
||||
friendlyButton.addStyleName("friendly");
|
||||
buttonLayout.addComponent(friendlyButton);
|
||||
|
||||
Button primaryButton = new Button("Primary Button");
|
||||
primaryButton.addStyleName("primary");
|
||||
buttonLayout.addComponent(primaryButton);
|
||||
|
||||
NativeButton nativeButton = new NativeButton("Native Button");
|
||||
buttonLayout.addComponent(nativeButton);
|
||||
|
||||
Button iconButton = new Button("Icon Button");
|
||||
iconButton.setIcon(FontAwesome.ALIGN_LEFT);
|
||||
buttonLayout.addComponent(iconButton);
|
||||
|
||||
Button borderlessButton = new Button("BorderLess Button");
|
||||
borderlessButton.addStyleName("borderless");
|
||||
buttonLayout.addComponent(borderlessButton);
|
||||
|
||||
Button linkButton = new Button("Link Button");
|
||||
linkButton.addStyleName("link");
|
||||
buttonLayout.addComponent(linkButton);
|
||||
|
||||
Button quietButton = new Button("Quiet Button");
|
||||
quietButton.addStyleName("quiet");
|
||||
buttonLayout.addComponent(quietButton);
|
||||
|
||||
horizontalLayout.addComponent(buttonLayout);
|
||||
|
||||
final CheckBox checkbox = new CheckBox("CheckBox");
|
||||
checkbox.setValue(true);
|
||||
checkbox.addValueChangeListener(e ->
|
||||
checkbox.setValue(!checkbox.getValue()));
|
||||
formLayout.addComponent(checkbox);
|
||||
|
||||
List<String> numbers = new ArrayList<String>();
|
||||
numbers.add("One");
|
||||
numbers.add("Ten");
|
||||
numbers.add("Eleven");
|
||||
ComboBox comboBox = new ComboBox("ComboBox");
|
||||
comboBox.addItems(numbers);
|
||||
formLayout.addComponent(comboBox);
|
||||
|
||||
ListSelect listSelect = new ListSelect("ListSelect");
|
||||
listSelect.addItems(numbers);
|
||||
listSelect.setRows(2);
|
||||
formLayout.addComponent(listSelect);
|
||||
|
||||
NativeSelect nativeSelect = new NativeSelect("NativeSelect");
|
||||
nativeSelect.addItems(numbers);
|
||||
formLayout.addComponent(nativeSelect);
|
||||
|
||||
TwinColSelect twinColSelect = new TwinColSelect("TwinColSelect");
|
||||
twinColSelect.addItems(numbers);
|
||||
|
||||
Grid grid = new Grid("Grid");
|
||||
grid.setColumns("Column1", "Column2", "Column3");
|
||||
grid.addRow("Item1", "Item2", "Item3");
|
||||
grid.addRow("Item4", "Item5", "Item6");
|
||||
|
||||
Panel panel = new Panel("Panel");
|
||||
panel.setContent(grid);
|
||||
panel.setSizeUndefined();
|
||||
|
||||
verticalLayout.addComponent(gridLayout);
|
||||
verticalLayout.addComponent(richTextPanel);
|
||||
verticalLayout.addComponent(horizontalLayout);
|
||||
verticalLayout.addComponent(formLayout);
|
||||
verticalLayout.addComponent(twinColSelect);
|
||||
verticalLayout.addComponent(panel);
|
||||
setContent(verticalLayout);
|
||||
}
|
||||
|
||||
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
|
||||
@VaadinServletConfiguration(ui = VaadinUI.class, productionMode = false)
|
||||
public static class MyUIServlet extends VaadinServlet {
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
/* This file is automatically managed and will be overwritten from time to time. */
|
||||
/* Do not manually edit this file. */
|
||||
|
||||
/* Import and include this mixin into your project theme to include the addon themes */
|
||||
@mixin addons {
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 30 KiB |
@@ -1,38 +0,0 @@
|
||||
// If you edit this file you need to compile the theme. See README.md for details.
|
||||
|
||||
// Global variable overrides. Must be declared before importing Valo.
|
||||
|
||||
// Defines the plaintext font size, weight and family. Font size affects general component sizing.
|
||||
//$v-font-size: 16px;
|
||||
//$v-font-weight: 300;
|
||||
//$v-font-family: "Open Sans", sans-serif;
|
||||
|
||||
// Defines the border used by all components.
|
||||
//$v-border: 1px solid (v-shade 0.7);
|
||||
//$v-border-radius: 4px;
|
||||
|
||||
// Affects the color of some component elements, e.g Button, Panel title, etc
|
||||
//$v-background-color: hsl(210, 0%, 98%);
|
||||
// Affects the color of content areas, e.g Panel and Window content, TextField input etc
|
||||
//$v-app-background-color: $v-background-color;
|
||||
|
||||
// Affects the visual appearance of all components
|
||||
//$v-gradient: v-linear 8%;
|
||||
//$v-bevel-depth: 30%;
|
||||
//$v-shadow-opacity: 5%;
|
||||
|
||||
// Defines colors for indicating status (focus, success, failure)
|
||||
//$v-focus-color: valo-focus-color(); // Calculates a suitable color automatically
|
||||
//$v-friendly-color: #2c9720;
|
||||
//$v-error-indicator-color: #ed473b;
|
||||
|
||||
// For more information, see: https://vaadin.com/book/-/page/themes.valo.html
|
||||
// Example variants can be copy/pasted from https://vaadin.com/wiki/-/wiki/Main/Valo+Examples
|
||||
|
||||
@import "../valo/valo.scss";
|
||||
|
||||
@mixin mytheme {
|
||||
@include valo;
|
||||
|
||||
// Insert your own theme rules here
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +0,0 @@
|
||||
@import "mytheme.scss";
|
||||
@import "addons.scss";
|
||||
|
||||
// This file prefixes all rules with the theme name to avoid causing conflicts with other themes.
|
||||
// The actual styles should be defined in mytheme.scss
|
||||
|
||||
.mytheme {
|
||||
@include addons;
|
||||
@include mytheme;
|
||||
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
/* This file is automatically managed and will be overwritten from time to time. */
|
||||
/* Do not manually edit this file. */
|
||||
|
||||
/* Import and include this mixin into your project theme to include the addon themes */
|
||||
@mixin addons {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.commons.chain;
|
||||
|
||||
import org.apache.commons.chain.Catalog;
|
||||
import org.apache.commons.chain.Command;
|
||||
import org.apache.commons.chain.Context;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.baeldung.commons.chain.AtmConstants.*;
|
||||
|
||||
public class AtmChainTest {
|
||||
|
||||
public static final int EXPECTED_TOTAL_AMOUNT_TO_BE_WITHDRAWN = 460;
|
||||
public static final int EXPECTED_AMOUNT_LEFT_TO_BE_WITHDRAWN = 0;
|
||||
public static final int EXPECTED_NO_OF_HUNDREDS_DISPENSED = 4;
|
||||
public static final int EXPECTED_NO_OF_FIFTIES_DISPENSED = 1;
|
||||
public static final int EXPECTED_NO_OF_TENS_DISPENSED = 1;
|
||||
|
||||
@Test
|
||||
public void givenInputsToContext_whenAppliedChain_thenExpectedContext() {
|
||||
Context context = new AtmRequestContext();
|
||||
context.put(TOTAL_AMOUNT_TO_BE_WITHDRAWN, 460);
|
||||
context.put(AMOUNT_LEFT_TO_BE_WITHDRAWN, 460);
|
||||
Catalog catalog = new AtmCatalog();
|
||||
Command atmWithdrawalChain = catalog.getCommand(ATM_WITHDRAWAL_CHAIN);
|
||||
try {
|
||||
atmWithdrawalChain.execute(context);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertEquals(EXPECTED_TOTAL_AMOUNT_TO_BE_WITHDRAWN, (int) context.get(TOTAL_AMOUNT_TO_BE_WITHDRAWN));
|
||||
Assert.assertEquals(EXPECTED_AMOUNT_LEFT_TO_BE_WITHDRAWN, (int) context.get(AMOUNT_LEFT_TO_BE_WITHDRAWN));
|
||||
Assert.assertEquals(EXPECTED_NO_OF_HUNDREDS_DISPENSED, (int) context.get(NO_OF_HUNDREDS_DISPENSED));
|
||||
Assert.assertEquals(EXPECTED_NO_OF_FIFTIES_DISPENSED, (int) context.get(NO_OF_FIFTIES_DISPENSED));
|
||||
Assert.assertEquals(EXPECTED_NO_OF_TENS_DISPENSED, (int) context.get(NO_OF_TENS_DISPENSED));
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,19 @@ import org.apache.commons.collections4.MapIterator;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.collections4.PredicateUtils;
|
||||
import org.apache.commons.collections4.TransformerUtils;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.collection.IsMapContaining.hasEntry;
|
||||
import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
|
||||
@@ -63,19 +68,7 @@ public class MapUtilsTest {
|
||||
|
||||
@Test
|
||||
public void whenVerbosePrintMap_thenMustPrintFormattedMap() {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
PrintStream outPrint = new PrintStream(out);
|
||||
|
||||
outPrint.println("Optional Label = ");
|
||||
outPrint.println("{");
|
||||
outPrint.println(" RED = #FF0000");
|
||||
outPrint.println(" BLUE = #0000FF");
|
||||
outPrint.println(" GREEN = #00FF00");
|
||||
outPrint.println("}");
|
||||
|
||||
out.reset();
|
||||
|
||||
MapUtils.verbosePrint(outPrint, "Optional Label", this.colorMap);
|
||||
MapUtils.verbosePrint(System.out, "Optional Label", this.colorMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,19 +90,12 @@ public class MapUtilsTest {
|
||||
@Test
|
||||
public void whenInvertMap_thenMustReturnInvertedMap() {
|
||||
Map<String, String> invColorMap = MapUtils.invertMap(this.colorMap);
|
||||
assertEquals(this.colorMap.size(), invColorMap.size());
|
||||
|
||||
MapIterator<String, String> itColorMap
|
||||
= MapUtils.iterableMap(this.colorMap).mapIterator();
|
||||
|
||||
while (itColorMap.hasNext()) {
|
||||
String colorMapKey = itColorMap.next();
|
||||
String colorMapValue = itColorMap.getValue();
|
||||
|
||||
String invColorMapValue = MapUtils.getString(invColorMap, colorMapValue);
|
||||
|
||||
assertTrue(invColorMapValue.equals(colorMapKey));
|
||||
}
|
||||
int size = invColorMap.size();
|
||||
Assertions.assertThat(invColorMap)
|
||||
.hasSameSizeAs(colorMap)
|
||||
.containsKeys(this.colorMap.values().toArray(new String[size]))
|
||||
.containsValues(this.colorMap.keySet().toArray(new String[size]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
||||
@@ -4,6 +4,7 @@ package com.baeldung.hll;
|
||||
import com.google.common.hash.HashFunction;
|
||||
import com.google.common.hash.Hashing;
|
||||
import net.agkn.hll.HLL;
|
||||
import org.assertj.core.data.Offset;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.stream.LongStream;
|
||||
@@ -15,8 +16,8 @@ public class HLLUnitTest {
|
||||
@Test
|
||||
public void givenHLL_whenAddHugeAmountOfNumbers_thenShouldReturnEstimatedCardinality() {
|
||||
//given
|
||||
int numberOfElements = 100_000_000;
|
||||
int toleratedDifference = 1_000_000;
|
||||
long numberOfElements = 100_000_000;
|
||||
long toleratedDifference = 1_000_000;
|
||||
HashFunction hashFunction = Hashing.murmur3_128();
|
||||
HLL hll = new HLL(14, 5);
|
||||
|
||||
@@ -29,14 +30,14 @@ public class HLLUnitTest {
|
||||
|
||||
//then
|
||||
long cardinality = hll.cardinality();
|
||||
assertThat(isSimilarTo(cardinality, numberOfElements, toleratedDifference)).isTrue();
|
||||
assertThat(cardinality).isCloseTo(numberOfElements, Offset.offset(toleratedDifference));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoHLLs_whenAddHugeAmountOfNumbers_thenShouldReturnEstimatedCardinalityForUnionOfHLLs() {
|
||||
//given
|
||||
int numberOfElements = 100_000_000;
|
||||
int toleratedDifference = 1_000_000;
|
||||
long numberOfElements = 100_000_000;
|
||||
long toleratedDifference = 1_000_000;
|
||||
HashFunction hashFunction = Hashing.murmur3_128();
|
||||
HLL firstHll = new HLL(15, 5);
|
||||
HLL secondHLL = new HLL(15, 5);
|
||||
@@ -57,12 +58,6 @@ public class HLLUnitTest {
|
||||
//then
|
||||
firstHll.union(secondHLL);
|
||||
long cardinality = firstHll.cardinality();
|
||||
assertThat(isSimilarTo(cardinality, numberOfElements * 2,
|
||||
toleratedDifference * 2)).isTrue();
|
||||
}
|
||||
|
||||
private boolean isSimilarTo(long cardinality, int numberOfElements, int maxToleratedDifference) {
|
||||
System.out.println(cardinality);
|
||||
return Math.abs(cardinality - numberOfElements) <= maxToleratedDifference;
|
||||
assertThat(cardinality).isCloseTo(numberOfElements * 2, Offset.offset(toleratedDifference * 2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.baeldung.neuroph;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.neuroph.core.NeuralNetwork;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class XORTest {
|
||||
private NeuralNetwork ann = null;
|
||||
|
||||
@Before
|
||||
public void annInit() {
|
||||
ann = NeurophXOR.trainNeuralNetwork(NeurophXOR.assembleNeuralNetwork());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leftDisjunctTest() {
|
||||
ann.setInput(0, 1);
|
||||
ann.calculate();
|
||||
assertEquals(ann.getOutput()[0], 1.0,0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rightDisjunctTest() {
|
||||
ann.setInput(1, 0);
|
||||
ann.calculate();
|
||||
assertEquals(ann.getOutput()[0], 1.0,0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bothFalseConjunctTest() {
|
||||
ann.setInput(0, 0);
|
||||
ann.calculate();
|
||||
assertEquals(ann.getOutput()[0], 0.0,0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bothTrueConjunctTest() {
|
||||
ann.setInput(1, 1);
|
||||
ann.calculate();
|
||||
assertEquals(ann.getOutput()[0], 0.0,0.0);
|
||||
}
|
||||
|
||||
@After
|
||||
public void annClose() {
|
||||
ann = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user