diff --git a/.gitignore b/.gitignore
index f3d6549..5a70402 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,8 @@
-/build/
\ No newline at end of file
+/build/
+
+*.lock
+*.bin
+*.xml
+*.properties
+*.bat
+*.jar
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..1318ed3
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,37 @@
+plugins {
+ id 'java'
+}
+
+group 'com.javaquery'
+version '1.0-SNAPSHOT'
+
+repositories {
+ mavenCentral()
+ maven {
+ url 'http://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/'
+ }
+}
+
+dependencies {
+ // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
+ compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.0'
+ // https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
+ compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
+
+ // https://mvnrepository.com/artifact/org.hibernate/hibernate-core
+ compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.27.Final'
+ // https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api
+ compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
+ // https://mvnrepository.com/artifact/javax.validation/validation-api
+ compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
+
+
+ // https://mvnrepository.com/artifact/com.google.firebase/firebase-server-sdk
+ compile group: 'com.google.firebase', name: 'firebase-server-sdk', version: '3.0.3'
+
+ // https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports
+ compile group: 'net.sf.jasperreports', name: 'jasperreports', version: '6.16.0'
+
+
+ runtime fileTree(dir: 'lib/JSON', include: '*.jar')
+}
diff --git a/build.xml b/build.xml
deleted file mode 100644
index a3a0ee4..0000000
--- a/build.xml
+++ /dev/null
@@ -1,73 +0,0 @@
-
-
-
-
-
-
-
-
-
-
- Builds, tests, and runs the project Examples.
-
-
-
diff --git a/lib/Apache/httpclient-4.5.1.jar b/lib/Apache/httpclient-4.5.1.jar
deleted file mode 100644
index b9c0c1c..0000000
Binary files a/lib/Apache/httpclient-4.5.1.jar and /dev/null differ
diff --git a/lib/Apache/httpcore-4.4.4.jar b/lib/Apache/httpcore-4.4.4.jar
deleted file mode 100644
index ac4a877..0000000
Binary files a/lib/Apache/httpcore-4.4.4.jar and /dev/null differ
diff --git a/lib/Firebase/firebase-server-sdk-3.0.1.jar b/lib/Firebase/firebase-server-sdk-3.0.1.jar
deleted file mode 100644
index b5c00cf..0000000
Binary files a/lib/Firebase/firebase-server-sdk-3.0.1.jar and /dev/null differ
diff --git a/lib/Google/google-api-client-1.22.0.jar b/lib/Google/google-api-client-1.22.0.jar
deleted file mode 100644
index b9c2b2d..0000000
Binary files a/lib/Google/google-api-client-1.22.0.jar and /dev/null differ
diff --git a/lib/Google/google-http-client-1.21.0.jar b/lib/Google/google-http-client-1.21.0.jar
deleted file mode 100644
index 8c67a9a..0000000
Binary files a/lib/Google/google-http-client-1.21.0.jar and /dev/null differ
diff --git a/lib/Google/google-http-client-gson-1.22.0.jar b/lib/Google/google-http-client-gson-1.22.0.jar
deleted file mode 100644
index e97065a..0000000
Binary files a/lib/Google/google-http-client-gson-1.22.0.jar and /dev/null differ
diff --git a/lib/Google/google-oauth-client-1.21.0.jar b/lib/Google/google-oauth-client-1.21.0.jar
deleted file mode 100644
index ae22049..0000000
Binary files a/lib/Google/google-oauth-client-1.21.0.jar and /dev/null differ
diff --git a/lib/Google/gson-2.1.jar b/lib/Google/gson-2.1.jar
deleted file mode 100644
index 83c5c99..0000000
Binary files a/lib/Google/gson-2.1.jar and /dev/null differ
diff --git a/lib/Hibernate/antlr-2.7.7.jar b/lib/Hibernate/antlr-2.7.7.jar
deleted file mode 100644
index 5e5f14b..0000000
Binary files a/lib/Hibernate/antlr-2.7.7.jar and /dev/null differ
diff --git a/lib/Hibernate/dom4j-1.6.1.jar b/lib/Hibernate/dom4j-1.6.1.jar
deleted file mode 100644
index c8c4dbb..0000000
Binary files a/lib/Hibernate/dom4j-1.6.1.jar and /dev/null differ
diff --git a/lib/Hibernate/hibernate-commons-annotations-5.0.1.Final - Copy.jar b/lib/Hibernate/hibernate-commons-annotations-5.0.1.Final - Copy.jar
deleted file mode 100644
index 82e425d..0000000
Binary files a/lib/Hibernate/hibernate-commons-annotations-5.0.1.Final - Copy.jar and /dev/null differ
diff --git a/lib/Hibernate/hibernate-core-5.0.5.Final.jar b/lib/Hibernate/hibernate-core-5.0.5.Final.jar
deleted file mode 100644
index 9d12116..0000000
Binary files a/lib/Hibernate/hibernate-core-5.0.5.Final.jar and /dev/null differ
diff --git a/lib/Hibernate/hibernate-jpa-2.1-api-1.0.0.Final.jar b/lib/Hibernate/hibernate-jpa-2.1-api-1.0.0.Final.jar
deleted file mode 100644
index e2f2c59..0000000
Binary files a/lib/Hibernate/hibernate-jpa-2.1-api-1.0.0.Final.jar and /dev/null differ
diff --git a/lib/Hibernate/javassist-3.18.1-GA.jar b/lib/Hibernate/javassist-3.18.1-GA.jar
deleted file mode 100644
index d5f19ac..0000000
Binary files a/lib/Hibernate/javassist-3.18.1-GA.jar and /dev/null differ
diff --git a/lib/Hibernate/jboss-logging-3.3.0.Final.jar b/lib/Hibernate/jboss-logging-3.3.0.Final.jar
deleted file mode 100644
index ea45d4d..0000000
Binary files a/lib/Hibernate/jboss-logging-3.3.0.Final.jar and /dev/null differ
diff --git a/lib/Hibernate/jta-1.1.jar b/lib/Hibernate/jta-1.1.jar
deleted file mode 100644
index 7736ec9..0000000
Binary files a/lib/Hibernate/jta-1.1.jar and /dev/null differ
diff --git a/lib/Hibernate/validation-api-2.0.1.Final.jar b/lib/Hibernate/validation-api-2.0.1.Final.jar
deleted file mode 100644
index 2368e10..0000000
Binary files a/lib/Hibernate/validation-api-2.0.1.Final.jar and /dev/null differ
diff --git a/lib/JSON/jackson-all-1.9.0.jar b/lib/JSON/jackson-all-1.9.0.jar
deleted file mode 100644
index 4998139..0000000
Binary files a/lib/JSON/jackson-all-1.9.0.jar and /dev/null differ
diff --git a/lib/JSON/java-json.jar b/lib/JSON/java-json.jar
deleted file mode 100644
index 2f211e3..0000000
Binary files a/lib/JSON/java-json.jar and /dev/null differ
diff --git a/lib/Jasper/com.lowagie.text-2.1.7.jar b/lib/Jasper/com.lowagie.text-2.1.7.jar
deleted file mode 100644
index 870adc4..0000000
Binary files a/lib/Jasper/com.lowagie.text-2.1.7.jar and /dev/null differ
diff --git a/lib/Jasper/commons-beanutils-1.8.3.jar b/lib/Jasper/commons-beanutils-1.8.3.jar
deleted file mode 100644
index 218510b..0000000
Binary files a/lib/Jasper/commons-beanutils-1.8.3.jar and /dev/null differ
diff --git a/lib/Jasper/commons-collections-3.2.1.jar b/lib/Jasper/commons-collections-3.2.1.jar
deleted file mode 100644
index c35fa1f..0000000
Binary files a/lib/Jasper/commons-collections-3.2.1.jar and /dev/null differ
diff --git a/lib/Jasper/commons-digester-2.1.jar b/lib/Jasper/commons-digester-2.1.jar
deleted file mode 100644
index a07cfa8..0000000
Binary files a/lib/Jasper/commons-digester-2.1.jar and /dev/null differ
diff --git a/lib/Jasper/commons-javaflow.jar b/lib/Jasper/commons-javaflow.jar
deleted file mode 100644
index 6f8e8db..0000000
Binary files a/lib/Jasper/commons-javaflow.jar and /dev/null differ
diff --git a/lib/Jasper/commons-logging-1.2.jar b/lib/Jasper/commons-logging-1.2.jar
deleted file mode 100644
index 93a3b9f..0000000
Binary files a/lib/Jasper/commons-logging-1.2.jar and /dev/null differ
diff --git a/lib/Jasper/jasperreports-javaflow-6.1.0.jar b/lib/Jasper/jasperreports-javaflow-6.1.0.jar
deleted file mode 100644
index c5c16a7..0000000
Binary files a/lib/Jasper/jasperreports-javaflow-6.1.0.jar and /dev/null differ
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
deleted file mode 100644
index ca84bc6..0000000
--- a/nbproject/build-impl.xml
+++ /dev/null
@@ -1,1422 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set src.resources.dir
- Must set src.dir
- Must set test.src.dir
- Must set build.dir
- Must set dist.dir
- Must set build.classes.dir
- Must set dist.javadoc.dir
- Must set build.test.classes.dir
- Must set build.test.results.dir
- Must set build.classes.excludes
- Must set dist.jar
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set javac.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- No tests executed.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set JVM to use for profiling in profiler.info.jvm
- Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select some files in the IDE or set javac.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- To run this application from the command line without Ant, try:
-
- java -jar "${dist.jar.resolved}"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set run.class
-
-
-
- Must select one file in the IDE or set run.class
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set debug.class
-
-
-
-
- Must select one file in the IDE or set debug.class
-
-
-
-
- Must set fix.includes
-
-
-
-
-
-
-
-
-
- This target only works when run from inside the NetBeans IDE.
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set profile.class
- This target only works when run from inside the NetBeans IDE.
-
-
-
-
-
-
-
-
- This target only works when run from inside the NetBeans IDE.
-
-
-
-
-
-
-
-
-
-
-
-
- This target only works when run from inside the NetBeans IDE.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set run.class
-
-
-
-
-
- Must select some files in the IDE or set test.includes
-
-
-
-
- Must select one file in the IDE or set run.class
-
-
-
-
- Must select one file in the IDE or set applet.url
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select some files in the IDE or set javac.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Some tests failed; see details above.
-
-
-
-
-
-
-
-
- Must select some files in the IDE or set test.includes
-
-
-
- Some tests failed; see details above.
-
-
-
- Must select some files in the IDE or set test.class
- Must select some method in the IDE or set test.method
-
-
-
- Some tests failed; see details above.
-
-
-
-
- Must select one file in the IDE or set test.class
-
-
-
- Must select one file in the IDE or set test.class
- Must select some method in the IDE or set test.method
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set applet.url
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set applet.url
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
deleted file mode 100644
index f24f76c..0000000
--- a/nbproject/genfiles.properties
+++ /dev/null
@@ -1,8 +0,0 @@
-build.xml.data.CRC32=446b1acb
-build.xml.script.CRC32=06c9251c
-build.xml.stylesheet.CRC32=8064a381@1.75.2.48
-# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
-# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=446b1acb
-nbproject/build-impl.xml.script.CRC32=07437918
-nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
diff --git a/nbproject/project.properties b/nbproject/project.properties
deleted file mode 100644
index f28cfa8..0000000
--- a/nbproject/project.properties
+++ /dev/null
@@ -1,112 +0,0 @@
-annotation.processing.enabled=true
-annotation.processing.enabled.in.editor=false
-annotation.processing.processors.list=
-annotation.processing.run.all.processors=true
-annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
-application.title=Examples
-application.vendor=javaquery
-auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
-build.classes.dir=${build.dir}/classes
-build.classes.excludes=**/*.java,**/*.form
-# This directory is removed when the project is cleaned:
-build.dir=build
-build.generated.dir=${build.dir}/generated
-build.generated.sources.dir=${build.dir}/generated-sources
-# Only compile against the classpath explicitly listed here:
-build.sysclasspath=ignore
-build.test.classes.dir=${build.dir}/test/classes
-build.test.results.dir=${build.dir}/test/results
-# Uncomment to specify the preferred debugger connection transport:
-#debug.transport=dt_socket
-debug.classpath=\
- ${run.classpath}
-debug.test.classpath=\
- ${run.test.classpath}
-# Files in build.classes.dir which should be excluded from distribution jar
-dist.archive.excludes=
-# This directory is removed when the project is cleaned:
-dist.dir=dist
-dist.jar=${dist.dir}/Examples.jar
-dist.javadoc.dir=${dist.dir}/javadoc
-endorsed.classpath=
-excludes=
-file.reference.com.lowagie.text-2.1.7.jar=lib\\Jasper\\com.lowagie.text-2.1.7.jar
-file.reference.commons-beanutils-1.8.3.jar=lib\\Jasper\\commons-beanutils-1.8.3.jar
-file.reference.commons-collections-3.2.1.jar=lib\\Jasper\\commons-collections-3.2.1.jar
-file.reference.commons-digester-2.1.jar=lib\\Jasper\\commons-digester-2.1.jar
-file.reference.commons-javaflow.jar=lib\\Jasper\\commons-javaflow.jar
-file.reference.commons-logging-1.2.jar=lib\\Jasper\\commons-logging-1.2.jar
-file.reference.httpclient-4.5.1.jar=D:\\Java APIs\\Apache\\httpclient-4.5.1.jar
-file.reference.httpcore-4.4.4.jar=D:\\Java APIs\\Apache\\httpcore-4.4.4.jar
-file.reference.jackson-all-1.9.0.jar=lib\\JSON\\jackson-all-1.9.0.jar
-file.reference.jasperreports-javaflow-6.1.0.jar=lib\\Jasper\\jasperreports-javaflow-6.1.0.jar
-includes=**
-jar.archive.disabled=${jnlp.enabled}
-jar.compress=false
-jar.index=${jnlp.enabled}
-javac.classpath=\
- ${file.reference.jackson-all-1.9.0.jar}:\
- ${file.reference.com.lowagie.text-2.1.7.jar}:\
- ${file.reference.commons-beanutils-1.8.3.jar}:\
- ${file.reference.commons-collections-3.2.1.jar}:\
- ${file.reference.commons-digester-2.1.jar}:\
- ${file.reference.commons-javaflow.jar}:\
- ${file.reference.jasperreports-javaflow-6.1.0.jar}:\
- ${file.reference.commons-logging-1.2.jar}:\
- ${file.reference.httpclient-4.5.1.jar}:\
- ${file.reference.httpcore-4.4.4.jar}
-# Space-separated list of extra javac options
-javac.compilerargs=
-javac.deprecation=false
-javac.processorpath=\
- ${javac.classpath}
-javac.source=1.8
-javac.target=1.8
-javac.test.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}
-javac.test.processorpath=\
- ${javac.test.classpath}
-javadoc.additionalparam=
-javadoc.author=false
-javadoc.encoding=${source.encoding}
-javadoc.noindex=false
-javadoc.nonavbar=false
-javadoc.notree=false
-javadoc.private=false
-javadoc.splitindex=true
-javadoc.use=true
-javadoc.version=false
-javadoc.windowtitle=
-jnlp.codebase.type=no.codebase
-jnlp.descriptor=application
-jnlp.enabled=false
-jnlp.mixed.code=default
-jnlp.offline-allowed=false
-jnlp.signed=false
-jnlp.signing=
-jnlp.signing.alias=
-jnlp.signing.keystore=
-main.class=
-# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed
-manifest.custom.codebase=
-# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions)
-manifest.custom.permissions=
-manifest.file=manifest.mf
-meta.inf.dir=${src.dir}/META-INF
-mkdist.disabled=false
-platform.active=default_platform
-run.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}
-# Space-separated list of JVM arguments used when running the project.
-# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
-# To set system properties for unit tests define test-sys-prop.name=value:
-run.jvmargs=
-run.test.classpath=\
- ${javac.test.classpath}:\
- ${build.test.classes.dir}
-source.encoding=UTF-8
-src.dir=src
-src.resources.dir=resources
-test.src.dir=test
diff --git a/nbproject/project.xml b/nbproject/project.xml
deleted file mode 100644
index b682212..0000000
--- a/nbproject/project.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
- org.netbeans.modules.java.j2seproject
-
-
- Examples
-
-
-
-
-
-
-
-
-
-
diff --git a/src/com/javaquery/algorithm/searching/SequentialSearch.java b/src/main/java/com/javaquery/algorithm/searching/SequentialSearch.java
similarity index 97%
rename from src/com/javaquery/algorithm/searching/SequentialSearch.java
rename to src/main/java/com/javaquery/algorithm/searching/SequentialSearch.java
index a65efec..8619abf 100644
--- a/src/com/javaquery/algorithm/searching/SequentialSearch.java
+++ b/src/main/java/com/javaquery/algorithm/searching/SequentialSearch.java
@@ -1,97 +1,97 @@
-package com.javaquery.algorithm.searching;
-
-public class SequentialSearch {
-
- /**
- * Sequential search on un-ordered dataset.
- * @param data
- * @param searchElement
- * @return position of element if found or -1 in case not found.
- */
- public static int UnOrderedDataSearch(int data[], int searchElement) {
- int position = -1;
- System.out.print("Compare: ");
-
- /* Search through dataset until record not found */
- for (int i = 0; i < data.length; i++) {
- System.out.print(data[i] + " == " + searchElement + ", ");
- if (data[i] == searchElement) {
- position = i;
- break;
- }
- }
- return position;
- }
-
- /**
- * Sequential search on ordered dataset.
- * @param data
- * @param searchElement
- * @return position of element if found or -1 in case not found.
- */
- public static int OrderedDataSearch(int data[], int searchElement){
- int position = -1;
- System.out.print("Compare: ");
-
- /**
- * As we know its "Ordered dataset"...
- * Compare through dataset until dataset record less than search element .
- */
- for (int i = 0; i < data.length; i++) {
- System.out.print(data[i] + " == " + searchElement + ", ");
- if(data[i] == searchElement){
- position = i;
- break;
- }else if(data[i] > searchElement){
- System.out.print(data[i] + " > " + searchElement + "[break loop]");
- break;
- }
- }
- return position;
- }
-
- public static void main(String[] args) {
- /**
- * Best case: When record found on first position.
- * Average case: When record found on middle position.
- * Worst case: When record found at last position or have to compare upto last record in dataset.
- */
- System.out.println("Sequential Search[Unordered dataset]");
- int[] UnOrderedData = {2, 1, 89, 3, 65, 32, 99, 100, 77};
-
- System.out.println("1. Best case");
- int bestCaseUnOrdered = UnOrderedDataSearch(UnOrderedData, 2);
- System.out.println("\nPosition: " + bestCaseUnOrdered);
- System.out.println("--------------------------------");
-
- System.out.println("2. Average case");
- int averageCaseUnOrdered = UnOrderedDataSearch(UnOrderedData, 65);
- System.out.println("\nPosition: " + averageCaseUnOrdered);
- System.out.println("--------------------------------");
-
- System.out.println("3. Worst case");
- int worstCaseUnOrdered = UnOrderedDataSearch(UnOrderedData, 101);
- System.out.println("\nPosition: " + worstCaseUnOrdered);
-
-
- System.out.println("++++++++++++++++++++++++++++++++++++++++++");
-
-
- System.out.println("Sequential Search[Ordered dataset]");
- int[] OrderedData = {1, 2, 3, 32, 65, 77, 89, 99, 100};
-
- System.out.println("1. Best case");
- int bestCaseOrdered = OrderedDataSearch(UnOrderedData, 2);
- System.out.println("\nPosition: " + bestCaseOrdered);
- System.out.println("--------------------------------");
-
- System.out.println("2. Average case");
- int averageCaseOrdered = OrderedDataSearch(OrderedData, 65);
- System.out.println("\nPosition: " + averageCaseOrdered);
- System.out.println("--------------------------------");
-
- System.out.println("3. Worst case");
- int worstCaseOrdered = OrderedDataSearch(OrderedData, 78);
- System.out.println("\nPosition: " + worstCaseOrdered);
- }
-}
+package com.javaquery.algorithm.searching;
+
+public class SequentialSearch {
+
+ /**
+ * Sequential search on un-ordered dataset.
+ * @param data
+ * @param searchElement
+ * @return position of element if found or -1 in case not found.
+ */
+ public static int UnOrderedDataSearch(int data[], int searchElement) {
+ int position = -1;
+ System.out.print("Compare: ");
+
+ /* Search through dataset until record not found */
+ for (int i = 0; i < data.length; i++) {
+ System.out.print(data[i] + " == " + searchElement + ", ");
+ if (data[i] == searchElement) {
+ position = i;
+ break;
+ }
+ }
+ return position;
+ }
+
+ /**
+ * Sequential search on ordered dataset.
+ * @param data
+ * @param searchElement
+ * @return position of element if found or -1 in case not found.
+ */
+ public static int OrderedDataSearch(int data[], int searchElement){
+ int position = -1;
+ System.out.print("Compare: ");
+
+ /**
+ * As we know its "Ordered dataset"...
+ * Compare through dataset until dataset record less than search element .
+ */
+ for (int i = 0; i < data.length; i++) {
+ System.out.print(data[i] + " == " + searchElement + ", ");
+ if(data[i] == searchElement){
+ position = i;
+ break;
+ }else if(data[i] > searchElement){
+ System.out.print(data[i] + " > " + searchElement + "[break loop]");
+ break;
+ }
+ }
+ return position;
+ }
+
+ public static void main(String[] args) {
+ /**
+ * Best case: When record found on first position.
+ * Average case: When record found on middle position.
+ * Worst case: When record found at last position or have to compare upto last record in dataset.
+ */
+ System.out.println("Sequential Search[Unordered dataset]");
+ int[] UnOrderedData = {2, 1, 89, 3, 65, 32, 99, 100, 77};
+
+ System.out.println("1. Best case");
+ int bestCaseUnOrdered = UnOrderedDataSearch(UnOrderedData, 2);
+ System.out.println("\nPosition: " + bestCaseUnOrdered);
+ System.out.println("--------------------------------");
+
+ System.out.println("2. Average case");
+ int averageCaseUnOrdered = UnOrderedDataSearch(UnOrderedData, 65);
+ System.out.println("\nPosition: " + averageCaseUnOrdered);
+ System.out.println("--------------------------------");
+
+ System.out.println("3. Worst case");
+ int worstCaseUnOrdered = UnOrderedDataSearch(UnOrderedData, 101);
+ System.out.println("\nPosition: " + worstCaseUnOrdered);
+
+
+ System.out.println("++++++++++++++++++++++++++++++++++++++++++");
+
+
+ System.out.println("Sequential Search[Ordered dataset]");
+ int[] OrderedData = {1, 2, 3, 32, 65, 77, 89, 99, 100};
+
+ System.out.println("1. Best case");
+ int bestCaseOrdered = OrderedDataSearch(UnOrderedData, 2);
+ System.out.println("\nPosition: " + bestCaseOrdered);
+ System.out.println("--------------------------------");
+
+ System.out.println("2. Average case");
+ int averageCaseOrdered = OrderedDataSearch(OrderedData, 65);
+ System.out.println("\nPosition: " + averageCaseOrdered);
+ System.out.println("--------------------------------");
+
+ System.out.println("3. Worst case");
+ int worstCaseOrdered = OrderedDataSearch(OrderedData, 78);
+ System.out.println("\nPosition: " + worstCaseOrdered);
+ }
+}
diff --git a/src/com/javaquery/apache/httpclient/HttpDeleteExample.java b/src/main/java/com/javaquery/apache/httpclient/HttpDeleteExample.java
similarity index 97%
rename from src/com/javaquery/apache/httpclient/HttpDeleteExample.java
rename to src/main/java/com/javaquery/apache/httpclient/HttpDeleteExample.java
index b16d8e9..d612dfd 100644
--- a/src/com/javaquery/apache/httpclient/HttpDeleteExample.java
+++ b/src/main/java/com/javaquery/apache/httpclient/HttpDeleteExample.java
@@ -1,64 +1,64 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.apache.httpclient;
-
-import java.io.IOException;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
-/**
- * Example: Apache HttpDelete.
- *
- * @author javaQuery
- * @date 26th January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class HttpDeleteExample {
-
- public static void main(String[] args) {
- /* Create object of CloseableHttpClient */
- CloseableHttpClient httpClient = HttpClients.createDefault();
-
- /* Prepare delete request */
- HttpDelete httpDelete = new HttpDelete("http://www.example.com/api/customer");
- /* Add headers to get request */
- httpDelete.addHeader("Authorization", "value");
-
- /* Response handler for after request execution */
- ResponseHandler responseHandler = new ResponseHandler() {
-
- @Override
- public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
- /* Get status code */
- int httpResponseCode = httpResponse.getStatusLine().getStatusCode();
- System.out.println("Response code: " + httpResponseCode);
- if (httpResponseCode >= 200 && httpResponseCode < 300) {
- /* Convert response to String */
- HttpEntity entity = httpResponse.getEntity();
- return entity != null ? EntityUtils.toString(entity) : null;
- } else {
- return null;
- /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */
- }
- }
- };
-
- try {
- /* Execute URL and attach after execution response handler */
- String strResponse = httpClient.execute(httpDelete, responseHandler);
- /* Print the response */
- System.out.println("Response: " + strResponse);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.apache.httpclient;
+
+import java.io.IOException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+/**
+ * Example: Apache HttpDelete.
+ *
+ * @author javaQuery
+ * @date 26th January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class HttpDeleteExample {
+
+ public static void main(String[] args) {
+ /* Create object of CloseableHttpClient */
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+
+ /* Prepare delete request */
+ HttpDelete httpDelete = new HttpDelete("http://www.example.com/api/customer");
+ /* Add headers to get request */
+ httpDelete.addHeader("Authorization", "value");
+
+ /* Response handler for after request execution */
+ ResponseHandler responseHandler = new ResponseHandler() {
+
+ @Override
+ public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
+ /* Get status code */
+ int httpResponseCode = httpResponse.getStatusLine().getStatusCode();
+ System.out.println("Response code: " + httpResponseCode);
+ if (httpResponseCode >= 200 && httpResponseCode < 300) {
+ /* Convert response to String */
+ HttpEntity entity = httpResponse.getEntity();
+ return entity != null ? EntityUtils.toString(entity) : null;
+ } else {
+ return null;
+ /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */
+ }
+ }
+ };
+
+ try {
+ /* Execute URL and attach after execution response handler */
+ String strResponse = httpClient.execute(httpDelete, responseHandler);
+ /* Print the response */
+ System.out.println("Response: " + strResponse);
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/src/com/javaquery/apache/httpclient/HttpGetExample.java b/src/main/java/com/javaquery/apache/httpclient/HttpGetExample.java
similarity index 97%
rename from src/com/javaquery/apache/httpclient/HttpGetExample.java
rename to src/main/java/com/javaquery/apache/httpclient/HttpGetExample.java
index c9d2df2..881abdd 100644
--- a/src/com/javaquery/apache/httpclient/HttpGetExample.java
+++ b/src/main/java/com/javaquery/apache/httpclient/HttpGetExample.java
@@ -1,64 +1,64 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.apache.httpclient;
-
-import java.io.IOException;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
-/**
- * Example: Apache HttpGet.
- * @author javaQuery
- * @date 22nd January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class HttpGetExample {
-
- public static void main(String[] args) {
- /* Create object of CloseableHttpClient */
- CloseableHttpClient httpClient = HttpClients.createDefault();
-
- /* Prepare get request */
- HttpGet httpGet = new HttpGet("http://www.example.com/api/customer");
- /* Add headers to get request */
- httpGet.addHeader("Authorization", "value");
- httpGet.addHeader("Content-Type", "application/json");
-
- /* Response handler for after request execution */
- ResponseHandler responseHandler = new ResponseHandler() {
-
- @Override
- public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
- /* Get status code */
- int httpResponseCode = httpResponse.getStatusLine().getStatusCode();
- System.out.println("Response code: " + httpResponseCode);
- if (httpResponseCode >= 200 && httpResponseCode < 300) {
- /* Convert response to String */
- HttpEntity entity = httpResponse.getEntity();
- return entity != null ? EntityUtils.toString(entity) : null;
- } else {
- return null;
- /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */
- }
- }
- };
-
- try {
- /* Execute URL and attach after execution response handler */
- String strResponse = httpClient.execute(httpGet, responseHandler);
- /* Print the response */
- System.out.println("Response: " + strResponse);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.apache.httpclient;
+
+import java.io.IOException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+/**
+ * Example: Apache HttpGet.
+ * @author javaQuery
+ * @date 22nd January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class HttpGetExample {
+
+ public static void main(String[] args) {
+ /* Create object of CloseableHttpClient */
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+
+ /* Prepare get request */
+ HttpGet httpGet = new HttpGet("http://www.example.com/api/customer");
+ /* Add headers to get request */
+ httpGet.addHeader("Authorization", "value");
+ httpGet.addHeader("Content-Type", "application/json");
+
+ /* Response handler for after request execution */
+ ResponseHandler responseHandler = new ResponseHandler() {
+
+ @Override
+ public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
+ /* Get status code */
+ int httpResponseCode = httpResponse.getStatusLine().getStatusCode();
+ System.out.println("Response code: " + httpResponseCode);
+ if (httpResponseCode >= 200 && httpResponseCode < 300) {
+ /* Convert response to String */
+ HttpEntity entity = httpResponse.getEntity();
+ return entity != null ? EntityUtils.toString(entity) : null;
+ } else {
+ return null;
+ /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */
+ }
+ }
+ };
+
+ try {
+ /* Execute URL and attach after execution response handler */
+ String strResponse = httpClient.execute(httpGet, responseHandler);
+ /* Print the response */
+ System.out.println("Response: " + strResponse);
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/src/com/javaquery/apache/httpclient/HttpPostExample.java b/src/main/java/com/javaquery/apache/httpclient/HttpPostExample.java
similarity index 97%
rename from src/com/javaquery/apache/httpclient/HttpPostExample.java
rename to src/main/java/com/javaquery/apache/httpclient/HttpPostExample.java
index 66038a9..4842ac7 100644
--- a/src/com/javaquery/apache/httpclient/HttpPostExample.java
+++ b/src/main/java/com/javaquery/apache/httpclient/HttpPostExample.java
@@ -1,70 +1,70 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.apache.httpclient;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
-/**
- * Example: Apache HttpPost.
- * @author javaQuery
- * @date 23rd January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class HttpPostExample {
- public static void main(String[] args) throws UnsupportedEncodingException {
- /* Create object of CloseableHttpClient */
- CloseableHttpClient httpClient = HttpClients.createDefault();
-
- /* Prepare POST request */
- HttpPost httpPost = new HttpPost("http://www.example.com/api/customer");
- /* Add headers to POST request */
- httpPost.addHeader("Authorization", "value");
- httpPost.addHeader("Content-Type", "application/json");
-
- /* Prepare StringEntity from JSON */
- StringEntity jsonData = new StringEntity("{\"id\":\"123\", \"name\":\"Vicky Thakor\"}", "UTF-8");
- /* Body of request */
- httpPost.setEntity(jsonData);
-
- /* Response handler for after request execution */
- ResponseHandler responseHandler = new ResponseHandler() {
-
- @Override
- public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
- /* Get status code */
- int httpResponseCode = httpResponse.getStatusLine().getStatusCode();
- System.out.println("Response code: " + httpResponseCode);
- if (httpResponseCode >= 200 && httpResponseCode < 300) {
- /* Convert response to String */
- HttpEntity entity = httpResponse.getEntity();
- return entity != null ? EntityUtils.toString(entity) : null;
- } else {
- return null;
- /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */
- }
- }
- };
-
- try {
- /* Execute URL and attach after execution response handler */
- String strResponse = httpClient.execute(httpPost, responseHandler);
- /* Print the response */
- System.out.println("Response: " + strResponse);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.apache.httpclient;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+/**
+ * Example: Apache HttpPost.
+ * @author javaQuery
+ * @date 23rd January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class HttpPostExample {
+ public static void main(String[] args) throws UnsupportedEncodingException {
+ /* Create object of CloseableHttpClient */
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+
+ /* Prepare POST request */
+ HttpPost httpPost = new HttpPost("http://www.example.com/api/customer");
+ /* Add headers to POST request */
+ httpPost.addHeader("Authorization", "value");
+ httpPost.addHeader("Content-Type", "application/json");
+
+ /* Prepare StringEntity from JSON */
+ StringEntity jsonData = new StringEntity("{\"id\":\"123\", \"name\":\"Vicky Thakor\"}", "UTF-8");
+ /* Body of request */
+ httpPost.setEntity(jsonData);
+
+ /* Response handler for after request execution */
+ ResponseHandler responseHandler = new ResponseHandler() {
+
+ @Override
+ public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
+ /* Get status code */
+ int httpResponseCode = httpResponse.getStatusLine().getStatusCode();
+ System.out.println("Response code: " + httpResponseCode);
+ if (httpResponseCode >= 200 && httpResponseCode < 300) {
+ /* Convert response to String */
+ HttpEntity entity = httpResponse.getEntity();
+ return entity != null ? EntityUtils.toString(entity) : null;
+ } else {
+ return null;
+ /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */
+ }
+ }
+ };
+
+ try {
+ /* Execute URL and attach after execution response handler */
+ String strResponse = httpClient.execute(httpPost, responseHandler);
+ /* Print the response */
+ System.out.println("Response: " + strResponse);
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/src/com/javaquery/apache/httpclient/HttpPutExample.java b/src/main/java/com/javaquery/apache/httpclient/HttpPutExample.java
similarity index 59%
rename from src/com/javaquery/apache/httpclient/HttpPutExample.java
rename to src/main/java/com/javaquery/apache/httpclient/HttpPutExample.java
index 6632182..ab6f676 100644
--- a/src/com/javaquery/apache/httpclient/HttpPutExample.java
+++ b/src/main/java/com/javaquery/apache/httpclient/HttpPutExample.java
@@ -1,70 +1,84 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.apache.httpclient;
-
-import java.io.IOException;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
-/**
- * Example: Apache HttpPut.
- *
- * @author javaQuery
- * @date 26th January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class HttpPutExample {
-
- public static void main(String[] args) {
- /* Create object of CloseableHttpClient */
- CloseableHttpClient httpClient = HttpClients.createDefault();
-
- /* Prepare put request */
- HttpPut httpPut = new HttpPut("http://www.example.com/api/customer");
- /* Add headers to get request */
- httpPut.addHeader("Authorization", "value");
-
- /* Prepare StringEntity from JSON */
- StringEntity jsonData = new StringEntity("{\"id\":\"123\", \"name\":\"Vicky Thakor\"}", "UTF-8");
- /* Body of request */
- httpPut.setEntity(jsonData);
-
- /* Response handler for after request execution */
- ResponseHandler responseHandler = new ResponseHandler() {
-
- @Override
- public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
- /* Get status code */
- int httpResponseCode = httpResponse.getStatusLine().getStatusCode();
- System.out.println("Response code: " + httpResponseCode);
- if (httpResponseCode >= 200 && httpResponseCode < 300) {
- /* Convert response to String */
- HttpEntity entity = httpResponse.getEntity();
- return entity != null ? EntityUtils.toString(entity) : null;
- } else {
- return null;
- /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */
- }
- }
- };
-
- try {
- /* Execute URL and attach after execution response handler */
- String strResponse = httpClient.execute(httpPut, responseHandler);
- /* Print the response */
- System.out.println("Response: " + strResponse);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.apache.httpclient;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+/**
+ * Example: Apache HttpPut.
+ *
+ * @author javaQuery
+ * @date 26th January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class HttpPutExample {
+
+ public static void main(String[] args) throws UnsupportedEncodingException {
+ /* Create object of CloseableHttpClient */
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+
+ /* Prepare put request */
+ HttpPut httpPut = new HttpPut("https://doto.vtexcommercestable.com.br/api/logistics/pvt/inventory/skus/57/warehouses/1_1");
+ /* Add headers to get request */
+// httpPut.addHeader("x-vtex-api-appKey", "vtexappkey-doto-YOYAUC");
+// httpPut.addHeader("x-vtex-api-appToken", "IMDRPFDFQQMJSFLMJOZCYGKSRKOSENKKNUCKLLXWZECSVKXSDKPTRSICCKZFQLBDFCWXCBAYQCDTDRWHMVOTXRSUMZIBLSFNDYNTOZPCKRCPPPZLNSSVXIGOJBLDSZMY");
+// httpPut.addHeader("Content-Type", "application/json");
+// httpPut.addHeader("Accept", "application/json");
+// httpPut.addHeader("Host", "doto.vtexcommercestable.com.br");
+
+ /* Prepare StringEntity from JSON */
+ StringEntity jsonData = new StringEntity("{\"quantity\":0,\"unlimitedQuantity\":false}", "application/json","UTF-8");
+ /* Body of request */
+ httpPut.setEntity(jsonData);
+
+ /* Response handler for after request execution */
+ ResponseHandler responseHandler = new ResponseHandler() {
+
+ @Override
+ public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {
+ /* Get status code */
+ int httpResponseCode = httpResponse.getStatusLine().getStatusCode();
+ System.out.println("Response code: " + httpResponseCode);
+ if (httpResponseCode >= 200 && httpResponseCode < 300) {
+ /* Convert response to String */
+ HttpEntity entity = httpResponse.getEntity();
+ return entity != null ? EntityUtils.toString(entity) : null;
+ } else {
+ return null;
+ /* throw new ClientProtocolException("Unexpected response status: " + httpResponseCode); */
+ }
+ }
+ };
+
+ try {
+ HttpRequestBase httpRequestBase = httpPut;
+ httpRequestBase.addHeader("x-vtex-api-appKey", "vtexappkey-doto-YOYAUC");
+ httpRequestBase.addHeader("x-vtex-api-appToken", "IMDRPFDFQQMJSFLMJOZCYGKSRKOSENKKNUCKLLXWZECSVKXSDKPTRSICCKZFQLBDFCWXCBAYQCDTDRWHMVOTXRSUMZIBLSFNDYNTOZPCKRCPPPZLNSSVXIGOJBLDSZMY");
+ httpRequestBase.addHeader("Content-Type", "application/json");
+ httpRequestBase.addHeader("Content-Type", "application/json");
+ httpRequestBase.addHeader("Accept", "application/json");
+ httpRequestBase.addHeader("Host", "doto.vtexcommercestable.com.br");
+ /* Execute URL and attach after execution response handler */
+ String strResponse = httpClient.execute(httpRequestBase, responseHandler);
+ /* Print the response */
+ System.out.println("Response: " + strResponse);
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/src/com/javaquery/aws/AWSV4Auth.java b/src/main/java/com/javaquery/aws/AWSV4Auth.java
similarity index 97%
rename from src/com/javaquery/aws/AWSV4Auth.java
rename to src/main/java/com/javaquery/aws/AWSV4Auth.java
index a9eb87e..ccdfd81 100644
--- a/src/com/javaquery/aws/AWSV4Auth.java
+++ b/src/main/java/com/javaquery/aws/AWSV4Auth.java
@@ -1,413 +1,413 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.aws;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TimeZone;
-import java.util.TreeMap;
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-
-/**
- * Example: Signing AWS Requests with Signature Version 4 in Java.
- *
- * @reference: http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
- * @author javaQuery
- * @date 19th January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class AWSV4Auth {
-
- private AWSV4Auth() {
- }
-
- public static class Builder {
-
- private String accessKeyID;
- private String secretAccessKey;
- private String regionName;
- private String serviceName;
- private String httpMethodName;
- private String canonicalURI;
- private TreeMap queryParametes;
- private TreeMap awsHeaders;
- private String payload;
- private boolean debug = false;
-
- public Builder(String accessKeyID, String secretAccessKey) {
- this.accessKeyID = accessKeyID;
- this.secretAccessKey = secretAccessKey;
- }
-
- public Builder regionName(String regionName) {
- this.regionName = regionName;
- return this;
- }
-
- public Builder serviceName(String serviceName) {
- this.serviceName = serviceName;
- return this;
- }
-
- public Builder httpMethodName(String httpMethodName) {
- this.httpMethodName = httpMethodName;
- return this;
- }
-
- public Builder canonicalURI(String canonicalURI) {
- this.canonicalURI = canonicalURI;
- return this;
- }
-
- public Builder queryParametes(TreeMap queryParametes) {
- this.queryParametes = queryParametes;
- return this;
- }
-
- public Builder awsHeaders(TreeMap awsHeaders) {
- this.awsHeaders = awsHeaders;
- return this;
- }
-
- public Builder payload(String payload) {
- this.payload = payload;
- return this;
- }
-
- public Builder debug() {
- this.debug = true;
- return this;
- }
-
- public AWSV4Auth build() {
- return new AWSV4Auth(this);
- }
- }
-
- private String accessKeyID;
- private String secretAccessKey;
- private String regionName;
- private String serviceName;
- private String httpMethodName;
- private String canonicalURI;
- private TreeMap queryParametes;
- private TreeMap awsHeaders;
- private String payload;
- private boolean debug = false;
-
- /* Other variables */
- private final String HMACAlgorithm = "AWS4-HMAC-SHA256";
- private final String aws4Request = "aws4_request";
- private String strSignedHeader;
- private String xAmzDate;
- private String currentDate;
-
- private AWSV4Auth(Builder builder) {
- accessKeyID = builder.accessKeyID;
- secretAccessKey = builder.secretAccessKey;
- regionName = builder.regionName;
- serviceName = builder.serviceName;
- httpMethodName = builder.httpMethodName;
- canonicalURI = builder.canonicalURI;
- queryParametes = builder.queryParametes;
- awsHeaders = builder.awsHeaders;
- payload = builder.payload;
- debug = builder.debug;
-
- /* Get current timestamp value.(UTC) */
- xAmzDate = getTimeStamp();
- currentDate = getDate();
- }
-
- /**
- * Task 1: Create a Canonical Request for Signature Version 4.
- *
- * @return
- */
- private String prepareCanonicalRequest() {
- StringBuilder canonicalURL = new StringBuilder("");
-
- /* Step 1.1 Start with the HTTP request method (GET, PUT, POST, etc.), followed by a newline character. */
- canonicalURL.append(httpMethodName).append("\n");
-
- /* Step 1.2 Add the canonical URI parameter, followed by a newline character. */
- canonicalURI = canonicalURI == null || canonicalURI.trim().isEmpty() ? "/" : canonicalURI;
- canonicalURL.append(canonicalURI).append("\n");
-
- /* Step 1.3 Add the canonical query string, followed by a newline character. */
- StringBuilder queryString = new StringBuilder("");
- if (queryParametes != null && !queryParametes.isEmpty()) {
- for (Map.Entry entrySet : queryParametes.entrySet()) {
- String key = entrySet.getKey();
- String value = entrySet.getValue();
- queryString.append(key).append("=").append(encodeParameter(value)).append("&");
- }
- /* @co-author https://github.com/dotkebi @git #1 @date 16th March, 2017 */
- queryString.deleteCharAt(queryString.lastIndexOf("&"));
- queryString.append("\n");
- } else {
- queryString.append("\n");
- }
- canonicalURL.append(queryString);
-
- /* Step 1.4 Add the canonical headers, followed by a newline character. */
- StringBuilder signedHeaders = new StringBuilder("");
- if (awsHeaders != null && !awsHeaders.isEmpty()) {
- for (Map.Entry entrySet : awsHeaders.entrySet()) {
- String key = entrySet.getKey();
- String value = entrySet.getValue();
- signedHeaders.append(key).append(";");
- canonicalURL.append(key).append(":").append(value).append("\n");
- }
-
- /* Note: Each individual header is followed by a newline character, meaning the complete list ends with a newline character. */
- canonicalURL.append("\n");
- } else {
- canonicalURL.append("\n");
- }
-
- /* Step 1.5 Add the signed headers, followed by a newline character. */
- strSignedHeader = signedHeaders.substring(0, signedHeaders.length() - 1); // Remove last ";"
- canonicalURL.append(strSignedHeader).append("\n");
-
- /* Step 1.6 Use a hash (digest) function like SHA256 to create a hashed value from the payload in the body of the HTTP or HTTPS. */
- payload = payload == null ? "" : payload;
- canonicalURL.append(generateHex(payload));
-
- if (debug) {
- System.out.println("##Canonical Request:\n" + canonicalURL.toString());
- }
-
- return canonicalURL.toString();
- }
-
- /**
- * Task 2: Create a String to Sign for Signature Version 4.
- *
- * @param canonicalURL
- * @return
- */
- private String prepareStringToSign(String canonicalURL) {
- String stringToSign = "";
-
- /* Step 2.1 Start with the algorithm designation, followed by a newline character. */
- stringToSign = HMACAlgorithm + "\n";
-
- /* Step 2.2 Append the request date value, followed by a newline character. */
- stringToSign += xAmzDate + "\n";
-
- /* Step 2.3 Append the credential scope value, followed by a newline character. */
- stringToSign += currentDate + "/" + regionName + "/" + serviceName + "/" + aws4Request + "\n";
-
- /* Step 2.4 Append the hash of the canonical request that you created in Task 1: Create a Canonical Request for Signature Version 4. */
- stringToSign += generateHex(canonicalURL);
-
- if (debug) {
- System.out.println("##String to sign:\n" + stringToSign);
- }
-
- return stringToSign;
- }
-
- /**
- * Task 3: Calculate the AWS Signature Version 4.
- *
- * @param stringToSign
- * @return
- */
- private String calculateSignature(String stringToSign) {
- try {
- /* Step 3.1 Derive your signing key */
- byte[] signatureKey = getSignatureKey(secretAccessKey, currentDate, regionName, serviceName);
-
- /* Step 3.2 Calculate the signature. */
- byte[] signature = HmacSHA256(signatureKey, stringToSign);
-
- /* Step 3.2.1 Encode signature (byte[]) to Hex */
- String strHexSignature = bytesToHex(signature);
- return strHexSignature;
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return null;
- }
-
- /**
- * Task 4: Add the Signing Information to the Request. We'll return Map of
- * all headers put this headers in your request.
- *
- * @return
- */
- public Map getHeaders() {
- awsHeaders.put("x-amz-date", xAmzDate);
-
- /* Execute Task 1: Create a Canonical Request for Signature Version 4. */
- String canonicalURL = prepareCanonicalRequest();
-
- /* Execute Task 2: Create a String to Sign for Signature Version 4. */
- String stringToSign = prepareStringToSign(canonicalURL);
-
- /* Execute Task 3: Calculate the AWS Signature Version 4. */
- String signature = calculateSignature(stringToSign);
-
- if (signature != null) {
- Map header = new HashMap(0);
- header.put("x-amz-date", xAmzDate);
- header.put("Authorization", buildAuthorizationString(signature));
-
- if (debug) {
- System.out.println("##Signature:\n" + signature);
- System.out.println("##Header:");
- for (Map.Entry entrySet : header.entrySet()) {
- System.out.println(entrySet.getKey() + " = " + entrySet.getValue());
- }
- System.out.println("================================");
- }
- return header;
- } else {
- if (debug) {
- System.out.println("##Signature:\n" + signature);
- }
- return null;
- }
- }
-
- /**
- * Build string for Authorization header.
- *
- * @param strSignature
- * @return
- */
- private String buildAuthorizationString(String strSignature) {
- return HMACAlgorithm + " "
- + "Credential=" + accessKeyID + "/" + getDate() + "/" + regionName + "/" + serviceName + "/" + aws4Request + ","
- + "SignedHeaders=" + strSignedHeader + ","
- + "Signature=" + strSignature;
- }
-
- /**
- * Generate Hex code of String.
- *
- * @param data
- * @return
- */
- private String generateHex(String data) {
- MessageDigest messageDigest;
- try {
- messageDigest = MessageDigest.getInstance("SHA-256");
- messageDigest.update(data.getBytes("UTF-8"));
- byte[] digest = messageDigest.digest();
- return String.format("%064x", new java.math.BigInteger(1, digest));
- } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * Apply HmacSHA256 on data using given key.
- *
- * @param data
- * @param key
- * @return
- * @throws Exception
- * @reference:
- * http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-java
- */
- private byte[] HmacSHA256(byte[] key, String data) throws Exception {
- String algorithm = "HmacSHA256";
- Mac mac = Mac.getInstance(algorithm);
- mac.init(new SecretKeySpec(key, algorithm));
- return mac.doFinal(data.getBytes("UTF8"));
- }
-
- /**
- * Generate AWS signature key.
- *
- * @param key
- * @param date
- * @param regionName
- * @param serviceName
- * @return
- * @throws Exception
- * @reference
- * http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-java
- */
- private byte[] getSignatureKey(String key, String date, String regionName, String serviceName) throws Exception {
- byte[] kSecret = ("AWS4" + key).getBytes("UTF8");
- byte[] kDate = HmacSHA256(kSecret, date);
- byte[] kRegion = HmacSHA256(kDate, regionName);
- byte[] kService = HmacSHA256(kRegion, serviceName);
- byte[] kSigning = HmacSHA256(kService, aws4Request);
- return kSigning;
- }
-
- final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
-
- /**
- * Convert byte array to Hex
- *
- * @param bytes
- * @return
- */
- private String bytesToHex(byte[] bytes) {
- char[] hexChars = new char[bytes.length * 2];
- for (int j = 0; j < bytes.length; j++) {
- int v = bytes[j] & 0xFF;
- hexChars[j * 2] = hexArray[v >>> 4];
- hexChars[j * 2 + 1] = hexArray[v & 0x0F];
- }
- return new String(hexChars).toLowerCase();
- }
-
- /**
- * Get timestamp. yyyyMMdd'T'HHmmss'Z'
- *
- * @return
- */
- private String getTimeStamp() {
- DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));//server timezone
- return dateFormat.format(new Date());
- }
-
- /**
- * Get date. yyyyMMdd
- *
- * @return
- */
- private String getDate() {
- DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));//server timezone
- return dateFormat.format(new Date());
- }
-
- /**
- * Using {@link URLEncoder#encode(java.lang.String, java.lang.String) } instead of
- * {@link URLEncoder#encode(java.lang.String) }
- *
- * @co-author https://github.com/dotkebi
- * @date 16th March, 2017
- * @git #1
- * @param param
- * @return
- */
- private String encodeParameter(String param){
- try {
- return URLEncoder.encode(param, "UTF-8");
- } catch (Exception e) {
- return URLEncoder.encode(param);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.aws;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.TreeMap;
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+/**
+ * Example: Signing AWS Requests with Signature Version 4 in Java.
+ *
+ * @reference: http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
+ * @author javaQuery
+ * @date 19th January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class AWSV4Auth {
+
+ private AWSV4Auth() {
+ }
+
+ public static class Builder {
+
+ private String accessKeyID;
+ private String secretAccessKey;
+ private String regionName;
+ private String serviceName;
+ private String httpMethodName;
+ private String canonicalURI;
+ private TreeMap queryParametes;
+ private TreeMap awsHeaders;
+ private String payload;
+ private boolean debug = false;
+
+ public Builder(String accessKeyID, String secretAccessKey) {
+ this.accessKeyID = accessKeyID;
+ this.secretAccessKey = secretAccessKey;
+ }
+
+ public Builder regionName(String regionName) {
+ this.regionName = regionName;
+ return this;
+ }
+
+ public Builder serviceName(String serviceName) {
+ this.serviceName = serviceName;
+ return this;
+ }
+
+ public Builder httpMethodName(String httpMethodName) {
+ this.httpMethodName = httpMethodName;
+ return this;
+ }
+
+ public Builder canonicalURI(String canonicalURI) {
+ this.canonicalURI = canonicalURI;
+ return this;
+ }
+
+ public Builder queryParametes(TreeMap queryParametes) {
+ this.queryParametes = queryParametes;
+ return this;
+ }
+
+ public Builder awsHeaders(TreeMap awsHeaders) {
+ this.awsHeaders = awsHeaders;
+ return this;
+ }
+
+ public Builder payload(String payload) {
+ this.payload = payload;
+ return this;
+ }
+
+ public Builder debug() {
+ this.debug = true;
+ return this;
+ }
+
+ public AWSV4Auth build() {
+ return new AWSV4Auth(this);
+ }
+ }
+
+ private String accessKeyID;
+ private String secretAccessKey;
+ private String regionName;
+ private String serviceName;
+ private String httpMethodName;
+ private String canonicalURI;
+ private TreeMap queryParametes;
+ private TreeMap awsHeaders;
+ private String payload;
+ private boolean debug = false;
+
+ /* Other variables */
+ private final String HMACAlgorithm = "AWS4-HMAC-SHA256";
+ private final String aws4Request = "aws4_request";
+ private String strSignedHeader;
+ private String xAmzDate;
+ private String currentDate;
+
+ private AWSV4Auth(Builder builder) {
+ accessKeyID = builder.accessKeyID;
+ secretAccessKey = builder.secretAccessKey;
+ regionName = builder.regionName;
+ serviceName = builder.serviceName;
+ httpMethodName = builder.httpMethodName;
+ canonicalURI = builder.canonicalURI;
+ queryParametes = builder.queryParametes;
+ awsHeaders = builder.awsHeaders;
+ payload = builder.payload;
+ debug = builder.debug;
+
+ /* Get current timestamp value.(UTC) */
+ xAmzDate = getTimeStamp();
+ currentDate = getDate();
+ }
+
+ /**
+ * Task 1: Create a Canonical Request for Signature Version 4.
+ *
+ * @return
+ */
+ private String prepareCanonicalRequest() {
+ StringBuilder canonicalURL = new StringBuilder("");
+
+ /* Step 1.1 Start with the HTTP request method (GET, PUT, POST, etc.), followed by a newline character. */
+ canonicalURL.append(httpMethodName).append("\n");
+
+ /* Step 1.2 Add the canonical URI parameter, followed by a newline character. */
+ canonicalURI = canonicalURI == null || canonicalURI.trim().isEmpty() ? "/" : canonicalURI;
+ canonicalURL.append(canonicalURI).append("\n");
+
+ /* Step 1.3 Add the canonical query string, followed by a newline character. */
+ StringBuilder queryString = new StringBuilder("");
+ if (queryParametes != null && !queryParametes.isEmpty()) {
+ for (Map.Entry entrySet : queryParametes.entrySet()) {
+ String key = entrySet.getKey();
+ String value = entrySet.getValue();
+ queryString.append(key).append("=").append(encodeParameter(value)).append("&");
+ }
+ /* @co-author https://github.com/dotkebi @git #1 @date 16th March, 2017 */
+ queryString.deleteCharAt(queryString.lastIndexOf("&"));
+ queryString.append("\n");
+ } else {
+ queryString.append("\n");
+ }
+ canonicalURL.append(queryString);
+
+ /* Step 1.4 Add the canonical headers, followed by a newline character. */
+ StringBuilder signedHeaders = new StringBuilder("");
+ if (awsHeaders != null && !awsHeaders.isEmpty()) {
+ for (Map.Entry entrySet : awsHeaders.entrySet()) {
+ String key = entrySet.getKey();
+ String value = entrySet.getValue();
+ signedHeaders.append(key).append(";");
+ canonicalURL.append(key).append(":").append(value).append("\n");
+ }
+
+ /* Note: Each individual header is followed by a newline character, meaning the complete list ends with a newline character. */
+ canonicalURL.append("\n");
+ } else {
+ canonicalURL.append("\n");
+ }
+
+ /* Step 1.5 Add the signed headers, followed by a newline character. */
+ strSignedHeader = signedHeaders.substring(0, signedHeaders.length() - 1); // Remove last ";"
+ canonicalURL.append(strSignedHeader).append("\n");
+
+ /* Step 1.6 Use a hash (digest) function like SHA256 to create a hashed value from the payload in the body of the HTTP or HTTPS. */
+ payload = payload == null ? "" : payload;
+ canonicalURL.append(generateHex(payload));
+
+ if (debug) {
+ System.out.println("##Canonical Request:\n" + canonicalURL.toString());
+ }
+
+ return canonicalURL.toString();
+ }
+
+ /**
+ * Task 2: Create a String to Sign for Signature Version 4.
+ *
+ * @param canonicalURL
+ * @return
+ */
+ private String prepareStringToSign(String canonicalURL) {
+ String stringToSign = "";
+
+ /* Step 2.1 Start with the algorithm designation, followed by a newline character. */
+ stringToSign = HMACAlgorithm + "\n";
+
+ /* Step 2.2 Append the request date value, followed by a newline character. */
+ stringToSign += xAmzDate + "\n";
+
+ /* Step 2.3 Append the credential scope value, followed by a newline character. */
+ stringToSign += currentDate + "/" + regionName + "/" + serviceName + "/" + aws4Request + "\n";
+
+ /* Step 2.4 Append the hash of the canonical request that you created in Task 1: Create a Canonical Request for Signature Version 4. */
+ stringToSign += generateHex(canonicalURL);
+
+ if (debug) {
+ System.out.println("##String to sign:\n" + stringToSign);
+ }
+
+ return stringToSign;
+ }
+
+ /**
+ * Task 3: Calculate the AWS Signature Version 4.
+ *
+ * @param stringToSign
+ * @return
+ */
+ private String calculateSignature(String stringToSign) {
+ try {
+ /* Step 3.1 Derive your signing key */
+ byte[] signatureKey = getSignatureKey(secretAccessKey, currentDate, regionName, serviceName);
+
+ /* Step 3.2 Calculate the signature. */
+ byte[] signature = HmacSHA256(signatureKey, stringToSign);
+
+ /* Step 3.2.1 Encode signature (byte[]) to Hex */
+ String strHexSignature = bytesToHex(signature);
+ return strHexSignature;
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Task 4: Add the Signing Information to the Request. We'll return Map of
+ * all headers put this headers in your request.
+ *
+ * @return
+ */
+ public Map getHeaders() {
+ awsHeaders.put("x-amz-date", xAmzDate);
+
+ /* Execute Task 1: Create a Canonical Request for Signature Version 4. */
+ String canonicalURL = prepareCanonicalRequest();
+
+ /* Execute Task 2: Create a String to Sign for Signature Version 4. */
+ String stringToSign = prepareStringToSign(canonicalURL);
+
+ /* Execute Task 3: Calculate the AWS Signature Version 4. */
+ String signature = calculateSignature(stringToSign);
+
+ if (signature != null) {
+ Map header = new HashMap(0);
+ header.put("x-amz-date", xAmzDate);
+ header.put("Authorization", buildAuthorizationString(signature));
+
+ if (debug) {
+ System.out.println("##Signature:\n" + signature);
+ System.out.println("##Header:");
+ for (Map.Entry entrySet : header.entrySet()) {
+ System.out.println(entrySet.getKey() + " = " + entrySet.getValue());
+ }
+ System.out.println("================================");
+ }
+ return header;
+ } else {
+ if (debug) {
+ System.out.println("##Signature:\n" + signature);
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Build string for Authorization header.
+ *
+ * @param strSignature
+ * @return
+ */
+ private String buildAuthorizationString(String strSignature) {
+ return HMACAlgorithm + " "
+ + "Credential=" + accessKeyID + "/" + getDate() + "/" + regionName + "/" + serviceName + "/" + aws4Request + ","
+ + "SignedHeaders=" + strSignedHeader + ","
+ + "Signature=" + strSignature;
+ }
+
+ /**
+ * Generate Hex code of String.
+ *
+ * @param data
+ * @return
+ */
+ private String generateHex(String data) {
+ MessageDigest messageDigest;
+ try {
+ messageDigest = MessageDigest.getInstance("SHA-256");
+ messageDigest.update(data.getBytes("UTF-8"));
+ byte[] digest = messageDigest.digest();
+ return String.format("%064x", new java.math.BigInteger(1, digest));
+ } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Apply HmacSHA256 on data using given key.
+ *
+ * @param data
+ * @param key
+ * @return
+ * @throws Exception
+ * @reference:
+ * http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-java
+ */
+ private byte[] HmacSHA256(byte[] key, String data) throws Exception {
+ String algorithm = "HmacSHA256";
+ Mac mac = Mac.getInstance(algorithm);
+ mac.init(new SecretKeySpec(key, algorithm));
+ return mac.doFinal(data.getBytes("UTF8"));
+ }
+
+ /**
+ * Generate AWS signature key.
+ *
+ * @param key
+ * @param date
+ * @param regionName
+ * @param serviceName
+ * @return
+ * @throws Exception
+ * @reference
+ * http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-java
+ */
+ private byte[] getSignatureKey(String key, String date, String regionName, String serviceName) throws Exception {
+ byte[] kSecret = ("AWS4" + key).getBytes("UTF8");
+ byte[] kDate = HmacSHA256(kSecret, date);
+ byte[] kRegion = HmacSHA256(kDate, regionName);
+ byte[] kService = HmacSHA256(kRegion, serviceName);
+ byte[] kSigning = HmacSHA256(kService, aws4Request);
+ return kSigning;
+ }
+
+ final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
+
+ /**
+ * Convert byte array to Hex
+ *
+ * @param bytes
+ * @return
+ */
+ private String bytesToHex(byte[] bytes) {
+ char[] hexChars = new char[bytes.length * 2];
+ for (int j = 0; j < bytes.length; j++) {
+ int v = bytes[j] & 0xFF;
+ hexChars[j * 2] = hexArray[v >>> 4];
+ hexChars[j * 2 + 1] = hexArray[v & 0x0F];
+ }
+ return new String(hexChars).toLowerCase();
+ }
+
+ /**
+ * Get timestamp. yyyyMMdd'T'HHmmss'Z'
+ *
+ * @return
+ */
+ private String getTimeStamp() {
+ DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));//server timezone
+ return dateFormat.format(new Date());
+ }
+
+ /**
+ * Get date. yyyyMMdd
+ *
+ * @return
+ */
+ private String getDate() {
+ DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));//server timezone
+ return dateFormat.format(new Date());
+ }
+
+ /**
+ * Using {@link URLEncoder#encode(java.lang.String, java.lang.String) } instead of
+ * {@link URLEncoder#encode(java.lang.String) }
+ *
+ * @co-author https://github.com/dotkebi
+ * @date 16th March, 2017
+ * @git #1
+ * @param param
+ * @return
+ */
+ private String encodeParameter(String param){
+ try {
+ return URLEncoder.encode(param, "UTF-8");
+ } catch (Exception e) {
+ return URLEncoder.encode(param);
+ }
+ }
+}
diff --git a/src/com/javaquery/aws/elasticsearch/AddUpdateExample.java b/src/main/java/com/javaquery/aws/elasticsearch/AddUpdateExample.java
similarity index 97%
rename from src/com/javaquery/aws/elasticsearch/AddUpdateExample.java
rename to src/main/java/com/javaquery/aws/elasticsearch/AddUpdateExample.java
index 21981f4..e4e65a4 100644
--- a/src/com/javaquery/aws/elasticsearch/AddUpdateExample.java
+++ b/src/main/java/com/javaquery/aws/elasticsearch/AddUpdateExample.java
@@ -1,83 +1,83 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.aws.elasticsearch;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
-/**
- * Example: Amazon ElasticSearch service add/update record.
- * @author javaQuery
- * @date 14th January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class AddUpdateExample {
-
- public static void main(String[] args) throws UnsupportedEncodingException {
- /**
- * Amazon ElasticSearch Service URL:
- * endpoint + / + {index_name} + / + {type} + / + {id}
- */
- String elastic_search_url = "http://xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/simple/123";
-
- /* Record to add in elastic search */
- String jsonDocument = "{\"id\": \"123\", \"name\": \"Apple iPhone 6s\", \"stock\" : 10}";
-
- /* Convert jsonDocument to apache StringEntity */
- StringEntity payload = new StringEntity(jsonDocument);
-
- /* Prepare post request to add record */
- HttpPost httpPost = new HttpPost(elastic_search_url);
- /* Attach payload */
- httpPost.setEntity(payload);
- /* Execute post request */
- httpPostRequest(httpPost);
- }
-
- /**
- * Perform post request.
- * @param httpPost
- */
- public static void httpPostRequest(HttpPost httpPost) {
- /* Create object of CloseableHttpClient */
- CloseableHttpClient httpClient = HttpClients.createDefault();
-
- /* Response handler for after request execution */
- ResponseHandler responseHandler = new ResponseHandler() {
-
- @Override
- public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
- /* Get status code */
- int status = response.getStatusLine().getStatusCode();
- if (status >= 200 && status < 300) {
- /* Convert response to String */
- HttpEntity entity = response.getEntity();
- return entity != null ? EntityUtils.toString(entity) : null;
- } else {
- throw new ClientProtocolException("Unexpected response status: " + status);
- }
- }
- };
-
- try {
- /* Execute URL and attach after execution response handler */
- String strResponse = httpClient.execute(httpPost, responseHandler);
- /* Print the response */
- System.out.println("Response: " + strResponse);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.aws.elasticsearch;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+/**
+ * Example: Amazon ElasticSearch service add/update record.
+ * @author javaQuery
+ * @date 14th January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class AddUpdateExample {
+
+ public static void main(String[] args) throws UnsupportedEncodingException {
+ /**
+ * Amazon ElasticSearch Service URL:
+ * endpoint + / + {index_name} + / + {type} + / + {id}
+ */
+ String elastic_search_url = "http://xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/simple/123";
+
+ /* Record to add in elastic search */
+ String jsonDocument = "{\"id\": \"123\", \"name\": \"Apple iPhone 6s\", \"stock\" : 10}";
+
+ /* Convert jsonDocument to apache StringEntity */
+ StringEntity payload = new StringEntity(jsonDocument);
+
+ /* Prepare post request to add record */
+ HttpPost httpPost = new HttpPost(elastic_search_url);
+ /* Attach payload */
+ httpPost.setEntity(payload);
+ /* Execute post request */
+ httpPostRequest(httpPost);
+ }
+
+ /**
+ * Perform post request.
+ * @param httpPost
+ */
+ public static void httpPostRequest(HttpPost httpPost) {
+ /* Create object of CloseableHttpClient */
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+
+ /* Response handler for after request execution */
+ ResponseHandler responseHandler = new ResponseHandler() {
+
+ @Override
+ public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
+ /* Get status code */
+ int status = response.getStatusLine().getStatusCode();
+ if (status >= 200 && status < 300) {
+ /* Convert response to String */
+ HttpEntity entity = response.getEntity();
+ return entity != null ? EntityUtils.toString(entity) : null;
+ } else {
+ throw new ClientProtocolException("Unexpected response status: " + status);
+ }
+ }
+ };
+
+ try {
+ /* Execute URL and attach after execution response handler */
+ String strResponse = httpClient.execute(httpPost, responseHandler);
+ /* Print the response */
+ System.out.println("Response: " + strResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/com/javaquery/aws/elasticsearch/BulkAddUpdateExample.java b/src/main/java/com/javaquery/aws/elasticsearch/BulkAddUpdateExample.java
similarity index 97%
rename from src/com/javaquery/aws/elasticsearch/BulkAddUpdateExample.java
rename to src/main/java/com/javaquery/aws/elasticsearch/BulkAddUpdateExample.java
index dedfcbb..85f2808 100644
--- a/src/com/javaquery/aws/elasticsearch/BulkAddUpdateExample.java
+++ b/src/main/java/com/javaquery/aws/elasticsearch/BulkAddUpdateExample.java
@@ -1,97 +1,97 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.aws.elasticsearch;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
-/**
- * Example: Amazon ElasticSearch service bulk add/update record.
- * @author javaQuery
- * @date 14th January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class BulkAddUpdateExample {
- public static void main(String[] args) throws UnsupportedEncodingException {
- /**
- * Amazon ElasticSearch Service URL:
- * endpoint + / + {index_name} + / + _bulk
- */
- String elastic_search_url = "http://xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/_bulk";
-
- /**
- * Records to add in elastic search
- * Important Note: For elastic search bulk add and update, it should be in following format.
- *
- * {header} + {new_line} // Header for next line json document
- * {jsonDocument} + {new_line}
- * {header} + {new_line}
- * {jsonDocument} + {new_line}
- *
- * New line at the end of String is compulsory.
- */
- String header_one = "{\"index\":{\"_index\":\"inventory\",\"_type\":\"simple\",\"_id\":\"123\"}}\n";
- String jsonDocument_one = "{\"id\": \"123\", \"name\": \"Apple iPhone 6s\", \"stock\" : 10}\n";
- String header_two = "{\"index\":{\"_index\":\"inventory\",\"_type\":\"simple\",\"_id\":\"456\"}}\n";
- String jsonDocument_two = "{\"id\": \"456\", \"name\": \"Apple iPhone 5s\", \"stock\" : 15}\n";
-
- String jsonDocumentBulk = header_one + jsonDocument_one + header_two + jsonDocument_two;
-
- /* Convert jsonDocument to apache StringEntity */
- StringEntity payload = new StringEntity(jsonDocumentBulk);
-
- /* Prepare post request to add record */
- HttpPost httpPost = new HttpPost(elastic_search_url);
- /* Attach payload */
- httpPost.setEntity(payload);
- /* Execute post request */
- httpPostRequest(httpPost);
- }
-
- /**
- * Perform post request.
- * @param httpPost
- */
- public static void httpPostRequest(HttpPost httpPost) {
- /* Create object of CloseableHttpClient */
- CloseableHttpClient httpClient = HttpClients.createDefault();
-
- /* Response handler for after request execution */
- ResponseHandler responseHandler = new ResponseHandler() {
-
- @Override
- public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
- /* Get status code */
- int status = response.getStatusLine().getStatusCode();
- if (status >= 200 && status < 300) {
- /* Convert response to String */
- HttpEntity entity = response.getEntity();
- return entity != null ? EntityUtils.toString(entity) : null;
- } else {
- throw new ClientProtocolException("Unexpected response status: " + status);
- }
- }
- };
-
- try {
- /* Execute URL and attach after execution response handler */
- String strResponse = httpClient.execute(httpPost, responseHandler);
- /* Print the response */
- System.out.println("Response: " + strResponse);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.aws.elasticsearch;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+/**
+ * Example: Amazon ElasticSearch service bulk add/update record.
+ * @author javaQuery
+ * @date 14th January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class BulkAddUpdateExample {
+ public static void main(String[] args) throws UnsupportedEncodingException {
+ /**
+ * Amazon ElasticSearch Service URL:
+ * endpoint + / + {index_name} + / + _bulk
+ */
+ String elastic_search_url = "http://xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/_bulk";
+
+ /**
+ * Records to add in elastic search
+ * Important Note: For elastic search bulk add and update, it should be in following format.
+ *
+ * {header} + {new_line} // Header for next line json document
+ * {jsonDocument} + {new_line}
+ * {header} + {new_line}
+ * {jsonDocument} + {new_line}
+ *
+ * New line at the end of String is compulsory.
+ */
+ String header_one = "{\"index\":{\"_index\":\"inventory\",\"_type\":\"simple\",\"_id\":\"123\"}}\n";
+ String jsonDocument_one = "{\"id\": \"123\", \"name\": \"Apple iPhone 6s\", \"stock\" : 10}\n";
+ String header_two = "{\"index\":{\"_index\":\"inventory\",\"_type\":\"simple\",\"_id\":\"456\"}}\n";
+ String jsonDocument_two = "{\"id\": \"456\", \"name\": \"Apple iPhone 5s\", \"stock\" : 15}\n";
+
+ String jsonDocumentBulk = header_one + jsonDocument_one + header_two + jsonDocument_two;
+
+ /* Convert jsonDocument to apache StringEntity */
+ StringEntity payload = new StringEntity(jsonDocumentBulk);
+
+ /* Prepare post request to add record */
+ HttpPost httpPost = new HttpPost(elastic_search_url);
+ /* Attach payload */
+ httpPost.setEntity(payload);
+ /* Execute post request */
+ httpPostRequest(httpPost);
+ }
+
+ /**
+ * Perform post request.
+ * @param httpPost
+ */
+ public static void httpPostRequest(HttpPost httpPost) {
+ /* Create object of CloseableHttpClient */
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+
+ /* Response handler for after request execution */
+ ResponseHandler responseHandler = new ResponseHandler() {
+
+ @Override
+ public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
+ /* Get status code */
+ int status = response.getStatusLine().getStatusCode();
+ if (status >= 200 && status < 300) {
+ /* Convert response to String */
+ HttpEntity entity = response.getEntity();
+ return entity != null ? EntityUtils.toString(entity) : null;
+ } else {
+ throw new ClientProtocolException("Unexpected response status: " + status);
+ }
+ }
+ };
+
+ try {
+ /* Execute URL and attach after execution response handler */
+ String strResponse = httpClient.execute(httpPost, responseHandler);
+ /* Print the response */
+ System.out.println("Response: " + strResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/com/javaquery/aws/elasticsearch/DeleteExample.java b/src/main/java/com/javaquery/aws/elasticsearch/DeleteExample.java
similarity index 97%
rename from src/com/javaquery/aws/elasticsearch/DeleteExample.java
rename to src/main/java/com/javaquery/aws/elasticsearch/DeleteExample.java
index 0e095f8..d6bb8f3 100644
--- a/src/com/javaquery/aws/elasticsearch/DeleteExample.java
+++ b/src/main/java/com/javaquery/aws/elasticsearch/DeleteExample.java
@@ -1,73 +1,73 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.aws.elasticsearch;
-
-import java.io.IOException;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
-/**
- * Example: Amazon ElasticSearch service delete record.
- * @author javaQuery
- * @date 14th January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class DeleteExample {
-
- public static void main(String[] args) {
- /**
- * Amazon ElasticSearch Service URL:
- * endpoint + / + {index_name} + / + {type} + / + {id}
- */
- String elastic_search_url = "http://xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/simple/123";
-
- /* Prepare delete request */
- HttpDelete httpDelete = new HttpDelete(elastic_search_url);
- /* Execute delete request */
- httpDeleteRequest(httpDelete);
- }
-
- /**
- * Perform delete request.
- * @param httpDelete
- */
- public static void httpDeleteRequest(HttpDelete httpDelete) {
- /* Create object of CloseableHttpClient */
- CloseableHttpClient httpClient = HttpClients.createDefault();
-
- /* Response handler for after request execution */
- ResponseHandler responseHandler = new ResponseHandler() {
-
- @Override
- public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
- /* Get status code */
- int status = response.getStatusLine().getStatusCode();
- if (status >= 200 && status < 300) {
- /* Convert response to String */
- HttpEntity entity = response.getEntity();
- return entity != null ? EntityUtils.toString(entity) : null;
- } else {
- throw new ClientProtocolException("Unexpected response status: " + status);
- }
- }
- };
-
- try {
- /* Execute URL and attach after execution response handler */
- String strResponse = httpClient.execute(httpDelete, responseHandler);
- /* Print the response */
- System.out.println("Response: " + strResponse);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.aws.elasticsearch;
+
+import java.io.IOException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+/**
+ * Example: Amazon ElasticSearch service delete record.
+ * @author javaQuery
+ * @date 14th January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class DeleteExample {
+
+ public static void main(String[] args) {
+ /**
+ * Amazon ElasticSearch Service URL:
+ * endpoint + / + {index_name} + / + {type} + / + {id}
+ */
+ String elastic_search_url = "http://xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/simple/123";
+
+ /* Prepare delete request */
+ HttpDelete httpDelete = new HttpDelete(elastic_search_url);
+ /* Execute delete request */
+ httpDeleteRequest(httpDelete);
+ }
+
+ /**
+ * Perform delete request.
+ * @param httpDelete
+ */
+ public static void httpDeleteRequest(HttpDelete httpDelete) {
+ /* Create object of CloseableHttpClient */
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+
+ /* Response handler for after request execution */
+ ResponseHandler responseHandler = new ResponseHandler() {
+
+ @Override
+ public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
+ /* Get status code */
+ int status = response.getStatusLine().getStatusCode();
+ if (status >= 200 && status < 300) {
+ /* Convert response to String */
+ HttpEntity entity = response.getEntity();
+ return entity != null ? EntityUtils.toString(entity) : null;
+ } else {
+ throw new ClientProtocolException("Unexpected response status: " + status);
+ }
+ }
+ };
+
+ try {
+ /* Execute URL and attach after execution response handler */
+ String strResponse = httpClient.execute(httpDelete, responseHandler);
+ /* Print the response */
+ System.out.println("Response: " + strResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/com/javaquery/aws/elasticsearch/GetExample.java b/src/main/java/com/javaquery/aws/elasticsearch/GetExample.java
similarity index 97%
rename from src/com/javaquery/aws/elasticsearch/GetExample.java
rename to src/main/java/com/javaquery/aws/elasticsearch/GetExample.java
index 021d25e..a507ade 100644
--- a/src/com/javaquery/aws/elasticsearch/GetExample.java
+++ b/src/main/java/com/javaquery/aws/elasticsearch/GetExample.java
@@ -1,73 +1,73 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.aws.elasticsearch;
-
-import java.io.IOException;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
-/**
- * Example: Amazon ElasticSearch service get record.
- * @author javaQuery
- * @date 14th January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class GetExample {
-
- public static void main(String[] args) {
- /**
- * Amazon ElasticSearch Service URL:
- * endpoint + / + {index_name} + / + {type} + / + {id}
- */
- String elastic_search_url = "http://xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/simple/123";
-
- /* Prepare get request */
- HttpGet httpGet = new HttpGet(elastic_search_url);
- /* Execute get request */
- httpGetRequest(httpGet);
- }
-
- /**
- * Perform get request.
- * @param httpGet
- */
- public static void httpGetRequest(HttpGet httpGet) {
- /* Create object of CloseableHttpClient */
- CloseableHttpClient httpClient = HttpClients.createDefault();
-
- /* Response handler for after request execution */
- ResponseHandler responseHandler = new ResponseHandler() {
-
- @Override
- public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
- /* Get status code */
- int status = response.getStatusLine().getStatusCode();
- if (status >= 200 && status < 300) {
- /* Convert response to String */
- HttpEntity entity = response.getEntity();
- return entity != null ? EntityUtils.toString(entity) : null;
- } else {
- throw new ClientProtocolException("Unexpected response status: " + status);
- }
- }
- };
-
- try {
- /* Execute URL and attach after execution response handler */
- String strResponse = httpClient.execute(httpGet, responseHandler);
- /* Print the response */
- System.out.println("Response: " + strResponse);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.aws.elasticsearch;
+
+import java.io.IOException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+/**
+ * Example: Amazon ElasticSearch service get record.
+ * @author javaQuery
+ * @date 14th January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class GetExample {
+
+ public static void main(String[] args) {
+ /**
+ * Amazon ElasticSearch Service URL:
+ * endpoint + / + {index_name} + / + {type} + / + {id}
+ */
+ String elastic_search_url = "http://xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/simple/123";
+
+ /* Prepare get request */
+ HttpGet httpGet = new HttpGet(elastic_search_url);
+ /* Execute get request */
+ httpGetRequest(httpGet);
+ }
+
+ /**
+ * Perform get request.
+ * @param httpGet
+ */
+ public static void httpGetRequest(HttpGet httpGet) {
+ /* Create object of CloseableHttpClient */
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+
+ /* Response handler for after request execution */
+ ResponseHandler responseHandler = new ResponseHandler() {
+
+ @Override
+ public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
+ /* Get status code */
+ int status = response.getStatusLine().getStatusCode();
+ if (status >= 200 && status < 300) {
+ /* Convert response to String */
+ HttpEntity entity = response.getEntity();
+ return entity != null ? EntityUtils.toString(entity) : null;
+ } else {
+ throw new ClientProtocolException("Unexpected response status: " + status);
+ }
+ }
+ };
+
+ try {
+ /* Execute URL and attach after execution response handler */
+ String strResponse = httpClient.execute(httpGet, responseHandler);
+ /* Print the response */
+ System.out.println("Response: " + strResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/com/javaquery/aws/test/AWSV4AuthTest.java b/src/main/java/com/javaquery/aws/test/AWSV4AuthTest.java
similarity index 97%
rename from src/com/javaquery/aws/test/AWSV4AuthTest.java
rename to src/main/java/com/javaquery/aws/test/AWSV4AuthTest.java
index 6844b30..a8eecbd 100644
--- a/src/com/javaquery/aws/test/AWSV4AuthTest.java
+++ b/src/main/java/com/javaquery/aws/test/AWSV4AuthTest.java
@@ -1,54 +1,54 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.aws.test;
-
-import com.javaquery.aws.AWSV4Auth;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * Example: Signing AWS Requests with Signature Version 4 in Java(Test class).
- * @reference: http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
- * @author javaQuery
- * @date 19th January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class AWSV4AuthTest {
- public static void main(String[] args) {
- String url = "xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/simple/123";
-
- /**
- * Add host without http or https protocol.
- * You can also add other parameters based on your amazon service requirement.
- */
- TreeMap awsHeaders = new TreeMap();
- awsHeaders.put("host", "xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com");
-
- AWSV4Auth aWSV4Auth = new AWSV4Auth.Builder("exampleKey", "exampleSecret")
- .regionName("xx-yy-zzz")
- .serviceName("es") // es - elastic search. use your service name
- .httpMethodName("GET") //GET, PUT, POST, DELETE, etc...
- .canonicalURI("/inventory/simple/123") //end point
- .queryParametes(null) //query parameters if any
- .awsHeaders(awsHeaders) //aws header parameters
- .payload(null) // payload if any
- .debug() // turn on the debug mode
- .build();
-
- /* Get header calculated for request */
- Map header = aWSV4Auth.getHeaders();
- for (Map.Entry entrySet : header.entrySet()) {
- String key = entrySet.getKey();
- String value = entrySet.getValue();
-
- /* Attach header in your request */
- /* Simple get request */
- //HttpGet httpGet = new HttpGet(url);
- //httpGet.addHeader(key, value);
- }
- // execute httpGet
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.aws.test;
+
+import com.javaquery.aws.AWSV4Auth;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * Example: Signing AWS Requests with Signature Version 4 in Java(Test class).
+ * @reference: http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
+ * @author javaQuery
+ * @date 19th January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class AWSV4AuthTest {
+ public static void main(String[] args) {
+ String url = "xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com/inventory/simple/123";
+
+ /**
+ * Add host without http or https protocol.
+ * You can also add other parameters based on your amazon service requirement.
+ */
+ TreeMap awsHeaders = new TreeMap();
+ awsHeaders.put("host", "xxxxx-yyyyy-r6nvlhpscgdwms5.ap-northeast-1.es.amazonaws.com");
+
+ AWSV4Auth aWSV4Auth = new AWSV4Auth.Builder("exampleKey", "exampleSecret")
+ .regionName("xx-yy-zzz")
+ .serviceName("es") // es - elastic search. use your service name
+ .httpMethodName("GET") //GET, PUT, POST, DELETE, etc...
+ .canonicalURI("/inventory/simple/123") //end point
+ .queryParametes(null) //query parameters if any
+ .awsHeaders(awsHeaders) //aws header parameters
+ .payload(null) // payload if any
+ .debug() // turn on the debug mode
+ .build();
+
+ /* Get header calculated for request */
+ Map header = aWSV4Auth.getHeaders();
+ for (Map.Entry entrySet : header.entrySet()) {
+ String key = entrySet.getKey();
+ String value = entrySet.getValue();
+
+ /* Attach header in your request */
+ /* Simple get request */
+ //HttpGet httpGet = new HttpGet(url);
+ //httpGet.addHeader(key, value);
+ }
+ // execute httpGet
+ }
+}
diff --git a/src/com/javaquery/bean/Capital.java b/src/main/java/com/javaquery/bean/Capital.java
similarity index 95%
rename from src/com/javaquery/bean/Capital.java
rename to src/main/java/com/javaquery/bean/Capital.java
index 9c5d199..3f454f2 100644
--- a/src/com/javaquery/bean/Capital.java
+++ b/src/main/java/com/javaquery/bean/Capital.java
@@ -1,66 +1,66 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.bean;
-
-import java.io.Serializable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-
-/**
- * @author javaQuery
- * @date 11th April, 2017
- * @Github: https://github.com/javaquery/Examples
- */
-@Entity
-@Table(name = "capital")
-public class Capital implements Serializable{
-
- @Id
- @GeneratedValue
- @Column(name = "id")
- private Long id;
-
- @Column(name = "name")
- private String name;
-
- @OneToOne
- @JoinColumn(referencedColumnName = "id", name = "country_id")
- private Country country;
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Country getCountry() {
- return country;
- }
-
- public void setCountry(Country country) {
- this.country = country;
- }
-
- @Override
- public String toString() {
- return "Capital{" + "id=" + id + ", name=" + name + '}';
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.bean;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+/**
+ * @author javaQuery
+ * @date 11th April, 2017
+ * @Github: https://github.com/javaquery/Examples
+ */
+@Entity
+@Table(name = "capital")
+public class Capital implements Serializable{
+
+ @Id
+ @GeneratedValue
+ @Column(name = "id")
+ private Long id;
+
+ @Column(name = "name")
+ private String name;
+
+ @OneToOne
+ @JoinColumn(referencedColumnName = "id", name = "country_id")
+ private Country country;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Country getCountry() {
+ return country;
+ }
+
+ public void setCountry(Country country) {
+ this.country = country;
+ }
+
+ @Override
+ public String toString() {
+ return "Capital{" + "id=" + id + ", name=" + name + '}';
+ }
+}
diff --git a/src/com/javaquery/bean/ComparableItem.java b/src/main/java/com/javaquery/bean/ComparableItem.java
similarity index 95%
rename from src/com/javaquery/bean/ComparableItem.java
rename to src/main/java/com/javaquery/bean/ComparableItem.java
index 1ffc6a0..b018f5f 100644
--- a/src/com/javaquery/bean/ComparableItem.java
+++ b/src/main/java/com/javaquery/bean/ComparableItem.java
@@ -1,47 +1,47 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.bean;
-
-/**
- * Comparable item.
- * @author javaQuery
- * @date 11th August, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class ComparableItem implements Comparable{
-
- private String name;
- private Double price;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Double getPrice() {
- return price;
- }
-
- public void setPrice(Double price) {
- this.price = price;
- }
-
- @Override
- public int compareTo(ComparableItem item) {
- if(item != null && item.getName() != null){
- return this.getName().compareTo(item.getName());
- }
- return -1;
- }
-
- @Override
- public String toString() {
- return "ComparableItem{" + "name=" + name + ", price=" + price + '}';
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.bean;
+
+/**
+ * Comparable item.
+ * @author javaQuery
+ * @date 11th August, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class ComparableItem implements Comparable{
+
+ private String name;
+ private Double price;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Double getPrice() {
+ return price;
+ }
+
+ public void setPrice(Double price) {
+ this.price = price;
+ }
+
+ @Override
+ public int compareTo(ComparableItem item) {
+ if(item != null && item.getName() != null){
+ return this.getName().compareTo(item.getName());
+ }
+ return -1;
+ }
+
+ @Override
+ public String toString() {
+ return "ComparableItem{" + "name=" + name + ", price=" + price + '}';
+ }
+}
diff --git a/src/com/javaquery/bean/Country.java b/src/main/java/com/javaquery/bean/Country.java
similarity index 95%
rename from src/com/javaquery/bean/Country.java
rename to src/main/java/com/javaquery/bean/Country.java
index 0fc40dd..ff05993 100644
--- a/src/com/javaquery/bean/Country.java
+++ b/src/main/java/com/javaquery/bean/Country.java
@@ -1,92 +1,92 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.bean;
-
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.Set;
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToMany;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-
-/**
- * @author javaQuery
- * @date 11th April, 2017
- * @Github: https://github.com/javaquery/Examples
- */
-@Entity
-@Table(name = "country")
-public class Country implements Serializable {
-
- @Id
- @GeneratedValue
- @Column(name = "id")
- private Long id;
-
- @Column(name = "name")
- private String name;
-
- @OneToOne(cascade = CascadeType.ALL, mappedBy = "country")
- private Capital capital;
-
- @OneToOne
- @JoinColumn(name = "primary_language_id", referencedColumnName = "id")
- private Language language;
-
- @OneToMany(mappedBy = "country" /*, fetch = FetchType.LAZY*/)
- Set states = new HashSet();
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Capital getCapital() {
- return capital;
- }
-
- public void setCapital(Capital capital) {
- this.capital = capital;
- }
-
- public Language getLanguage() {
- return language;
- }
-
- public void setLanguage(Language language) {
- this.language = language;
- }
-
- public Set getStates() {
- return states;
- }
-
- public void setStates(Set states) {
- this.states = states;
- }
-
- @Override
- public String toString() {
- return "Country{" + "id=" + id + ", name=" + name + ", capital=" + capital + ", language=" + language + '}';
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.bean;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+/**
+ * @author javaQuery
+ * @date 11th April, 2017
+ * @Github: https://github.com/javaquery/Examples
+ */
+@Entity
+@Table(name = "country")
+public class Country implements Serializable {
+
+ @Id
+ @GeneratedValue
+ @Column(name = "id")
+ private Long id;
+
+ @Column(name = "name")
+ private String name;
+
+ @OneToOne(cascade = CascadeType.ALL, mappedBy = "country")
+ private Capital capital;
+
+ @OneToOne
+ @JoinColumn(name = "primary_language_id", referencedColumnName = "id")
+ private Language language;
+
+ @OneToMany(mappedBy = "country" /*, fetch = FetchType.LAZY*/)
+ Set states = new HashSet();
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Capital getCapital() {
+ return capital;
+ }
+
+ public void setCapital(Capital capital) {
+ this.capital = capital;
+ }
+
+ public Language getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(Language language) {
+ this.language = language;
+ }
+
+ public Set getStates() {
+ return states;
+ }
+
+ public void setStates(Set states) {
+ this.states = states;
+ }
+
+ @Override
+ public String toString() {
+ return "Country{" + "id=" + id + ", name=" + name + ", capital=" + capital + ", language=" + language + '}';
+ }
+}
diff --git a/src/com/javaquery/bean/Item.java b/src/main/java/com/javaquery/bean/Item.java
similarity index 95%
rename from src/com/javaquery/bean/Item.java
rename to src/main/java/com/javaquery/bean/Item.java
index 5f3a8f4..54330e9 100644
--- a/src/com/javaquery/bean/Item.java
+++ b/src/main/java/com/javaquery/bean/Item.java
@@ -1,78 +1,78 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.bean;
-
-import java.util.Comparator;
-
-public class Item {
-
- private Long id;
- private String name;
- private Double price;
-
- public Item() {
- }
-
- public Item(String name, Double price) {
- this.name = name;
- this.price = price;
- }
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Double getPrice() {
- return price;
- }
-
- public void setPrice(Double price) {
- this.price = price;
- }
-
- public Comparator- orderByNameASC(){
- return new Comparator
- () {
- @Override
- public int compare(Item o1, Item o2) {
- if(o1 != null && o1.getName() != null
- && o2 != null && o2.getName() != null){
- return o1.getName().compareTo(o2.getName());
- }
- return -1;
- }
- };
- }
-
- public Comparator
- orderByNameDESC(){
- return new Comparator
- () {
- @Override
- public int compare(Item o1, Item o2) {
- if(o1 != null && o1.getName() != null
- && o2 != null && o2.getName() != null){
- return o2.getName().compareTo(o1.getName());
- }
- return -1;
- }
- };
- }
-
- @Override
- public String toString() {
- return "Item{" + "name=" + name + ", price=" + price + '}';
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.bean;
+
+import java.util.Comparator;
+
+public class Item {
+
+ private Long id;
+ private String name;
+ private Double price;
+
+ public Item() {
+ }
+
+ public Item(String name, Double price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Double getPrice() {
+ return price;
+ }
+
+ public void setPrice(Double price) {
+ this.price = price;
+ }
+
+ public Comparator
- orderByNameASC(){
+ return new Comparator
- () {
+ @Override
+ public int compare(Item o1, Item o2) {
+ if(o1 != null && o1.getName() != null
+ && o2 != null && o2.getName() != null){
+ return o1.getName().compareTo(o2.getName());
+ }
+ return -1;
+ }
+ };
+ }
+
+ public Comparator
- orderByNameDESC(){
+ return new Comparator
- () {
+ @Override
+ public int compare(Item o1, Item o2) {
+ if(o1 != null && o1.getName() != null
+ && o2 != null && o2.getName() != null){
+ return o2.getName().compareTo(o1.getName());
+ }
+ return -1;
+ }
+ };
+ }
+
+ @Override
+ public String toString() {
+ return "Item{" + "name=" + name + ", price=" + price + '}';
+ }
+}
diff --git a/src/com/javaquery/bean/Language.java b/src/main/java/com/javaquery/bean/Language.java
similarity index 95%
rename from src/com/javaquery/bean/Language.java
rename to src/main/java/com/javaquery/bean/Language.java
index f5bf8f6..2d06ec0 100644
--- a/src/com/javaquery/bean/Language.java
+++ b/src/main/java/com/javaquery/bean/Language.java
@@ -1,51 +1,51 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.bean;
-
-import java.io.Serializable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-/**
- * @author javaQuery
- * @date 1th April, 2017
- * @Github: https://github.com/javaquery/Examples
- */
-@Entity
-@Table(name = "languages")
-public class Language implements Serializable{
- @Id
- @GeneratedValue
- @Column(name = "id")
- private Long id;
-
- @Column(name = "language")
- private String language;
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public String getLanguage() {
- return language;
- }
-
- public void setLanguage(String language) {
- this.language = language;
- }
-
- @Override
- public String toString() {
- return "Language{" + "id=" + id + ", language=" + language + '}';
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.bean;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * @author javaQuery
+ * @date 1th April, 2017
+ * @Github: https://github.com/javaquery/Examples
+ */
+@Entity
+@Table(name = "languages")
+public class Language implements Serializable{
+ @Id
+ @GeneratedValue
+ @Column(name = "id")
+ private Long id;
+
+ @Column(name = "language")
+ private String language;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ @Override
+ public String toString() {
+ return "Language{" + "id=" + id + ", language=" + language + '}';
+ }
+}
diff --git a/src/com/javaquery/bean/State.java b/src/main/java/com/javaquery/bean/State.java
similarity index 95%
rename from src/com/javaquery/bean/State.java
rename to src/main/java/com/javaquery/bean/State.java
index 53ecb11..122bb55 100644
--- a/src/com/javaquery/bean/State.java
+++ b/src/main/java/com/javaquery/bean/State.java
@@ -1,62 +1,62 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.bean;
-
-import java.io.Serializable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-
-/**
- * @author javaQuery
- * @date 15th June, 2017
- * @Github: https://github.com/javaquery/Examples
- */
-@Entity
-@Table(name = "state")
-public class State implements Serializable{
-
- @Id
- @GeneratedValue
- @Column(name = "id")
- private Long id;
-
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "country_id")
- private Country country;
-
- @Column(name = "name")
- private String name;
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public Country getCountry() {
- return country;
- }
-
- public void setCountry(Country country) {
- this.country = country;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.bean;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+/**
+ * @author javaQuery
+ * @date 15th June, 2017
+ * @Github: https://github.com/javaquery/Examples
+ */
+@Entity
+@Table(name = "state")
+public class State implements Serializable{
+
+ @Id
+ @GeneratedValue
+ @Column(name = "id")
+ private Long id;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "country_id")
+ private Country country;
+
+ @Column(name = "name")
+ private String name;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Country getCountry() {
+ return country;
+ }
+
+ public void setCountry(Country country) {
+ this.country = country;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/src/com/javaquery/collections/list/InitializeListExample.java b/src/main/java/com/javaquery/collections/list/InitializeListExample.java
similarity index 96%
rename from src/com/javaquery/collections/list/InitializeListExample.java
rename to src/main/java/com/javaquery/collections/list/InitializeListExample.java
index 0acf24e..e0aea30 100644
--- a/src/com/javaquery/collections/list/InitializeListExample.java
+++ b/src/main/java/com/javaquery/collections/list/InitializeListExample.java
@@ -1,39 +1,39 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.collections.list;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Initialize List in its declaration.
- * @author javaQuery
- * @date 29th October, 2015
- * @Github: https://github.com/javaquery/Examples
- */
-public class InitializeListExample {
-
- public static void main(String[] args) {
- /* Declare and Initialize List of Integer */
- List listIntegers = new ArrayList(Arrays.asList(10, 20, 30));
-
- System.out.println("Print value of List");
- /* Print value of List */
- for (Integer integer : listIntegers) {
- System.out.println(integer);
- }
-
- /* Declare and Initialize List of String */
- List listStrings = new ArrayList(Arrays.asList("Chirag", "Yogita", "Vicky", "Heer"));
-
- System.out.println("Print value of List");
- /* Print value of List */
- for (String string : listStrings) {
- System.out.println(string);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.collections.list;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Initialize List in its declaration.
+ * @author javaQuery
+ * @date 29th October, 2015
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class InitializeListExample {
+
+ public static void main(String[] args) {
+ /* Declare and Initialize List of Integer */
+ List listIntegers = new ArrayList(Arrays.asList(10, 20, 30));
+
+ System.out.println("Print value of List");
+ /* Print value of List */
+ for (Integer integer : listIntegers) {
+ System.out.println(integer);
+ }
+
+ /* Declare and Initialize List of String */
+ List listStrings = new ArrayList(Arrays.asList("Chirag", "Yogita", "Vicky", "Heer"));
+
+ System.out.println("Print value of List");
+ /* Print value of List */
+ for (String string : listStrings) {
+ System.out.println(string);
+ }
+ }
+}
diff --git a/src/com/javaquery/collections/list/ListStreamSum.java b/src/main/java/com/javaquery/collections/list/ListStreamSum.java
similarity index 96%
rename from src/com/javaquery/collections/list/ListStreamSum.java
rename to src/main/java/com/javaquery/collections/list/ListStreamSum.java
index c397471..0039b5f 100644
--- a/src/com/javaquery/collections/list/ListStreamSum.java
+++ b/src/main/java/com/javaquery/collections/list/ListStreamSum.java
@@ -1,38 +1,38 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.collections.list;
-
-import com.javaquery.bean.Item;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Summation of element in List using Stream api in java 8.
- *
- * @author javaQuery
- * @date 17th October, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class ListStreamSum {
-
- public static void main(String[] args) {
- /* Summation of Integers in List */
- List integers = new ArrayList<>(Arrays.asList(10, 20, 30));
-
- Integer integerSum = integers.stream().mapToInt(Integer::intValue).sum();
- System.out.println("summation: " + integerSum);
-
- /* Summation when you have list of beans */
- Item motoG = new Item("MotoG", 100.12);
- Item iPhone = new Item("iPhone", 200.12);
-
- List
- listBeans = new ArrayList<>(Arrays.asList(motoG, iPhone));
-
- Double doubleSum = listBeans.stream().mapToDouble(Item::getPrice).sum();
- System.out.println("summation: " + doubleSum);
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.collections.list;
+
+import com.javaquery.bean.Item;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Summation of element in List using Stream api in java 8.
+ *
+ * @author javaQuery
+ * @date 17th October, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class ListStreamSum {
+
+ public static void main(String[] args) {
+ /* Summation of Integers in List */
+ List integers = new ArrayList<>(Arrays.asList(10, 20, 30));
+
+ Integer integerSum = integers.stream().mapToInt(Integer::intValue).sum();
+ System.out.println("summation: " + integerSum);
+
+ /* Summation when you have list of beans */
+ Item motoG = new Item("MotoG", 100.12);
+ Item iPhone = new Item("iPhone", 200.12);
+
+ List
- listBeans = new ArrayList<>(Arrays.asList(motoG, iPhone));
+
+ Double doubleSum = listBeans.stream().mapToDouble(Item::getPrice).sum();
+ System.out.println("summation: " + doubleSum);
+ }
+}
diff --git a/src/com/javaquery/collections/list/SetToList.java b/src/main/java/com/javaquery/collections/list/SetToList.java
similarity index 96%
rename from src/com/javaquery/collections/list/SetToList.java
rename to src/main/java/com/javaquery/collections/list/SetToList.java
index 98ff68b..aac4c19 100644
--- a/src/com/javaquery/collections/list/SetToList.java
+++ b/src/main/java/com/javaquery/collections/list/SetToList.java
@@ -1,37 +1,37 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.collections.list;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Set to List example.
- *
- * @author javaQuery
- * @date 7th October, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class SetToList {
-
- public static void main(String[] args) {
- /* Create set of string */
- Set strings = new HashSet();
- strings.add("A");
- strings.add("B");
-
- /**
- * new ArrayList(Collection extends E> c) We created List of String so
- * we can initialize ArrayList using any collection that extends String.
- */
- List list = new ArrayList<>(strings);
- for (String string : list) {
- System.out.println(string);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.collections.list;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Set to List example.
+ *
+ * @author javaQuery
+ * @date 7th October, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class SetToList {
+
+ public static void main(String[] args) {
+ /* Create set of string */
+ Set strings = new HashSet();
+ strings.add("A");
+ strings.add("B");
+
+ /**
+ * new ArrayList(Collection extends E> c) We created List of String so
+ * we can initialize ArrayList using any collection that extends String.
+ */
+ List list = new ArrayList<>(strings);
+ for (String string : list) {
+ System.out.println(string);
+ }
+ }
+}
diff --git a/src/com/javaquery/collections/map/FailFastExample.java b/src/main/java/com/javaquery/collections/map/FailFastExample.java
similarity index 96%
rename from src/com/javaquery/collections/map/FailFastExample.java
rename to src/main/java/com/javaquery/collections/map/FailFastExample.java
index 33eaf20..257508a 100644
--- a/src/com/javaquery/collections/map/FailFastExample.java
+++ b/src/main/java/com/javaquery/collections/map/FailFastExample.java
@@ -1,32 +1,32 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.collections.map;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Example of Fail Fast using Map.
- * @author javaQuery
- * @date 4th August, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class FailFastExample {
- public static void main(String[] args) {
- Map carPrice = new HashMap();
- carPrice.put("Porsche", 100000D);
- carPrice.put("Ferrari", 200000D);
-
- /* Iterate over Map */
- for(Map.Entry car : carPrice.entrySet()){
- System.out.println("Car: " + car.getKey());
- System.out.println("Price: " + car.getValue());
-
- /* Will cause java.util.ConcurrentModificationException */
- carPrice.put("Lamborghini", 300000D);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.collections.map;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Example of Fail Fast using Map.
+ * @author javaQuery
+ * @date 4th August, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class FailFastExample {
+ public static void main(String[] args) {
+ Map carPrice = new HashMap();
+ carPrice.put("Porsche", 100000D);
+ carPrice.put("Ferrari", 200000D);
+
+ /* Iterate over Map */
+ for(Map.Entry car : carPrice.entrySet()){
+ System.out.println("Car: " + car.getKey());
+ System.out.println("Price: " + car.getValue());
+
+ /* Will cause java.util.ConcurrentModificationException */
+ carPrice.put("Lamborghini", 300000D);
+ }
+ }
+}
diff --git a/src/com/javaquery/collections/map/FailSafeExample.java b/src/main/java/com/javaquery/collections/map/FailSafeExample.java
similarity index 97%
rename from src/com/javaquery/collections/map/FailSafeExample.java
rename to src/main/java/com/javaquery/collections/map/FailSafeExample.java
index 8d300dc..8ac1bf6 100644
--- a/src/com/javaquery/collections/map/FailSafeExample.java
+++ b/src/main/java/com/javaquery/collections/map/FailSafeExample.java
@@ -1,35 +1,35 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.collections.map;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Example of Fail Safe using ConcurrentHashMap.
- * @author javaQuery
- * @date 4th August, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class FailSafeExample {
-
- public static void main(String[] args) {
- Map carPrice = new ConcurrentHashMap();
- carPrice.put("Porsche", 100000D);
- carPrice.put("Ferrari", 200000D);
-
- /* Iterate over Map */
- for (Map.Entry car : carPrice.entrySet()) {
- System.out.println("Car: " + car.getKey());
- System.out.println("Price: " + car.getValue());
-
- /* Will be added in original copy of Map but won't available in Iterator */
- carPrice.put("Lamborghini", 300000D);
- }
- System.out.println("=== loop finished ===");
- System.out.println("Car: Lamborghini" + ", Price: " + carPrice.get("Lamborghini"));
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.collections.map;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Example of Fail Safe using ConcurrentHashMap.
+ * @author javaQuery
+ * @date 4th August, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class FailSafeExample {
+
+ public static void main(String[] args) {
+ Map carPrice = new ConcurrentHashMap();
+ carPrice.put("Porsche", 100000D);
+ carPrice.put("Ferrari", 200000D);
+
+ /* Iterate over Map */
+ for (Map.Entry car : carPrice.entrySet()) {
+ System.out.println("Car: " + car.getKey());
+ System.out.println("Price: " + car.getValue());
+
+ /* Will be added in original copy of Map but won't available in Iterator */
+ carPrice.put("Lamborghini", 300000D);
+ }
+ System.out.println("=== loop finished ===");
+ System.out.println("Car: Lamborghini" + ", Price: " + carPrice.get("Lamborghini"));
+ }
+}
diff --git a/src/com/javaquery/collections/map/LinkedHashMapExample.java b/src/main/java/com/javaquery/collections/map/LinkedHashMapExample.java
similarity index 100%
rename from src/com/javaquery/collections/map/LinkedHashMapExample.java
rename to src/main/java/com/javaquery/collections/map/LinkedHashMapExample.java
diff --git a/src/com/javaquery/collections/map/MapStreamSum.java b/src/main/java/com/javaquery/collections/map/MapStreamSum.java
similarity index 97%
rename from src/com/javaquery/collections/map/MapStreamSum.java
rename to src/main/java/com/javaquery/collections/map/MapStreamSum.java
index 47007a5..ce025c8 100644
--- a/src/com/javaquery/collections/map/MapStreamSum.java
+++ b/src/main/java/com/javaquery/collections/map/MapStreamSum.java
@@ -1,57 +1,57 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.collections.map;
-
-import com.javaquery.bean.Item;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Summation of element in Map using Stream api in java 8.
- *
- * @author javaQuery
- * @date 17th October, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class MapStreamSum {
-
- public static void main(String[] args) {
- /* Summation of Integers in Map */
- Map integers = new HashMap<>();
- integers.put("A", 10);
- integers.put("B", 20);
- integers.put("C", 30);
-
- Integer integerSum = integers.values().stream().mapToInt(Integer::intValue).sum();
- System.out.println("summation: " + integerSum);
-
- /* Summation when you have List/Set in Map */
- Map> listInMap = new HashMap<>();
- listInMap.put("even_numbers", new ArrayList<>(Arrays.asList(2, 4, 6)));
-
- integerSum = listInMap.values().stream()
- .flatMapToInt(list -> list.stream().mapToInt(Integer::intValue))
- .sum();
- System.out.println("summation: " + integerSum);
-
- /* Summation when you have List/Set of beans in Map */
- Item motoG = new Item("MotoG", 100.12);
- Item iPhone = new Item("iPhone", 200.12);
-
- List
- items = new ArrayList<>(Arrays.asList(motoG, iPhone));
-
- Map> itemMap = new HashMap<>();
- itemMap.put("items", items);
-
- Double doubleSum = itemMap.values().stream()
- .flatMapToDouble(list -> list.stream().mapToDouble(Item::getPrice))
- .sum();
- System.out.println("summation: " + doubleSum);
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.collections.map;
+
+import com.javaquery.bean.Item;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Summation of element in Map using Stream api in java 8.
+ *
+ * @author javaQuery
+ * @date 17th October, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class MapStreamSum {
+
+ public static void main(String[] args) {
+ /* Summation of Integers in Map */
+ Map integers = new HashMap<>();
+ integers.put("A", 10);
+ integers.put("B", 20);
+ integers.put("C", 30);
+
+ Integer integerSum = integers.values().stream().mapToInt(Integer::intValue).sum();
+ System.out.println("summation: " + integerSum);
+
+ /* Summation when you have List/Set in Map */
+ Map> listInMap = new HashMap<>();
+ listInMap.put("even_numbers", new ArrayList<>(Arrays.asList(2, 4, 6)));
+
+ integerSum = listInMap.values().stream()
+ .flatMapToInt(list -> list.stream().mapToInt(Integer::intValue))
+ .sum();
+ System.out.println("summation: " + integerSum);
+
+ /* Summation when you have List/Set of beans in Map */
+ Item motoG = new Item("MotoG", 100.12);
+ Item iPhone = new Item("iPhone", 200.12);
+
+ List
- items = new ArrayList<>(Arrays.asList(motoG, iPhone));
+
+ Map> itemMap = new HashMap<>();
+ itemMap.put("items", items);
+
+ Double doubleSum = itemMap.values().stream()
+ .flatMapToDouble(list -> list.stream().mapToDouble(Item::getPrice))
+ .sum();
+ System.out.println("summation: " + doubleSum);
+ }
+}
diff --git a/src/com/javaquery/collections/set/InitializeSetExample.java b/src/main/java/com/javaquery/collections/set/InitializeSetExample.java
similarity index 96%
rename from src/com/javaquery/collections/set/InitializeSetExample.java
rename to src/main/java/com/javaquery/collections/set/InitializeSetExample.java
index 4e254cf..3207b34 100644
--- a/src/com/javaquery/collections/set/InitializeSetExample.java
+++ b/src/main/java/com/javaquery/collections/set/InitializeSetExample.java
@@ -1,38 +1,38 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.collections.set;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Initialize Set in its declaration.
- * @author javaQuery
- * @date 29th October, 2015
- * @Github: https://github.com/javaquery/Examples
- */
-public class InitializeSetExample {
- public static void main(String[] args) {
- /* Declare and Initialize Set of Integer */
- Set setIntegers = new HashSet(Arrays.asList(10, 20, 30));
-
- System.out.println("Print value of Set");
- /* Print value of Set */
- for (Integer integer : setIntegers) {
- System.out.println(integer);
- }
-
- /* Declare and Initialize Set of String */
- Set setStrings = new HashSet<>(Arrays.asList("Chirag", "Yogita", "Vicky", "Heer"));
-
- System.out.println("Print value of Set");
- /* Print value of Set */
- for (String string : setStrings) {
- System.out.println(string);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.collections.set;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Initialize Set in its declaration.
+ * @author javaQuery
+ * @date 29th October, 2015
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class InitializeSetExample {
+ public static void main(String[] args) {
+ /* Declare and Initialize Set of Integer */
+ Set setIntegers = new HashSet(Arrays.asList(10, 20, 30));
+
+ System.out.println("Print value of Set");
+ /* Print value of Set */
+ for (Integer integer : setIntegers) {
+ System.out.println(integer);
+ }
+
+ /* Declare and Initialize Set of String */
+ Set setStrings = new HashSet<>(Arrays.asList("Chirag", "Yogita", "Vicky", "Heer"));
+
+ System.out.println("Print value of Set");
+ /* Print value of Set */
+ for (String string : setStrings) {
+ System.out.println(string);
+ }
+ }
+}
diff --git a/src/com/javaquery/collections/set/ListToSet.java b/src/main/java/com/javaquery/collections/set/ListToSet.java
similarity index 96%
rename from src/com/javaquery/collections/set/ListToSet.java
rename to src/main/java/com/javaquery/collections/set/ListToSet.java
index 8e0f2af..2076541 100644
--- a/src/com/javaquery/collections/set/ListToSet.java
+++ b/src/main/java/com/javaquery/collections/set/ListToSet.java
@@ -1,37 +1,37 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.collections.set;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * List to Set example.
- *
- * @author javaQuery
- * @date 7th October, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class ListToSet {
-
- public static void main(String[] args) {
- /* Create list of string */
- List strings = new ArrayList();
- strings.add("A");
- strings.add("B");
-
- /**
- * new HashSet(Collection extends E> c) We created Set of String so we
- * can initialize HashSet using any collection that extends String.
- */
- Set stringSet = new HashSet(strings);
- for (String string : stringSet) {
- System.out.println(string);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.collections.set;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * List to Set example.
+ *
+ * @author javaQuery
+ * @date 7th October, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class ListToSet {
+
+ public static void main(String[] args) {
+ /* Create list of string */
+ List strings = new ArrayList();
+ strings.add("A");
+ strings.add("B");
+
+ /**
+ * new HashSet(Collection extends E> c) We created Set of String so we
+ * can initialize HashSet using any collection that extends String.
+ */
+ Set stringSet = new HashSet(strings);
+ for (String string : stringSet) {
+ System.out.println(string);
+ }
+ }
+}
diff --git a/src/com/javaquery/collections/set/SetStreamSum.java b/src/main/java/com/javaquery/collections/set/SetStreamSum.java
similarity index 96%
rename from src/com/javaquery/collections/set/SetStreamSum.java
rename to src/main/java/com/javaquery/collections/set/SetStreamSum.java
index 97e26f1..396cd0d 100644
--- a/src/com/javaquery/collections/set/SetStreamSum.java
+++ b/src/main/java/com/javaquery/collections/set/SetStreamSum.java
@@ -1,38 +1,38 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.collections.set;
-
-import com.javaquery.bean.Item;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Summation of element in Set using Stream api in java 8.
- *
- * @author javaQuery
- * @date 17th October, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class SetStreamSum {
-
- public static void main(String[] args) {
- /* Summation of Integers in Set */
- Set integers = new HashSet<>(Arrays.asList(10, 20, 30));
-
- Integer integerSum = integers.stream().mapToInt(Integer::intValue).sum();
- System.out.println("summation: " + integerSum);
-
- /* Summation when you have set of beans */
- Item motoG = new Item("MotoG", 100.12);
- Item iPhone = new Item("iPhone", 200.12);
-
- Set
- listBeans = new HashSet<>(Arrays.asList(motoG, iPhone));
-
- Double doubleSum = listBeans.stream().mapToDouble(Item::getPrice).sum();
- System.out.println("summation: " + doubleSum);
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.collections.set;
+
+import com.javaquery.bean.Item;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Summation of element in Set using Stream api in java 8.
+ *
+ * @author javaQuery
+ * @date 17th October, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class SetStreamSum {
+
+ public static void main(String[] args) {
+ /* Summation of Integers in Set */
+ Set integers = new HashSet<>(Arrays.asList(10, 20, 30));
+
+ Integer integerSum = integers.stream().mapToInt(Integer::intValue).sum();
+ System.out.println("summation: " + integerSum);
+
+ /* Summation when you have set of beans */
+ Item motoG = new Item("MotoG", 100.12);
+ Item iPhone = new Item("iPhone", 200.12);
+
+ Set
- listBeans = new HashSet<>(Arrays.asList(motoG, iPhone));
+
+ Double doubleSum = listBeans.stream().mapToDouble(Item::getPrice).sum();
+ System.out.println("summation: " + doubleSum);
+ }
+}
diff --git a/src/com/javaquery/core/Thread/MessageThread.java b/src/main/java/com/javaquery/core/Thread/MessageThread.java
similarity index 96%
rename from src/com/javaquery/core/Thread/MessageThread.java
rename to src/main/java/com/javaquery/core/Thread/MessageThread.java
index 013295c..e7aee11 100644
--- a/src/com/javaquery/core/Thread/MessageThread.java
+++ b/src/main/java/com/javaquery/core/Thread/MessageThread.java
@@ -1,43 +1,43 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.Thread;
-
-/**
- * Thread that prints message in interval of 4 seconds.
- *
- * @author javaQuery
- * @date 29th August, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class MessageThread implements Runnable {
-
- // Display a message, preceded by
- // the name of the current thread
- static void threadMessage(String message) {
- String threadName = Thread.currentThread().getName();
- System.out.format("%s: %s%n", threadName, message);
- }
-
- @Override
- public void run() {
- String importantInfo[] = {
- "Mares eat oats",
- "Does eat oats",
- "Little lambs eat ivy",
- "A kid will eat ivy too"
- };
- try {
- for (int i = 0; i < importantInfo.length; i++) {
- // Pause for 4 seconds
- Thread.sleep(4000);
- // Print a message
- threadMessage(importantInfo[i]);
- }
- } catch (InterruptedException e) {
- threadMessage("I wasn't done!");
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.Thread;
+
+/**
+ * Thread that prints message in interval of 4 seconds.
+ *
+ * @author javaQuery
+ * @date 29th August, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class MessageThread implements Runnable {
+
+ // Display a message, preceded by
+ // the name of the current thread
+ static void threadMessage(String message) {
+ String threadName = Thread.currentThread().getName();
+ System.out.format("%s: %s%n", threadName, message);
+ }
+
+ @Override
+ public void run() {
+ String importantInfo[] = {
+ "Mares eat oats",
+ "Does eat oats",
+ "Little lambs eat ivy",
+ "A kid will eat ivy too"
+ };
+ try {
+ for (int i = 0; i < importantInfo.length; i++) {
+ // Pause for 4 seconds
+ Thread.sleep(4000);
+ // Print a message
+ threadMessage(importantInfo[i]);
+ }
+ } catch (InterruptedException e) {
+ threadMessage("I wasn't done!");
+ }
+ }
+}
diff --git a/src/com/javaquery/core/Thread/ThreadJoinExample.java b/src/main/java/com/javaquery/core/Thread/ThreadJoinExample.java
similarity index 96%
rename from src/com/javaquery/core/Thread/ThreadJoinExample.java
rename to src/main/java/com/javaquery/core/Thread/ThreadJoinExample.java
index cc3edd8..6a1323c 100644
--- a/src/com/javaquery/core/Thread/ThreadJoinExample.java
+++ b/src/main/java/com/javaquery/core/Thread/ThreadJoinExample.java
@@ -1,31 +1,31 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.Thread;
-
-/**
- * Thread join example.
- * @author javaQuery
- * @date 29th August, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class ThreadJoinExample {
- public static void main(String[] args) throws InterruptedException {
- Thread t = new Thread(new MessageThread());
- // start MessageThread.
- t.start();
- /**
- * Main Thread (ThreadJoinExample) will wait for 't' to finish
- * its task in 5 seconds of it will leave.
- */
- t.join(5000);
-
- /**
- * Main Thread (ThreadJoinExample) will wait until 't' finish its task.
- */
- // t.join();
- System.out.println("Main Thread left(finish).");
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.Thread;
+
+/**
+ * Thread join example.
+ * @author javaQuery
+ * @date 29th August, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class ThreadJoinExample {
+ public static void main(String[] args) throws InterruptedException {
+ Thread t = new Thread(new MessageThread());
+ // start MessageThread.
+ t.start();
+ /**
+ * Main Thread (ThreadJoinExample) will wait for 't' to finish
+ * its task in 5 seconds of it will leave.
+ */
+ t.join(5000);
+
+ /**
+ * Main Thread (ThreadJoinExample) will wait until 't' finish its task.
+ */
+ // t.join();
+ System.out.println("Main Thread left(finish).");
+ }
+}
diff --git a/src/com/javaquery/core/accessmodifiers/DefaultAccessModifier.java b/src/main/java/com/javaquery/core/accessmodifiers/DefaultAccessModifier.java
similarity index 100%
rename from src/com/javaquery/core/accessmodifiers/DefaultAccessModifier.java
rename to src/main/java/com/javaquery/core/accessmodifiers/DefaultAccessModifier.java
diff --git a/src/com/javaquery/core/accessmodifiers/DefaultAccessModifierSubClass.java b/src/main/java/com/javaquery/core/accessmodifiers/DefaultAccessModifierSubClass.java
similarity index 100%
rename from src/com/javaquery/core/accessmodifiers/DefaultAccessModifierSubClass.java
rename to src/main/java/com/javaquery/core/accessmodifiers/DefaultAccessModifierSubClass.java
diff --git a/src/com/javaquery/core/accessmodifiers/PrivateAccessModifier.java b/src/main/java/com/javaquery/core/accessmodifiers/PrivateAccessModifier.java
similarity index 100%
rename from src/com/javaquery/core/accessmodifiers/PrivateAccessModifier.java
rename to src/main/java/com/javaquery/core/accessmodifiers/PrivateAccessModifier.java
diff --git a/src/com/javaquery/core/accessmodifiers/PrivateAccessModifierSubClass.java b/src/main/java/com/javaquery/core/accessmodifiers/PrivateAccessModifierSubClass.java
similarity index 100%
rename from src/com/javaquery/core/accessmodifiers/PrivateAccessModifierSubClass.java
rename to src/main/java/com/javaquery/core/accessmodifiers/PrivateAccessModifierSubClass.java
diff --git a/src/com/javaquery/core/accessmodifiers/ProtectedAccessModifier.java b/src/main/java/com/javaquery/core/accessmodifiers/ProtectedAccessModifier.java
similarity index 100%
rename from src/com/javaquery/core/accessmodifiers/ProtectedAccessModifier.java
rename to src/main/java/com/javaquery/core/accessmodifiers/ProtectedAccessModifier.java
diff --git a/src/com/javaquery/core/accessmodifiers/ProtectedAccessModifierSubClass.java b/src/main/java/com/javaquery/core/accessmodifiers/ProtectedAccessModifierSubClass.java
similarity index 100%
rename from src/com/javaquery/core/accessmodifiers/ProtectedAccessModifierSubClass.java
rename to src/main/java/com/javaquery/core/accessmodifiers/ProtectedAccessModifierSubClass.java
diff --git a/src/com/javaquery/core/accessmodifiers/PublicAccessModifier.java b/src/main/java/com/javaquery/core/accessmodifiers/PublicAccessModifier.java
similarity index 100%
rename from src/com/javaquery/core/accessmodifiers/PublicAccessModifier.java
rename to src/main/java/com/javaquery/core/accessmodifiers/PublicAccessModifier.java
diff --git a/src/com/javaquery/core/array/InitializeBooleanArrayExample.java b/src/main/java/com/javaquery/core/array/InitializeBooleanArrayExample.java
similarity index 96%
rename from src/com/javaquery/core/array/InitializeBooleanArrayExample.java
rename to src/main/java/com/javaquery/core/array/InitializeBooleanArrayExample.java
index fe04087..0ac6298 100644
--- a/src/com/javaquery/core/array/InitializeBooleanArrayExample.java
+++ b/src/main/java/com/javaquery/core/array/InitializeBooleanArrayExample.java
@@ -1,35 +1,35 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.array;
-
-/**
- * @author javaQuery
- * @Github: https://github.com/javaquery/Examples
- */
-public class InitializeBooleanArrayExample {
- public static void main(String[] args) {
- /* Declare and Initialize boolean Array */
- boolean[] booleanArray1 = {true, false};
-
- System.out.println("Print value of boolean[]");
- /* Print value of array */
- for (boolean b : booleanArray1) {
- System.out.println(b);
- }
-
- /**
- * Declare and Initialize Boolean Array.
- * Boolean can hold `null` values.
- */
- Boolean booleanArray2[] = {true, false, null};
-
- System.out.println("Print value of Boolean[]");
- /* Print value of array */
- for (Boolean b : booleanArray2) {
- System.out.println(b);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.array;
+
+/**
+ * @author javaQuery
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class InitializeBooleanArrayExample {
+ public static void main(String[] args) {
+ /* Declare and Initialize boolean Array */
+ boolean[] booleanArray1 = {true, false};
+
+ System.out.println("Print value of boolean[]");
+ /* Print value of array */
+ for (boolean b : booleanArray1) {
+ System.out.println(b);
+ }
+
+ /**
+ * Declare and Initialize Boolean Array.
+ * Boolean can hold `null` values.
+ */
+ Boolean booleanArray2[] = {true, false, null};
+
+ System.out.println("Print value of Boolean[]");
+ /* Print value of array */
+ for (Boolean b : booleanArray2) {
+ System.out.println(b);
+ }
+ }
+}
diff --git a/src/com/javaquery/core/array/InitializeDoubleArrayExample.java b/src/main/java/com/javaquery/core/array/InitializeDoubleArrayExample.java
similarity index 96%
rename from src/com/javaquery/core/array/InitializeDoubleArrayExample.java
rename to src/main/java/com/javaquery/core/array/InitializeDoubleArrayExample.java
index a3788aa..c02876a 100644
--- a/src/com/javaquery/core/array/InitializeDoubleArrayExample.java
+++ b/src/main/java/com/javaquery/core/array/InitializeDoubleArrayExample.java
@@ -1,35 +1,35 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.array;
-
-/**
- * @author javaQuery
- * @Github: https://github.com/javaquery/Examples
- */
-public class InitializeDoubleArrayExample {
- public static void main(String[] args) {
- /* Declare and Initialize double Array */
- double[] doubleArray1 = {10.1D, 20.2D, 30.3D};
-
- System.out.println("Print value of double[]");
- /* Print value of array */
- for (double d : doubleArray1) {
- System.out.println(d);
- }
-
- /**
- * Declare and Initialize Double Array.
- * Double can hold `null` values.
- */
- Double doubleArray2[] = {10.1D, 20.2D, null};
-
- System.out.println("Print value of Double[]");
- /* Print value of array */
- for (Double d : doubleArray2) {
- System.out.println(d);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.array;
+
+/**
+ * @author javaQuery
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class InitializeDoubleArrayExample {
+ public static void main(String[] args) {
+ /* Declare and Initialize double Array */
+ double[] doubleArray1 = {10.1D, 20.2D, 30.3D};
+
+ System.out.println("Print value of double[]");
+ /* Print value of array */
+ for (double d : doubleArray1) {
+ System.out.println(d);
+ }
+
+ /**
+ * Declare and Initialize Double Array.
+ * Double can hold `null` values.
+ */
+ Double doubleArray2[] = {10.1D, 20.2D, null};
+
+ System.out.println("Print value of Double[]");
+ /* Print value of array */
+ for (Double d : doubleArray2) {
+ System.out.println(d);
+ }
+ }
+}
diff --git a/src/com/javaquery/core/array/InitializeFloatArrayExample.java b/src/main/java/com/javaquery/core/array/InitializeFloatArrayExample.java
similarity index 96%
rename from src/com/javaquery/core/array/InitializeFloatArrayExample.java
rename to src/main/java/com/javaquery/core/array/InitializeFloatArrayExample.java
index b54dcea..1d7e246 100644
--- a/src/com/javaquery/core/array/InitializeFloatArrayExample.java
+++ b/src/main/java/com/javaquery/core/array/InitializeFloatArrayExample.java
@@ -1,35 +1,35 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.array;
-
-/**
- * @author javaQuery
- * @Github: https://github.com/javaquery/Examples
- */
-public class InitializeFloatArrayExample {
- public static void main(String[] args) {
- /* Declare and Initialize float Array */
- float[] floatArray1 = {10.1f, 20.2f, 30.3f};
-
- System.out.println("Print value of float[]");
- /* Print value of array */
- for (float f : floatArray1) {
- System.out.println(f);
- }
-
- /**
- * Declare and Initialize Float Array.
- * Float can hold `null` values.
- */
- Float floatArray2[] = {10.1f, 20.2f, null};
-
- System.out.println("Print value of Float[]");
- /* Print value of array */
- for (Float f : floatArray2) {
- System.out.println(f);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.array;
+
+/**
+ * @author javaQuery
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class InitializeFloatArrayExample {
+ public static void main(String[] args) {
+ /* Declare and Initialize float Array */
+ float[] floatArray1 = {10.1f, 20.2f, 30.3f};
+
+ System.out.println("Print value of float[]");
+ /* Print value of array */
+ for (float f : floatArray1) {
+ System.out.println(f);
+ }
+
+ /**
+ * Declare and Initialize Float Array.
+ * Float can hold `null` values.
+ */
+ Float floatArray2[] = {10.1f, 20.2f, null};
+
+ System.out.println("Print value of Float[]");
+ /* Print value of array */
+ for (Float f : floatArray2) {
+ System.out.println(f);
+ }
+ }
+}
diff --git a/src/com/javaquery/core/array/InitializeIntArrayExample.java b/src/main/java/com/javaquery/core/array/InitializeIntArrayExample.java
similarity index 96%
rename from src/com/javaquery/core/array/InitializeIntArrayExample.java
rename to src/main/java/com/javaquery/core/array/InitializeIntArrayExample.java
index 154be76..ad4cf2a 100644
--- a/src/com/javaquery/core/array/InitializeIntArrayExample.java
+++ b/src/main/java/com/javaquery/core/array/InitializeIntArrayExample.java
@@ -1,35 +1,35 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.array;
-
-/**
- * @author javaQuery
- * @Github: https://github.com/javaquery/Examples
- */
-public class InitializeIntArrayExample {
- public static void main(String[] args) {
- /* Declare and Initialize int Array */
- int intArray[] = {10, 20, 30};
-
- System.out.println("Print value of int[]");
- /* Print value of array */
- for (int i : intArray) {
- System.out.println(i);
- }
-
- /**
- * Declare and Initialize Integer Array.
- * Integer can hold `null` values.
- */
- Integer integerArray[] = {10, 20, null};
-
- System.out.println("Print value of Integer[]");
- /* Print value of array */
- for (Integer i : integerArray) {
- System.out.println(i);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.array;
+
+/**
+ * @author javaQuery
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class InitializeIntArrayExample {
+ public static void main(String[] args) {
+ /* Declare and Initialize int Array */
+ int intArray[] = {10, 20, 30};
+
+ System.out.println("Print value of int[]");
+ /* Print value of array */
+ for (int i : intArray) {
+ System.out.println(i);
+ }
+
+ /**
+ * Declare and Initialize Integer Array.
+ * Integer can hold `null` values.
+ */
+ Integer integerArray[] = {10, 20, null};
+
+ System.out.println("Print value of Integer[]");
+ /* Print value of array */
+ for (Integer i : integerArray) {
+ System.out.println(i);
+ }
+ }
+}
diff --git a/src/com/javaquery/core/array/InitializeLongArrayExample.java b/src/main/java/com/javaquery/core/array/InitializeLongArrayExample.java
similarity index 96%
rename from src/com/javaquery/core/array/InitializeLongArrayExample.java
rename to src/main/java/com/javaquery/core/array/InitializeLongArrayExample.java
index b54e219..be9b1d8 100644
--- a/src/com/javaquery/core/array/InitializeLongArrayExample.java
+++ b/src/main/java/com/javaquery/core/array/InitializeLongArrayExample.java
@@ -1,35 +1,35 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.array;
-
-/**
- * @author javaQuery
- * @Github: https://github.com/javaquery/Examples
- */
-public class InitializeLongArrayExample {
- public static void main(String[] args) {
- /* Declare and Initialize long Array */
- long longArray1[] = {10L, 20L, 30L};
-
- System.out.println("Print value of long[]");
- /* Print value of array */
- for (long l : longArray1) {
- System.out.println(l);
- }
-
- /**
- * Declare and Initialize Long Array.
- * Long can hold `null` values.
- */
- Long longArray2[] = {10L, 20L, null};
-
- System.out.println("Print value of Long[]");
- /* Print value of array */
- for (Long l : longArray2) {
- System.out.println(l);
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.array;
+
+/**
+ * @author javaQuery
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class InitializeLongArrayExample {
+ public static void main(String[] args) {
+ /* Declare and Initialize long Array */
+ long longArray1[] = {10L, 20L, 30L};
+
+ System.out.println("Print value of long[]");
+ /* Print value of array */
+ for (long l : longArray1) {
+ System.out.println(l);
+ }
+
+ /**
+ * Declare and Initialize Long Array.
+ * Long can hold `null` values.
+ */
+ Long longArray2[] = {10L, 20L, null};
+
+ System.out.println("Print value of Long[]");
+ /* Print value of array */
+ for (Long l : longArray2) {
+ System.out.println(l);
+ }
+ }
+}
diff --git a/src/com/javaquery/core/basic/AddAndDisplay.java b/src/main/java/com/javaquery/core/basic/AddAndDisplay.java
similarity index 96%
rename from src/com/javaquery/core/basic/AddAndDisplay.java
rename to src/main/java/com/javaquery/core/basic/AddAndDisplay.java
index 48e9026..98f03d4 100644
--- a/src/com/javaquery/core/basic/AddAndDisplay.java
+++ b/src/main/java/com/javaquery/core/basic/AddAndDisplay.java
@@ -1,32 +1,32 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.basic;
-
-/**
- * Example of method overriding.
- *
- * @author javaQuery
- * @date 6th October, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class AddAndDisplay extends Addition {
-
- /**
- * Method override of class Addition.
- * We're overriding 'add' method because we want to print
- * values of 'x' and 'y' to console along with the 'result'.
- * @param x
- * @param y
- * @return
- */
- @Override
- public int add(int x, int y) {
- int result = x + y;
- System.out.println("(x:" + x + ",y:" + y + ")");
- System.out.println("result: " + result);
- return result;
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.basic;
+
+/**
+ * Example of method overriding.
+ *
+ * @author javaQuery
+ * @date 6th October, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class AddAndDisplay extends Addition {
+
+ /**
+ * Method override of class Addition.
+ * We're overriding 'add' method because we want to print
+ * values of 'x' and 'y' to console along with the 'result'.
+ * @param x
+ * @param y
+ * @return
+ */
+ @Override
+ public int add(int x, int y) {
+ int result = x + y;
+ System.out.println("(x:" + x + ",y:" + y + ")");
+ System.out.println("result: " + result);
+ return result;
+ }
+}
diff --git a/src/com/javaquery/core/basic/Addition.java b/src/main/java/com/javaquery/core/basic/Addition.java
similarity index 95%
rename from src/com/javaquery/core/basic/Addition.java
rename to src/main/java/com/javaquery/core/basic/Addition.java
index 319331f..4188f98 100644
--- a/src/com/javaquery/core/basic/Addition.java
+++ b/src/main/java/com/javaquery/core/basic/Addition.java
@@ -1,26 +1,26 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.basic;
-
-/**
- * Example of method overriding.
- *
- * @author javaQuery
- * @date 6th October, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class Addition {
-
- /**
- * Add two numbers and return the result.
- * @param x
- * @param y
- * @return
- */
- public int add(int x, int y) {
- return x + y;
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.basic;
+
+/**
+ * Example of method overriding.
+ *
+ * @author javaQuery
+ * @date 6th October, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class Addition {
+
+ /**
+ * Add two numbers and return the result.
+ * @param x
+ * @param y
+ * @return
+ */
+ public int add(int x, int y) {
+ return x + y;
+ }
+}
diff --git a/src/com/javaquery/core/basic/AssignSameValue.java b/src/main/java/com/javaquery/core/basic/AssignSameValue.java
similarity index 96%
rename from src/com/javaquery/core/basic/AssignSameValue.java
rename to src/main/java/com/javaquery/core/basic/AssignSameValue.java
index ce2930a..36c8353 100644
--- a/src/com/javaquery/core/basic/AssignSameValue.java
+++ b/src/main/java/com/javaquery/core/basic/AssignSameValue.java
@@ -1,35 +1,35 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.basic;
-
-/**
- * Example: Assign same value to multiple variable.
- *
- * @author javaQuery
- * @date 2nd January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class AssignSameValue {
-
- public static void main(String[] args) {
- int red = 0, green = 0, blue = 0;
-
- String color = "white"; // args[0]
-
- if ("white".equalsIgnoreCase(color)) {
- /* assign same value to red, green, blue */
- red = green = blue = 255;
- } else if ("black".equalsIgnoreCase(color)) {
- /* assign same value to red, green, blue */
- red = green = blue = 0;
- } else {
- /* other else if...else for more color combinations */
- }
-
- System.out.println("Color code:");
- System.out.println("red = " + red + ", green = " + green + ", blue = " + blue);
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.basic;
+
+/**
+ * Example: Assign same value to multiple variable.
+ *
+ * @author javaQuery
+ * @date 2nd January, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class AssignSameValue {
+
+ public static void main(String[] args) {
+ int red = 0, green = 0, blue = 0;
+
+ String color = "white"; // args[0]
+
+ if ("white".equalsIgnoreCase(color)) {
+ /* assign same value to red, green, blue */
+ red = green = blue = 255;
+ } else if ("black".equalsIgnoreCase(color)) {
+ /* assign same value to red, green, blue */
+ red = green = blue = 0;
+ } else {
+ /* other else if...else for more color combinations */
+ }
+
+ System.out.println("Color code:");
+ System.out.println("red = " + red + ", green = " + green + ", blue = " + blue);
+ }
+}
diff --git a/src/com/javaquery/core/basic/BreakLoopExample.java b/src/main/java/com/javaquery/core/basic/BreakLoopExample.java
similarity index 96%
rename from src/com/javaquery/core/basic/BreakLoopExample.java
rename to src/main/java/com/javaquery/core/basic/BreakLoopExample.java
index ffc5746..dad1492 100644
--- a/src/com/javaquery/core/basic/BreakLoopExample.java
+++ b/src/main/java/com/javaquery/core/basic/BreakLoopExample.java
@@ -1,65 +1,65 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.basic;
-
-/**
- * Example: Break loop in Java
- *
- * @author javaQuery
- * @date 11th December, 2015
- * @Github: https://github.com/javaquery/Examples
- */
-public class BreakLoopExample {
-
- public static void main(String[] args) {
- System.out.println("break(stop) for loop");
- for (int i = 0; i < 10; i++) {
- if (i == 2) {
- /* Loop will be terminated when i == 2 */
- break;
- }
- System.out.println("for-loop: " + i);
- }
-
- System.out.println("------------------------------------------");
- System.out.println("break(stop) for-each loop");
-
- int[] numbers = {0, 1, 2, 3, 4};
- for (int number : numbers) {
- if (number == 2) {
- /* Loop will be terminated when i == 2 */
- break;
- }
- System.out.println("for-each loop: " + number);
- }
-
- System.out.println("------------------------------------------");
- System.out.println("break(stop) while loop");
-
- int i = 10;
- while (i > 0) {
- if (i == 8) {
- /* Loop will be terminated when i == 8 */
- break;
- }
- System.out.println("while loop: " + i);
- i--;
- }
-
- System.out.println("------------------------------------------");
- System.out.println("break(stop) do-while loop");
-
- int j = 10;
- do {
- if (j == 8) {
- /* Loop will be terminated when j == 8 */
- break;
- }
- System.out.println("do-while loop: " + j);
- j--;
- } while (j > 0);
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.basic;
+
+/**
+ * Example: Break loop in Java
+ *
+ * @author javaQuery
+ * @date 11th December, 2015
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class BreakLoopExample {
+
+ public static void main(String[] args) {
+ System.out.println("break(stop) for loop");
+ for (int i = 0; i < 10; i++) {
+ if (i == 2) {
+ /* Loop will be terminated when i == 2 */
+ break;
+ }
+ System.out.println("for-loop: " + i);
+ }
+
+ System.out.println("------------------------------------------");
+ System.out.println("break(stop) for-each loop");
+
+ int[] numbers = {0, 1, 2, 3, 4};
+ for (int number : numbers) {
+ if (number == 2) {
+ /* Loop will be terminated when i == 2 */
+ break;
+ }
+ System.out.println("for-each loop: " + number);
+ }
+
+ System.out.println("------------------------------------------");
+ System.out.println("break(stop) while loop");
+
+ int i = 10;
+ while (i > 0) {
+ if (i == 8) {
+ /* Loop will be terminated when i == 8 */
+ break;
+ }
+ System.out.println("while loop: " + i);
+ i--;
+ }
+
+ System.out.println("------------------------------------------");
+ System.out.println("break(stop) do-while loop");
+
+ int j = 10;
+ do {
+ if (j == 8) {
+ /* Loop will be terminated when j == 8 */
+ break;
+ }
+ System.out.println("do-while loop: " + j);
+ j--;
+ } while (j > 0);
+ }
+}
diff --git a/src/com/javaquery/core/basic/BreakLoopWithLabel.java b/src/main/java/com/javaquery/core/basic/BreakLoopWithLabel.java
similarity index 96%
rename from src/com/javaquery/core/basic/BreakLoopWithLabel.java
rename to src/main/java/com/javaquery/core/basic/BreakLoopWithLabel.java
index 90a2be4..ea19a47 100644
--- a/src/com/javaquery/core/basic/BreakLoopWithLabel.java
+++ b/src/main/java/com/javaquery/core/basic/BreakLoopWithLabel.java
@@ -1,51 +1,51 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.basic;
-
-/**
- * Example: Break loop using label in Java
- *
- * @author javaQuery
- * @date 11th December, 2015
- * @Github: https://github.com/javaquery/Examples
- */
-public class BreakLoopWithLabel {
-
- public static void main(String[] args) {
-
- System.out.println("break multiple loop using label");
-
- /* Label used to break loop anytime */
- rootForLoop:
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 3; j++) {
- if (i == 1 && j == 2) {
- break rootForLoop;
- }
- System.out.println("i = " + i + ", j = " + j);
- }
- }
-
- System.out.println("------------------------------------------");
-
- /* Label used to break loop anytime */
- rootWhileLoop:
- while (true) {
-
- parentForLoop:
- for (int m = 0; m < 10; m++) {
-
- childForLoop:
- for (int n = 0; n < 3; n++) {
- if (m == 0 && n == 2) {
- break rootWhileLoop;
- }
- System.out.println("m = " + m + ", n = " + n);
- }
- }
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.basic;
+
+/**
+ * Example: Break loop using label in Java
+ *
+ * @author javaQuery
+ * @date 11th December, 2015
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class BreakLoopWithLabel {
+
+ public static void main(String[] args) {
+
+ System.out.println("break multiple loop using label");
+
+ /* Label used to break loop anytime */
+ rootForLoop:
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 3; j++) {
+ if (i == 1 && j == 2) {
+ break rootForLoop;
+ }
+ System.out.println("i = " + i + ", j = " + j);
+ }
+ }
+
+ System.out.println("------------------------------------------");
+
+ /* Label used to break loop anytime */
+ rootWhileLoop:
+ while (true) {
+
+ parentForLoop:
+ for (int m = 0; m < 10; m++) {
+
+ childForLoop:
+ for (int n = 0; n < 3; n++) {
+ if (m == 0 && n == 2) {
+ break rootWhileLoop;
+ }
+ System.out.println("m = " + m + ", n = " + n);
+ }
+ }
+ }
+ }
+}
diff --git a/src/com/javaquery/core/basic/ContinueExample.java b/src/main/java/com/javaquery/core/basic/ContinueExample.java
similarity index 96%
rename from src/com/javaquery/core/basic/ContinueExample.java
rename to src/main/java/com/javaquery/core/basic/ContinueExample.java
index ce0b30c..5a1606d 100644
--- a/src/com/javaquery/core/basic/ContinueExample.java
+++ b/src/main/java/com/javaquery/core/basic/ContinueExample.java
@@ -1,67 +1,67 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.basic;
-
-/**
- * Example: continue in Java loop
- *
- * @author javaQuery
- * @date 11th December, 2015
- * @Github: https://github.com/javaquery/Examples
- */
-public class ContinueExample {
-
- public static void main(String[] args) {
- System.out.println("continue in for loop");
- for (int i = 0; i < 5; i++) {
- if (i == 2) {
- /* Loop will skip current iteration when i == 2 */
- continue;
- }
- System.out.println("for-loop: " + i);
- }
-
- System.out.println("------------------------------------------");
- System.out.println("continue in for-each loop");
-
- int[] numbers = {0, 1, 2, 3, 4};
- for (int number : numbers) {
- if (number == 3) {
- /* Loop will skip current iteration when number == 3 */
- continue;
- }
- System.out.println("for-each loop: " + number);
- }
-
- System.out.println("------------------------------------------");
- System.out.println("continue in while loop");
-
- int i = 5;
- while (i > 0) {
- if (i == 1) {
- i--;
- /* Loop will skip current iteration when i == 1 */
- continue;
- }
- System.out.println("while loop: " + i);
- i--;
- }
-
- System.out.println("------------------------------------------");
- System.out.println("continue in do-while loop");
-
- int j = 5;
- do {
- if (j == 2) {
- j--;
- /* Loop will skip current iteration when j == 2 */
- continue;
- }
- System.out.println("do-while loop: " + j);
- j--;
- } while (j > 0);
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.basic;
+
+/**
+ * Example: continue in Java loop
+ *
+ * @author javaQuery
+ * @date 11th December, 2015
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class ContinueExample {
+
+ public static void main(String[] args) {
+ System.out.println("continue in for loop");
+ for (int i = 0; i < 5; i++) {
+ if (i == 2) {
+ /* Loop will skip current iteration when i == 2 */
+ continue;
+ }
+ System.out.println("for-loop: " + i);
+ }
+
+ System.out.println("------------------------------------------");
+ System.out.println("continue in for-each loop");
+
+ int[] numbers = {0, 1, 2, 3, 4};
+ for (int number : numbers) {
+ if (number == 3) {
+ /* Loop will skip current iteration when number == 3 */
+ continue;
+ }
+ System.out.println("for-each loop: " + number);
+ }
+
+ System.out.println("------------------------------------------");
+ System.out.println("continue in while loop");
+
+ int i = 5;
+ while (i > 0) {
+ if (i == 1) {
+ i--;
+ /* Loop will skip current iteration when i == 1 */
+ continue;
+ }
+ System.out.println("while loop: " + i);
+ i--;
+ }
+
+ System.out.println("------------------------------------------");
+ System.out.println("continue in do-while loop");
+
+ int j = 5;
+ do {
+ if (j == 2) {
+ j--;
+ /* Loop will skip current iteration when j == 2 */
+ continue;
+ }
+ System.out.println("do-while loop: " + j);
+ j--;
+ } while (j > 0);
+ }
+}
diff --git a/src/com/javaquery/core/basic/ContinueWithLabel.java b/src/main/java/com/javaquery/core/basic/ContinueWithLabel.java
similarity index 96%
rename from src/com/javaquery/core/basic/ContinueWithLabel.java
rename to src/main/java/com/javaquery/core/basic/ContinueWithLabel.java
index fe935a4..73a5df2 100644
--- a/src/com/javaquery/core/basic/ContinueWithLabel.java
+++ b/src/main/java/com/javaquery/core/basic/ContinueWithLabel.java
@@ -1,56 +1,56 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.basic;
-
-/**
- * Example: continue with label in Java loop
- *
- * @author javaQuery
- * @date 11th December, 2015
- * @Github: https://github.com/javaquery/Examples
- */
-public class ContinueWithLabel {
-
- public static void main(String[] args) {
- System.out.println("continue in loop using label");
-
- /* Label used to continue loop */
- rootForLoop:
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- if (i == 1 && j == 2) {
- System.out.println(">>>> skipped");
- /* Loop will skip current iteration when i == 1 and j == 2 */
- continue rootForLoop;
- }
- System.out.println("i = " + i + ", j = " + j);
- }
- }
-
- System.out.println("------------------------------------------");
-
- /* Label used to continue loop */
- parentForLoop:
- for (int l = 0; l < 2; l++) {
-
- childForLoop:
- for (int m = 0; m < 3; m++) {
- int n = 1;
-
- rootWhileLoop:
- while (n <= 2) {
- if (l == 0 && m == 2) {
- System.out.println(">>>> skipped");
- /* Loop will skip current iteration when l == 0 && m == 2 */
- continue childForLoop;
- }
- System.out.println("l = " + l + ", m = " + m + ", n = " + n);
- n++;
- }
- }
- }
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.basic;
+
+/**
+ * Example: continue with label in Java loop
+ *
+ * @author javaQuery
+ * @date 11th December, 2015
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class ContinueWithLabel {
+
+ public static void main(String[] args) {
+ System.out.println("continue in loop using label");
+
+ /* Label used to continue loop */
+ rootForLoop:
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ if (i == 1 && j == 2) {
+ System.out.println(">>>> skipped");
+ /* Loop will skip current iteration when i == 1 and j == 2 */
+ continue rootForLoop;
+ }
+ System.out.println("i = " + i + ", j = " + j);
+ }
+ }
+
+ System.out.println("------------------------------------------");
+
+ /* Label used to continue loop */
+ parentForLoop:
+ for (int l = 0; l < 2; l++) {
+
+ childForLoop:
+ for (int m = 0; m < 3; m++) {
+ int n = 1;
+
+ rootWhileLoop:
+ while (n <= 2) {
+ if (l == 0 && m == 2) {
+ System.out.println(">>>> skipped");
+ /* Loop will skip current iteration when l == 0 && m == 2 */
+ continue childForLoop;
+ }
+ System.out.println("l = " + l + ", m = " + m + ", n = " + n);
+ n++;
+ }
+ }
+ }
+ }
+}
diff --git a/src/com/javaquery/core/basic/MethodOverload.java b/src/main/java/com/javaquery/core/basic/MethodOverload.java
similarity index 96%
rename from src/com/javaquery/core/basic/MethodOverload.java
rename to src/main/java/com/javaquery/core/basic/MethodOverload.java
index ddc1e69..2db17c1 100644
--- a/src/com/javaquery/core/basic/MethodOverload.java
+++ b/src/main/java/com/javaquery/core/basic/MethodOverload.java
@@ -1,47 +1,47 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.basic;
-
-/**
- * Example of method overloading
- *
- * @author javaQuery
- * @date 5th October, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class MethodOverload {
-
- public int x = 0;
-
- /**
- * Method overloading - Same method name(getAndIncrement) with no parameter.
- * Increment x by 1.
- *
- * @return
- */
- public int getAndIncrement() {
- x = x + 1; // you can also use like x = getAndIncrement(1);
- return x;
- }
-
- /**
- * Method overloading - Same method name(getAndIncrement) with parameter.
- * Increment x by given count(value).
- *
- * @param add
- * @return
- */
- public int getAndIncrement(int add) {
- x = x + add;
- return x;
- }
-
- public static void main(String[] args) {
- MethodOverload methodOverload = new MethodOverload();
- System.out.println("calling 'getAndIncrement()': " + methodOverload.getAndIncrement());
- System.out.println("calling 'getAndIncrement(int add)': " + methodOverload.getAndIncrement(2));
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.basic;
+
+/**
+ * Example of method overloading
+ *
+ * @author javaQuery
+ * @date 5th October, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class MethodOverload {
+
+ public int x = 0;
+
+ /**
+ * Method overloading - Same method name(getAndIncrement) with no parameter.
+ * Increment x by 1.
+ *
+ * @return
+ */
+ public int getAndIncrement() {
+ x = x + 1; // you can also use like x = getAndIncrement(1);
+ return x;
+ }
+
+ /**
+ * Method overloading - Same method name(getAndIncrement) with parameter.
+ * Increment x by given count(value).
+ *
+ * @param add
+ * @return
+ */
+ public int getAndIncrement(int add) {
+ x = x + add;
+ return x;
+ }
+
+ public static void main(String[] args) {
+ MethodOverload methodOverload = new MethodOverload();
+ System.out.println("calling 'getAndIncrement()': " + methodOverload.getAndIncrement());
+ System.out.println("calling 'getAndIncrement(int add)': " + methodOverload.getAndIncrement(2));
+ }
+}
diff --git a/src/com/javaquery/core/basic/MethodOverride.java b/src/main/java/com/javaquery/core/basic/MethodOverride.java
similarity index 97%
rename from src/com/javaquery/core/basic/MethodOverride.java
rename to src/main/java/com/javaquery/core/basic/MethodOverride.java
index 2960432..b75e667 100644
--- a/src/com/javaquery/core/basic/MethodOverride.java
+++ b/src/main/java/com/javaquery/core/basic/MethodOverride.java
@@ -1,38 +1,38 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.core.basic;
-
-/**
- * Example of method overriding.
- *
- * @author javaQuery
- * @date 6th October, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class MethodOverride {
- public static void main(String[] args) {
- /* Add two number using super class Addition's add method */
- Addition addition1 = new Addition();
- int result = addition1.add(20, 30);
- System.out.println("calling Addition.add(int x, int y)");
- System.out.println("result: " + result);
- System.out.println("********************************************");
-
- System.out.println("calling AddAndDisplay.add(int x, int y)");
- Addition addition2 = new AddAndDisplay();
- /**
- * Notice: We created object of 'Addition' using 'AddAndDisplay'.
- *
- * So when we call Addition.add(int x, int y) method it'll execute
- * AddAndDisplay.add(int x, int y) method because 'add' is
- * overridden.
- *
- * It'll hide the superclass Addition's add method and execute
- * subclass AddAndDisplay's method.
- */
- addition2.add(10, 20);
- }
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.javaquery.core.basic;
+
+/**
+ * Example of method overriding.
+ *
+ * @author javaQuery
+ * @date 6th October, 2016
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class MethodOverride {
+ public static void main(String[] args) {
+ /* Add two number using super class Addition's add method */
+ Addition addition1 = new Addition();
+ int result = addition1.add(20, 30);
+ System.out.println("calling Addition.add(int x, int y)");
+ System.out.println("result: " + result);
+ System.out.println("********************************************");
+
+ System.out.println("calling AddAndDisplay.add(int x, int y)");
+ Addition addition2 = new AddAndDisplay();
+ /**
+ * Notice: We created object of 'Addition' using 'AddAndDisplay'.
+ *
+ * So when we call Addition.add(int x, int y) method it'll execute
+ * AddAndDisplay.add(int x, int y) method because 'add' is
+ * overridden.
+ *
+ * It'll hide the superclass Addition's add method and execute
+ * subclass AddAndDisplay's method.
+ */
+ addition2.add(10, 20);
+ }
+}
diff --git a/src/com/javaquery/core/date/StringToDateExample.java b/src/main/java/com/javaquery/core/date/StringToDateExample.java
similarity index 97%
rename from src/com/javaquery/core/date/StringToDateExample.java
rename to src/main/java/com/javaquery/core/date/StringToDateExample.java
index c342647..11edfe6 100644
--- a/src/com/javaquery/core/date/StringToDateExample.java
+++ b/src/main/java/com/javaquery/core/date/StringToDateExample.java
@@ -1,61 +1,61 @@
-package com.javaquery.core.date;
-
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * Example: String to Date in Java
- * @author javaQuery
- * @date 22nd November, 2015
- * @Github: https://github.com/javaquery/Examples
- */
-public class StringToDateExample {
-
- public static void main(String[] args) throws ParseException {
- /**
- * parseDate(StringDate, PatternToParse)
- */
- parseDate("20151225", "yyyyMMdd");
- parseDate("2015.12.25", "yyyy.MM.dd");
- parseDate("2015-12-25", "yyyy-MM-dd");
- parseDate("2015/12/25", "yyyy/MM/dd");
-
- parseDate("25122015", "ddMMyyyy");
- parseDate("25.12.2015", "dd.MM.yyyy");
- parseDate("25-12-2015", "dd-MM-yyyy");
- parseDate("25/12/2015", "dd/MM/yyyy");
- parseDate("25/12/2015 15:10:05", "dd/MM/yyyy HH:mm:ss");
-
- parseDate("2015-12-25 15:10:05", "yyyy-MM-dd HH:mm:ss");
- parseDate("2015-12-25 15:10", "yyyy-MM-dd HH:mm");
- parseDate("2015-12-25T15:20:25Z", "yyyy-MM-dd'T'HH:mm:ss'Z'");
- parseDate("2015-12-25 15:10Z", "yyyy-MM-dd HH:mm'Z'");
- parseDate("2013-12-25T15:25:30-05:00", "yyyy-MM-dd'T'HH:mm:ssXXX");
- parseDate("2015-06-26T05:27:05.000Z", "yyyy-MM-dd'T'HH:mm:ss.'000Z'");
- }
-
- /**
- * Method to parse StringDate to {@link Date}.
- * @param strDate
- * @param pattern
- * @return {@link Date}
- */
- public static Date parseDate(String strDate, String pattern) {
- /* Return object of Date */
- Date date = null;
- /* Get DateFormatter for given pattern */
- DateFormat dateFormat = new SimpleDateFormat(pattern);
- try {
- /* Parse String to java.util.Date */
- date = dateFormat.parse(strDate);
- } catch (ParseException ex) {
- ex.printStackTrace();
- date = null;
- }
- /* Print the StringDate, Pattern and converted java Date */
- System.out.println("Date: " + strDate + ", Pattern: " + pattern + " -> java.util.Date[" + date + "]");
- return date;
- }
-}
+package com.javaquery.core.date;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Example: String to Date in Java
+ * @author javaQuery
+ * @date 22nd November, 2015
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class StringToDateExample {
+
+ public static void main(String[] args) throws ParseException {
+ /**
+ * parseDate(StringDate, PatternToParse)
+ */
+ parseDate("20151225", "yyyyMMdd");
+ parseDate("2015.12.25", "yyyy.MM.dd");
+ parseDate("2015-12-25", "yyyy-MM-dd");
+ parseDate("2015/12/25", "yyyy/MM/dd");
+
+ parseDate("25122015", "ddMMyyyy");
+ parseDate("25.12.2015", "dd.MM.yyyy");
+ parseDate("25-12-2015", "dd-MM-yyyy");
+ parseDate("25/12/2015", "dd/MM/yyyy");
+ parseDate("25/12/2015 15:10:05", "dd/MM/yyyy HH:mm:ss");
+
+ parseDate("2015-12-25 15:10:05", "yyyy-MM-dd HH:mm:ss");
+ parseDate("2015-12-25 15:10", "yyyy-MM-dd HH:mm");
+ parseDate("2015-12-25T15:20:25Z", "yyyy-MM-dd'T'HH:mm:ss'Z'");
+ parseDate("2015-12-25 15:10Z", "yyyy-MM-dd HH:mm'Z'");
+ parseDate("2013-12-25T15:25:30-05:00", "yyyy-MM-dd'T'HH:mm:ssXXX");
+ parseDate("2015-06-26T05:27:05.000Z", "yyyy-MM-dd'T'HH:mm:ss.'000Z'");
+ }
+
+ /**
+ * Method to parse StringDate to {@link Date}.
+ * @param strDate
+ * @param pattern
+ * @return {@link Date}
+ */
+ public static Date parseDate(String strDate, String pattern) {
+ /* Return object of Date */
+ Date date = null;
+ /* Get DateFormatter for given pattern */
+ DateFormat dateFormat = new SimpleDateFormat(pattern);
+ try {
+ /* Parse String to java.util.Date */
+ date = dateFormat.parse(strDate);
+ } catch (ParseException ex) {
+ ex.printStackTrace();
+ date = null;
+ }
+ /* Print the StringDate, Pattern and converted java Date */
+ System.out.println("Date: " + strDate + ", Pattern: " + pattern + " -> java.util.Date[" + date + "]");
+ return date;
+ }
+}
diff --git a/src/main/java/com/javaquery/core/exception/ArithmeticExceptionExample.java b/src/main/java/com/javaquery/core/exception/ArithmeticExceptionExample.java
new file mode 100644
index 0000000..efdbaba
--- /dev/null
+++ b/src/main/java/com/javaquery/core/exception/ArithmeticExceptionExample.java
@@ -0,0 +1,26 @@
+package com.javaquery.core.exception;
+
+/**
+ * Example of ArithmeticException in java.
+ * @author javaQuery
+ * @date 2021-09-07
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class ArithmeticExceptionExample {
+
+ public static void main(String[] args) {
+ int x = 10;
+ int y = getY();
+ System.out.println(x / y);
+ }
+
+ /**
+ * This is example of getting value from some method call.
+ * There is possibilities of getting value `0`.
+ *
+ * Java compiler can't identify such errors
+ */
+ public static int getY(){
+ return 2-2;
+ }
+}
diff --git a/src/main/java/com/javaquery/core/exception/StackOverflowErrorExample.java b/src/main/java/com/javaquery/core/exception/StackOverflowErrorExample.java
new file mode 100644
index 0000000..1310556
--- /dev/null
+++ b/src/main/java/com/javaquery/core/exception/StackOverflowErrorExample.java
@@ -0,0 +1,21 @@
+package com.javaquery.core.exception;
+
+/**
+ * Example of StackOverflowError in java.
+ * @author javaQuery
+ * @date 2021-09-07
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class StackOverflowErrorExample {
+ private static void recursion(int i){
+ if(i == 0){
+ System.out.println("Not reachable code");
+ }else{
+ recursion(i++);
+ }
+ }
+
+ public static void main(String[] args) {
+ recursion(10);
+ }
+}
diff --git a/src/main/java/com/javaquery/core/exception/SuperClassExceptionRule1.java b/src/main/java/com/javaquery/core/exception/SuperClassExceptionRule1.java
new file mode 100644
index 0000000..5017686
--- /dev/null
+++ b/src/main/java/com/javaquery/core/exception/SuperClassExceptionRule1.java
@@ -0,0 +1,33 @@
+package com.javaquery.core.exception;
+
+/**
+ * Example of SuperClassExceptionRule1 in java.
+ * @author javaQuery
+ * @date 2021-09-07
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class SuperClassExceptionRule1 {
+
+ public void methodWithoutException(){
+ System.out.println("methodWithoutException");
+ }
+
+ public static void main(String[] args) {
+ System.out.printf("SuperClassExceptionRule1");
+ }
+
+ public class ChildClassExceptionRule1 extends SuperClassExceptionRule1{
+
+// Compile time error when tried to throw checked exception
+// @Override
+// public void methodWithoutException() throws Exception{
+// super.methodWithoutException();
+// }
+
+ // Allowed to throw unchecked exception (i.e Any RuntimeException)
+ @Override
+ public void methodWithoutException() throws RuntimeException{
+ super.methodWithoutException();
+ }
+ }
+}
diff --git a/src/main/java/com/javaquery/core/exception/SuperClassExceptionRule2.java b/src/main/java/com/javaquery/core/exception/SuperClassExceptionRule2.java
new file mode 100644
index 0000000..e425e60
--- /dev/null
+++ b/src/main/java/com/javaquery/core/exception/SuperClassExceptionRule2.java
@@ -0,0 +1,43 @@
+package com.javaquery.core.exception;
+
+/**
+ * Example of SuperClassExceptionRule2 in java.
+ * @author javaQuery
+ * @date 2021-09-07
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class SuperClassExceptionRule2 {
+
+ public void methodWithException() throws IllegalArgumentException{
+ System.out.println("methodWithException");
+ }
+
+ public static void main(String[] args) {
+ System.out.printf("SuperClassExceptionRule2");
+ }
+
+ public class ChildClassExceptionRule2 extends SuperClassExceptionRule2 {
+
+// Compile time error when tried to throw parent exception
+// @Override
+// public void methodWithException() throws Exception{
+// super.methodWithException();
+// }
+
+ // Allowed to throw original exception (IllegalArgumentException)
+ // or child exception of IllegalArgumentException
+ @Override
+ public void methodWithException() throws NumberFormatException{
+ super.methodWithException();
+ }
+ }
+
+ public class ChildClassExceptionRule22 extends SuperClassExceptionRule2 {
+
+ // Allowed not to throw any exception
+ @Override
+ public void methodWithException(){
+ super.methodWithException();
+ }
+ }
+}
diff --git a/src/com/javaquery/core/immutable/ImmutableClassLatLon.java b/src/main/java/com/javaquery/core/immutable/ImmutableClassLatLon.java
similarity index 100%
rename from src/com/javaquery/core/immutable/ImmutableClassLatLon.java
rename to src/main/java/com/javaquery/core/immutable/ImmutableClassLatLon.java
diff --git a/src/com/javaquery/core/math/MathAbsExample.java b/src/main/java/com/javaquery/core/math/MathAbsExample.java
similarity index 96%
rename from src/com/javaquery/core/math/MathAbsExample.java
rename to src/main/java/com/javaquery/core/math/MathAbsExample.java
index 8da13ec..64c5d4e 100644
--- a/src/com/javaquery/core/math/MathAbsExample.java
+++ b/src/main/java/com/javaquery/core/math/MathAbsExample.java
@@ -1,34 +1,34 @@
-package com.javaquery.core.math;
-
-/**
- * Example: Math.abs
- * @author javaQuery
- * @date 31st December, 2015
- * @Github: https://github.com/javaquery/Examples
- */
-public class MathAbsExample {
-
- public static void main(String[] args) {
- int x = 1, y = -2;
-
- System.out.println("Before:");
- System.out.println("x = " + x + ", y = " + y);
-
- /**
- * Math.abs(int a)
- * Returns the absolute value of an int value.
- * - If the argument is not negative, the argument is returned.
- * - If the argument is negative, the negation of the argument is returned.
- *
- * Math.abs(int a) => return 'int'
- * Math.abs(long a) => return 'long'
- * Math.abs(float a) => return 'float'
- * Math.abs(double a) => return 'double'
- */
- x = Math.abs(x);
- y = Math.abs(y);
-
- System.out.println("After:");
- System.out.println("x = " + x + ", y = " + y);
- }
-}
+package com.javaquery.core.math;
+
+/**
+ * Example: Math.abs
+ * @author javaQuery
+ * @date 31st December, 2015
+ * @Github: https://github.com/javaquery/Examples
+ */
+public class MathAbsExample {
+
+ public static void main(String[] args) {
+ int x = 1, y = -2;
+
+ System.out.println("Before:");
+ System.out.println("x = " + x + ", y = " + y);
+
+ /**
+ * Math.abs(int a)
+ * Returns the absolute value of an int value.
+ * - If the argument is not negative, the argument is returned.
+ * - If the argument is negative, the negation of the argument is returned.
+ *
+ * Math.abs(int a) => return 'int'
+ * Math.abs(long a) => return 'long'
+ * Math.abs(float a) => return 'float'
+ * Math.abs(double a) => return 'double'
+ */
+ x = Math.abs(x);
+ y = Math.abs(y);
+
+ System.out.println("After:");
+ System.out.println("x = " + x + ", y = " + y);
+ }
+}
diff --git a/src/com/javaquery/database/PreparedStatementExample.java b/src/main/java/com/javaquery/database/PreparedStatementExample.java
similarity index 96%
rename from src/com/javaquery/database/PreparedStatementExample.java
rename to src/main/java/com/javaquery/database/PreparedStatementExample.java
index 0ec0335..21d42ee 100644
--- a/src/com/javaquery/database/PreparedStatementExample.java
+++ b/src/main/java/com/javaquery/database/PreparedStatementExample.java
@@ -1,48 +1,48 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.javaquery.database;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Example of SQL injection.
- * @author javaQuery
- * @date 8th November, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class PreparedStatementExample {
- public static void main(String[] args) {
- new PreparedStatementExample().getUser("12");
- }
-
- /**
- * Get user from database.
- * @param id
- * @return
- */
- public List