diff --git a/StorageSim/.classpath b/StorageSim/.classpath new file mode 100644 index 0000000..f57dc2f --- /dev/null +++ b/StorageSim/.classpath @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/StorageSim/.project b/StorageSim/.project new file mode 100644 index 0000000..ad69f5d --- /dev/null +++ b/StorageSim/.project @@ -0,0 +1,17 @@ + + + SVEN + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/StorageSim/.settings/org.eclipse.core.resources.prefs b/StorageSim/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..f5169ed --- /dev/null +++ b/StorageSim/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//src/storagesim/Simulation.java=UTF-8 +encoding//src/storagesim/StorageWindow.java=UTF-8 diff --git a/StorageSim/.settings/org.eclipse.jdt.core.prefs b/StorageSim/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ace45ce --- /dev/null +++ b/StorageSim/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/StorageSim/bin/Grafische_Oberfläche$1.class b/StorageSim/bin/Grafische_Oberfläche$1.class new file mode 100644 index 0000000..b10a91f Binary files /dev/null and b/StorageSim/bin/Grafische_Oberfläche$1.class differ diff --git a/StorageSim/bin/Grafische_Oberfläche$2.class b/StorageSim/bin/Grafische_Oberfläche$2.class new file mode 100644 index 0000000..e97b2d2 Binary files /dev/null and b/StorageSim/bin/Grafische_Oberfläche$2.class differ diff --git a/StorageSim/bin/Grafische_Oberfläche$3$1.class b/StorageSim/bin/Grafische_Oberfläche$3$1.class new file mode 100644 index 0000000..9c386c7 Binary files /dev/null and b/StorageSim/bin/Grafische_Oberfläche$3$1.class differ diff --git a/StorageSim/bin/Grafische_Oberfläche$3.class b/StorageSim/bin/Grafische_Oberfläche$3.class new file mode 100644 index 0000000..844307a Binary files /dev/null and b/StorageSim/bin/Grafische_Oberfläche$3.class differ diff --git a/StorageSim/bin/Grafische_Oberfläche$4.class b/StorageSim/bin/Grafische_Oberfläche$4.class new file mode 100644 index 0000000..692895c Binary files /dev/null and b/StorageSim/bin/Grafische_Oberfläche$4.class differ diff --git a/StorageSim/bin/Grafische_Oberfläche$5.class b/StorageSim/bin/Grafische_Oberfläche$5.class new file mode 100644 index 0000000..d692474 Binary files /dev/null and b/StorageSim/bin/Grafische_Oberfläche$5.class differ diff --git a/StorageSim/bin/Grafische_Oberfläche$6.class b/StorageSim/bin/Grafische_Oberfläche$6.class new file mode 100644 index 0000000..d88c791 Binary files /dev/null and b/StorageSim/bin/Grafische_Oberfläche$6.class differ diff --git a/StorageSim/bin/Grafische_Oberfläche$7.class b/StorageSim/bin/Grafische_Oberfläche$7.class new file mode 100644 index 0000000..9028275 Binary files /dev/null and b/StorageSim/bin/Grafische_Oberfläche$7.class differ diff --git a/StorageSim/bin/Grafische_Oberfläche.class b/StorageSim/bin/Grafische_Oberfläche.class new file mode 100644 index 0000000..eed0c69 Binary files /dev/null and b/StorageSim/bin/Grafische_Oberfläche.class differ diff --git a/StorageSim/bin/Main.class b/StorageSim/bin/Main.class new file mode 100644 index 0000000..5ee4608 Binary files /dev/null and b/StorageSim/bin/Main.class differ diff --git a/StorageSim/bin/lib/OpenSimplexNoise.class b/StorageSim/bin/lib/OpenSimplexNoise.class new file mode 100644 index 0000000..8e059c7 Binary files /dev/null and b/StorageSim/bin/lib/OpenSimplexNoise.class differ diff --git a/StorageSim/bin/lib/SQLConnection.class b/StorageSim/bin/lib/SQLConnection.class new file mode 100644 index 0000000..550c128 Binary files /dev/null and b/StorageSim/bin/lib/SQLConnection.class differ diff --git a/StorageSim/bin/org/mindrot/BCrypt.class b/StorageSim/bin/org/mindrot/BCrypt.class new file mode 100644 index 0000000..f55d3e1 Binary files /dev/null and b/StorageSim/bin/org/mindrot/BCrypt.class differ diff --git a/StorageSim/bin/res/Roboter_1.png b/StorageSim/bin/res/Roboter_1.png new file mode 100644 index 0000000..0dce4fa Binary files /dev/null and b/StorageSim/bin/res/Roboter_1.png differ diff --git a/StorageSim/bin/res/Roboter_2.png b/StorageSim/bin/res/Roboter_2.png new file mode 100644 index 0000000..d08cfd8 Binary files /dev/null and b/StorageSim/bin/res/Roboter_2.png differ diff --git a/StorageSim/bin/res/Template.xlsx b/StorageSim/bin/res/Template.xlsx new file mode 100644 index 0000000..8346a9a Binary files /dev/null and b/StorageSim/bin/res/Template.xlsx differ diff --git a/StorageSim/bin/res/palette.png b/StorageSim/bin/res/palette.png new file mode 100644 index 0000000..72908b7 Binary files /dev/null and b/StorageSim/bin/res/palette.png differ diff --git a/StorageSim/bin/res/pixelart/1.png b/StorageSim/bin/res/pixelart/1.png new file mode 100644 index 0000000..da56220 Binary files /dev/null and b/StorageSim/bin/res/pixelart/1.png differ diff --git a/StorageSim/bin/res/pixelart/10.png b/StorageSim/bin/res/pixelart/10.png new file mode 100644 index 0000000..2c7f034 Binary files /dev/null and b/StorageSim/bin/res/pixelart/10.png differ diff --git a/StorageSim/bin/res/pixelart/11.png b/StorageSim/bin/res/pixelart/11.png new file mode 100644 index 0000000..de862ff Binary files /dev/null and b/StorageSim/bin/res/pixelart/11.png differ diff --git a/StorageSim/bin/res/pixelart/12.png b/StorageSim/bin/res/pixelart/12.png new file mode 100644 index 0000000..feacb1c Binary files /dev/null and b/StorageSim/bin/res/pixelart/12.png differ diff --git a/StorageSim/bin/res/pixelart/13.png b/StorageSim/bin/res/pixelart/13.png new file mode 100644 index 0000000..090d702 Binary files /dev/null and b/StorageSim/bin/res/pixelart/13.png differ diff --git a/StorageSim/bin/res/pixelart/14.png b/StorageSim/bin/res/pixelart/14.png new file mode 100644 index 0000000..fbdeee5 Binary files /dev/null and b/StorageSim/bin/res/pixelart/14.png differ diff --git a/StorageSim/bin/res/pixelart/15.png b/StorageSim/bin/res/pixelart/15.png new file mode 100644 index 0000000..febeb9d Binary files /dev/null and b/StorageSim/bin/res/pixelart/15.png differ diff --git a/StorageSim/bin/res/pixelart/16.png b/StorageSim/bin/res/pixelart/16.png new file mode 100644 index 0000000..211e8ce Binary files /dev/null and b/StorageSim/bin/res/pixelart/16.png differ diff --git a/StorageSim/bin/res/pixelart/17.png b/StorageSim/bin/res/pixelart/17.png new file mode 100644 index 0000000..69d7304 Binary files /dev/null and b/StorageSim/bin/res/pixelart/17.png differ diff --git a/StorageSim/bin/res/pixelart/18.png b/StorageSim/bin/res/pixelart/18.png new file mode 100644 index 0000000..a541fe3 Binary files /dev/null and b/StorageSim/bin/res/pixelart/18.png differ diff --git a/StorageSim/bin/res/pixelart/19.png b/StorageSim/bin/res/pixelart/19.png new file mode 100644 index 0000000..69196dd Binary files /dev/null and b/StorageSim/bin/res/pixelart/19.png differ diff --git a/StorageSim/bin/res/pixelart/2.png b/StorageSim/bin/res/pixelart/2.png new file mode 100644 index 0000000..bfde7a0 Binary files /dev/null and b/StorageSim/bin/res/pixelart/2.png differ diff --git a/StorageSim/bin/res/pixelart/20.png b/StorageSim/bin/res/pixelart/20.png new file mode 100644 index 0000000..384b117 Binary files /dev/null and b/StorageSim/bin/res/pixelart/20.png differ diff --git a/StorageSim/bin/res/pixelart/21.png b/StorageSim/bin/res/pixelart/21.png new file mode 100644 index 0000000..166c87a Binary files /dev/null and b/StorageSim/bin/res/pixelart/21.png differ diff --git a/StorageSim/bin/res/pixelart/22.png b/StorageSim/bin/res/pixelart/22.png new file mode 100644 index 0000000..aad7ead Binary files /dev/null and b/StorageSim/bin/res/pixelart/22.png differ diff --git a/StorageSim/bin/res/pixelart/23.png b/StorageSim/bin/res/pixelart/23.png new file mode 100644 index 0000000..2f42152 Binary files /dev/null and b/StorageSim/bin/res/pixelart/23.png differ diff --git a/StorageSim/bin/res/pixelart/24.png b/StorageSim/bin/res/pixelart/24.png new file mode 100644 index 0000000..372b412 Binary files /dev/null and b/StorageSim/bin/res/pixelart/24.png differ diff --git a/StorageSim/bin/res/pixelart/25.png b/StorageSim/bin/res/pixelart/25.png new file mode 100644 index 0000000..55d0b53 Binary files /dev/null and b/StorageSim/bin/res/pixelart/25.png differ diff --git a/StorageSim/bin/res/pixelart/26.png b/StorageSim/bin/res/pixelart/26.png new file mode 100644 index 0000000..1cd7f4e Binary files /dev/null and b/StorageSim/bin/res/pixelart/26.png differ diff --git a/StorageSim/bin/res/pixelart/27.png b/StorageSim/bin/res/pixelart/27.png new file mode 100644 index 0000000..0345e55 Binary files /dev/null and b/StorageSim/bin/res/pixelart/27.png differ diff --git a/StorageSim/bin/res/pixelart/28.png b/StorageSim/bin/res/pixelart/28.png new file mode 100644 index 0000000..d978a37 Binary files /dev/null and b/StorageSim/bin/res/pixelart/28.png differ diff --git a/StorageSim/bin/res/pixelart/29.png b/StorageSim/bin/res/pixelart/29.png new file mode 100644 index 0000000..8adbba3 Binary files /dev/null and b/StorageSim/bin/res/pixelart/29.png differ diff --git a/StorageSim/bin/res/pixelart/3.png b/StorageSim/bin/res/pixelart/3.png new file mode 100644 index 0000000..06c1e61 Binary files /dev/null and b/StorageSim/bin/res/pixelart/3.png differ diff --git a/StorageSim/bin/res/pixelart/30.png b/StorageSim/bin/res/pixelart/30.png new file mode 100644 index 0000000..13df259 Binary files /dev/null and b/StorageSim/bin/res/pixelart/30.png differ diff --git a/StorageSim/bin/res/pixelart/31.png b/StorageSim/bin/res/pixelart/31.png new file mode 100644 index 0000000..8583790 Binary files /dev/null and b/StorageSim/bin/res/pixelart/31.png differ diff --git a/StorageSim/bin/res/pixelart/32.png b/StorageSim/bin/res/pixelart/32.png new file mode 100644 index 0000000..1879e10 Binary files /dev/null and b/StorageSim/bin/res/pixelart/32.png differ diff --git a/StorageSim/bin/res/pixelart/33.png b/StorageSim/bin/res/pixelart/33.png new file mode 100644 index 0000000..6388984 Binary files /dev/null and b/StorageSim/bin/res/pixelart/33.png differ diff --git a/StorageSim/bin/res/pixelart/34.png b/StorageSim/bin/res/pixelart/34.png new file mode 100644 index 0000000..a9ea101 Binary files /dev/null and b/StorageSim/bin/res/pixelart/34.png differ diff --git a/StorageSim/bin/res/pixelart/35.png b/StorageSim/bin/res/pixelart/35.png new file mode 100644 index 0000000..a722b65 Binary files /dev/null and b/StorageSim/bin/res/pixelart/35.png differ diff --git a/StorageSim/bin/res/pixelart/36.png b/StorageSim/bin/res/pixelart/36.png new file mode 100644 index 0000000..f3eafa2 Binary files /dev/null and b/StorageSim/bin/res/pixelart/36.png differ diff --git a/StorageSim/bin/res/pixelart/37.png b/StorageSim/bin/res/pixelart/37.png new file mode 100644 index 0000000..0fec0b4 Binary files /dev/null and b/StorageSim/bin/res/pixelart/37.png differ diff --git a/StorageSim/bin/res/pixelart/38.png b/StorageSim/bin/res/pixelart/38.png new file mode 100644 index 0000000..dcba85c Binary files /dev/null and b/StorageSim/bin/res/pixelart/38.png differ diff --git a/StorageSim/bin/res/pixelart/39.png b/StorageSim/bin/res/pixelart/39.png new file mode 100644 index 0000000..bdc0c57 Binary files /dev/null and b/StorageSim/bin/res/pixelart/39.png differ diff --git a/StorageSim/bin/res/pixelart/4.png b/StorageSim/bin/res/pixelart/4.png new file mode 100644 index 0000000..e3bc964 Binary files /dev/null and b/StorageSim/bin/res/pixelart/4.png differ diff --git a/StorageSim/bin/res/pixelart/40.png b/StorageSim/bin/res/pixelart/40.png new file mode 100644 index 0000000..0d20776 Binary files /dev/null and b/StorageSim/bin/res/pixelart/40.png differ diff --git a/StorageSim/bin/res/pixelart/41.png b/StorageSim/bin/res/pixelart/41.png new file mode 100644 index 0000000..cfa8a9a Binary files /dev/null and b/StorageSim/bin/res/pixelart/41.png differ diff --git a/StorageSim/bin/res/pixelart/42.png b/StorageSim/bin/res/pixelart/42.png new file mode 100644 index 0000000..4384555 Binary files /dev/null and b/StorageSim/bin/res/pixelart/42.png differ diff --git a/StorageSim/bin/res/pixelart/43.png b/StorageSim/bin/res/pixelart/43.png new file mode 100644 index 0000000..f7c4c7f Binary files /dev/null and b/StorageSim/bin/res/pixelart/43.png differ diff --git a/StorageSim/bin/res/pixelart/44.png b/StorageSim/bin/res/pixelart/44.png new file mode 100644 index 0000000..5678351 Binary files /dev/null and b/StorageSim/bin/res/pixelart/44.png differ diff --git a/StorageSim/bin/res/pixelart/45.png b/StorageSim/bin/res/pixelart/45.png new file mode 100644 index 0000000..2c813d7 Binary files /dev/null and b/StorageSim/bin/res/pixelart/45.png differ diff --git a/StorageSim/bin/res/pixelart/46.png b/StorageSim/bin/res/pixelart/46.png new file mode 100644 index 0000000..6674bfd Binary files /dev/null and b/StorageSim/bin/res/pixelart/46.png differ diff --git a/StorageSim/bin/res/pixelart/47.png b/StorageSim/bin/res/pixelart/47.png new file mode 100644 index 0000000..7eaac0d Binary files /dev/null and b/StorageSim/bin/res/pixelart/47.png differ diff --git a/StorageSim/bin/res/pixelart/48.png b/StorageSim/bin/res/pixelart/48.png new file mode 100644 index 0000000..238d81b Binary files /dev/null and b/StorageSim/bin/res/pixelart/48.png differ diff --git a/StorageSim/bin/res/pixelart/49.png b/StorageSim/bin/res/pixelart/49.png new file mode 100644 index 0000000..24d7dd1 Binary files /dev/null and b/StorageSim/bin/res/pixelart/49.png differ diff --git a/StorageSim/bin/res/pixelart/5.png b/StorageSim/bin/res/pixelart/5.png new file mode 100644 index 0000000..1fa61f6 Binary files /dev/null and b/StorageSim/bin/res/pixelart/5.png differ diff --git a/StorageSim/bin/res/pixelart/50.png b/StorageSim/bin/res/pixelart/50.png new file mode 100644 index 0000000..a56ca0a Binary files /dev/null and b/StorageSim/bin/res/pixelart/50.png differ diff --git a/StorageSim/bin/res/pixelart/6.png b/StorageSim/bin/res/pixelart/6.png new file mode 100644 index 0000000..a38bfbc Binary files /dev/null and b/StorageSim/bin/res/pixelart/6.png differ diff --git a/StorageSim/bin/res/pixelart/7.png b/StorageSim/bin/res/pixelart/7.png new file mode 100644 index 0000000..832c77f Binary files /dev/null and b/StorageSim/bin/res/pixelart/7.png differ diff --git a/StorageSim/bin/res/pixelart/8.png b/StorageSim/bin/res/pixelart/8.png new file mode 100644 index 0000000..0fca22d Binary files /dev/null and b/StorageSim/bin/res/pixelart/8.png differ diff --git a/StorageSim/bin/res/pixelart/9.png b/StorageSim/bin/res/pixelart/9.png new file mode 100644 index 0000000..833498a Binary files /dev/null and b/StorageSim/bin/res/pixelart/9.png differ diff --git a/StorageSim/bin/res/store.png b/StorageSim/bin/res/store.png new file mode 100644 index 0000000..fc3ec09 Binary files /dev/null and b/StorageSim/bin/res/store.png differ diff --git a/StorageSim/bin/storagesim/BWLHelper.class b/StorageSim/bin/storagesim/BWLHelper.class new file mode 100644 index 0000000..fc00f0f Binary files /dev/null and b/StorageSim/bin/storagesim/BWLHelper.class differ diff --git a/StorageSim/bin/storagesim/MapPanel$1.class b/StorageSim/bin/storagesim/MapPanel$1.class new file mode 100644 index 0000000..fe22ab5 Binary files /dev/null and b/StorageSim/bin/storagesim/MapPanel$1.class differ diff --git a/StorageSim/bin/storagesim/MapPanel$Controls.class b/StorageSim/bin/storagesim/MapPanel$Controls.class new file mode 100644 index 0000000..1753ea2 Binary files /dev/null and b/StorageSim/bin/storagesim/MapPanel$Controls.class differ diff --git a/StorageSim/bin/storagesim/MapPanel.class b/StorageSim/bin/storagesim/MapPanel.class new file mode 100644 index 0000000..0cfeaa0 Binary files /dev/null and b/StorageSim/bin/storagesim/MapPanel.class differ diff --git a/StorageSim/bin/storagesim/Simulation.class b/StorageSim/bin/storagesim/Simulation.class new file mode 100644 index 0000000..f4b22ce Binary files /dev/null and b/StorageSim/bin/storagesim/Simulation.class differ diff --git a/StorageSim/bin/storagesim/StorageMap$Tile.class b/StorageSim/bin/storagesim/StorageMap$Tile.class new file mode 100644 index 0000000..1c07bd4 Binary files /dev/null and b/StorageSim/bin/storagesim/StorageMap$Tile.class differ diff --git a/StorageSim/bin/storagesim/StorageMap.class b/StorageSim/bin/storagesim/StorageMap.class new file mode 100644 index 0000000..eb7ecd8 Binary files /dev/null and b/StorageSim/bin/storagesim/StorageMap.class differ diff --git a/StorageSim/bin/storagesim/StorageWindow.class b/StorageSim/bin/storagesim/StorageWindow.class new file mode 100644 index 0000000..a8d3bda Binary files /dev/null and b/StorageSim/bin/storagesim/StorageWindow.class differ diff --git a/StorageSim/mysql-connector-java-5.1.37-bin.jar b/StorageSim/mysql-connector-java-5.1.37-bin.jar new file mode 100644 index 0000000..465af67 Binary files /dev/null and b/StorageSim/mysql-connector-java-5.1.37-bin.jar differ diff --git a/StorageSim/poi-3.17/LICENSE b/StorageSim/poi-3.17/LICENSE new file mode 100644 index 0000000..3b63d08 --- /dev/null +++ b/StorageSim/poi-3.17/LICENSE @@ -0,0 +1,537 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +APACHE POI SUBCOMPONENTS: + +Apache POI includes subcomponents with separate copyright notices and +license terms. Your use of these subcomponents is subject to the terms +and conditions of the following licenses: + + +Office Open XML schemas (ooxml-schemas-1.*.jar) + + The Office Open XML schema definitions used by Apache POI are + a part of the Office Open XML ECMA Specification (ECMA-376, [1]). + As defined in section 9.4 of the ECMA bylaws [2], this specification + is available to all interested parties without restriction: + + 9.4 All documents when approved shall be made available to + all interested parties without restriction. + + Furthermore, both Microsoft and Adobe have granted patent licenses + to this work [3,4,5]. + + [1] http://www.ecma-international.org/publications/standards/Ecma-376.htm + [2] http://www.ecma-international.org/memento/Ecmabylaws.htm + [3] http://www.microsoft.com/openspecifications/en/us/programs/osp/default.aspx + [4] http://www.ecma-international.org/publications/files/ECMA-ST/Ecma%20PATENT/ + Patent%20statements%20ok/ECMA-376%20Edition%202%20Microsoft%20Patent%20Declaration.pdf + [5] http://www.ecma-international.org/publications/files/ECMA-ST/Ecma%20PATENT/ + Patent%20statements%20ok/ECMA-376%20Adobe%20Patent%20Declaration.pdf + + +Bouncy Castle library (bcprov-*.jar, bcpg-*.jar, bcpkix-*.jar) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + +JUnit test library (junit-4.*.jar) & JaCoCo (*jacoco*) + + Eclipse Public License - v 1.0 + + THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC + LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM + CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + + 1. DEFINITIONS + + "Contribution" means: + + a) in the case of the initial Contributor, the initial code and documentation + distributed under this Agreement, and + b) in the case of each subsequent Contributor: + i) changes to the Program, and + ii) additions to the Program; + where such changes and/or additions to the Program originate from and are + distributed by that particular Contributor. A Contribution 'originates' from + a Contributor if it was added to the Program by such Contributor itself or + anyone acting on such Contributor's behalf. Contributions do not include + additions to the Program which: (i) are separate modules of software + distributed in conjunction with the Program under their own license agreement, + and (ii) are not derivative works of the Program. + + "Contributor" means any person or entity that distributes the Program. + + "Licensed Patents" mean patent claims licensable by a Contributor which are + necessarily infringed by the use or sale of its Contribution alone or when + combined with the Program. + + "Program" means the Contributions distributed in accordance with this Agreement. + + "Recipient" means anyone who receives the Program under this Agreement, + including all Contributors. + + 2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free copyright license to + reproduce, prepare derivative works of, publicly display, publicly + perform, distribute and sublicense the Contribution of such Contributor, + if any, and such derivative works, in source code and object code form. + b) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free patent license under + Licensed Patents to make, use, sell, offer to sell, import and otherwise + transfer the Contribution of such Contributor, if any, in source code + and object code form. This patent license shall apply to the combination + of the Contribution and the Program if, at the time the Contribution is + added by the Contributor, such addition of the Contribution causes such + combination to be covered by the Licensed Patents. The patent license + shall not apply to any other combinations which include the Contribution. + No hardware per se is licensed hereunder. + c) Recipient understands that although each Contributor grants the licenses + to its Contributions set forth herein, no assurances are provided by any + Contributor that the Program does not infringe the patent or other + intellectual property rights of any other entity. Each Contributor + disclaims any liability to Recipient for claims brought by any other + entity based on infringement of intellectual property rights or + otherwise. As a condition to exercising the rights and licenses granted + hereunder, each Recipient hereby assumes sole responsibility to secure + any other intellectual property rights needed, if any. For example, if + a third party patent license is required to allow Recipient to distribute + the Program, it is Recipient's responsibility to acquire that license + before distributing the Program. + d) Each Contributor represents that to its knowledge it has sufficient + copyright rights in its Contribution, if any, to grant the copyright + license set forth in this Agreement. + + 3. REQUIREMENTS + + A Contributor may choose to distribute the Program in object code form under + its own license agreement, provided that: + + a) it complies with the terms and conditions of this Agreement; and + b) its license agreement: + i) effectively disclaims on behalf of all Contributors all warranties and + conditions, express and implied, including warranties or conditions of + title and non-infringement, and implied warranties or conditions of + merchantability and fitness for a particular purpose; + ii) effectively excludes on behalf of all Contributors all liability for + damages, including direct, indirect, special, incidental and + consequential damages, such as lost profits; + iii) states that any provisions which differ from this Agreement are + offered by that Contributor alone and not by any other party; and + iv) states that source code for the Program is available from such + Contributor, and informs licensees how to obtain it in a reasonable + manner on or through a medium customarily used for software exchange. + + When the Program is made available in source code form: + + a) it must be made available under this Agreement; and + b) a copy of this Agreement must be included with each copy of the Program. + Contributors may not remove or alter any copyright notices contained + within the Program. + + Each Contributor must identify itself as the originator of its Contribution, + if any, in a manner that reasonably allows subsequent Recipients to identify + the originator of the Contribution. + + 4. COMMERCIAL DISTRIBUTION + + Commercial distributors of software may accept certain responsibilities with + respect to end users, business partners and the like. While this license is + intended to facilitate the commercial use of the Program, the Contributor + who includes the Program in a commercial product offering should do so in a + manner which does not create potential liability for other Contributors. + Therefore, if a Contributor includes the Program in a commercial product + offering, such Contributor ("Commercial Contributor") hereby agrees to + defend and indemnify every other Contributor ("Indemnified Contributor") + against any losses, damages and costs (collectively "Losses") arising from + claims, lawsuits and other legal actions brought by a third party against + the Indemnified Contributor to the extent caused by the acts or omissions + of such Commercial Contributor in connection with its distribution of the + Program in a commercial product offering. The obligations in this section + do not apply to any claims or Losses relating to any actual or alleged + intellectual property infringement. In order to qualify, an Indemnified + Contributor must: a) promptly notify the Commercial Contributor in writing + of such claim, and b) allow the Commercial Contributor to control, and + cooperate with the Commercial Contributor in, the defense and any related + settlement negotiations. The Indemnified Contributor may participate in any + such claim at its own expense. + + For example, a Contributor might include the Program in a commercial product + offering, Product X. That Contributor is then a Commercial Contributor. If + that Commercial Contributor then makes performance claims, or offers + warranties related to Product X, those performance claims and warranties are + such Commercial Contributor's responsibility alone. Under this section, the + Commercial Contributor would have to defend claims against the other + Contributors related to those performance claims and warranties, and if a + court requires any other Contributor to pay any damages as a result, the + Commercial Contributor must pay those damages. + + 5. NO WARRANTY + + EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON + AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER + EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR + CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A + PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the + appropriateness of using and distributing the Program and assumes all risks + associated with its exercise of rights under this Agreement , including but + not limited to the risks and costs of program errors, compliance with + applicable laws, damage to or loss of data, programs or equipment, and + unavailability or interruption of operations. + + 6. DISCLAIMER OF LIABILITY + + EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY + CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION + LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE + EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY + OF SUCH DAMAGES. + + 7. GENERAL + + If any provision of this Agreement is invalid or unenforceable under + applicable law, it shall not affect the validity or enforceability of the + remainder of the terms of this Agreement, and without further action by the + parties hereto, such provision shall be reformed to the minimum extent + necessary to make such provision valid and enforceable. + + If Recipient institutes patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Program itself + (excluding combinations of the Program with other software or hardware) + infringes such Recipient's patent(s), then such Recipient's rights granted + under Section 2(b) shall terminate as of the date such litigation is filed. + + All Recipient's rights under this Agreement shall terminate if it fails to + comply with any of the material terms or conditions of this Agreement and + does not cure such failure in a reasonable period of time after becoming + aware of such noncompliance. If all Recipient's rights under this Agreement + terminate, Recipient agrees to cease use and distribution of the Program as + soon as reasonably practicable. However, Recipient's obligations under this + Agreement and any licenses granted by Recipient relating to the Program + shall continue and survive. + + Everyone is permitted to copy and distribute copies of this Agreement, but + in order to avoid inconsistency the Agreement is copyrighted and may only + be modified in the following manner. The Agreement Steward reserves the + right to publish new versions (including revisions) of this Agreement from + time to time. No one other than the Agreement Steward has the right to + modify this Agreement. The Eclipse Foundation is the initial Agreement + Steward. The Eclipse Foundation may assign the responsibility to serve as + the Agreement Steward to a suitable separate entity. Each new version of + the Agreement will be given a distinguishing version number. The Program + (including Contributions) may always be distributed subject to the version + of the Agreement under which it was received. In addition, after a new + version of the Agreement is published, Contributor may elect to distribute + the Program (including its Contributions) under the new version. Except as + expressly stated in Sections 2(a) and 2(b) above, Recipient receives no + rights or licenses to the intellectual property of any Contributor under + this Agreement, whether expressly, by implication, estoppel or otherwise. + All rights in the Program not expressly granted under this Agreement are + reserved. + + This Agreement is governed by the laws of the State of New York and the + intellectual property laws of the United States of America. No party to this + Agreement will bring a legal action under this Agreement more than one year + after the cause of action arose. Each party waives its rights to a jury + trial in any resulting litigation. + +Hamcrest library (hamcrest-*.jar) & CuvesAPI / Curve API + + BSD License + + Copyright (c) 2000-2006, www.hamcrest.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions and + the following disclaimer in the documentation and/or other materials + provided with the distribution. + + Neither the name of Hamcrest nor the names of its contributors may be used + to endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +SLF4J library (slf4j-api-*.jar) + + Copyright (c) 2004-2013 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +inbot-utils (https://github.com/Inbot/inbot-utils) + + The MIT License (MIT) + + Copyright (c) 2015 Inbot + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. \ No newline at end of file diff --git a/StorageSim/poi-3.17/NOTICE b/StorageSim/poi-3.17/NOTICE new file mode 100644 index 0000000..15f1611 --- /dev/null +++ b/StorageSim/poi-3.17/NOTICE @@ -0,0 +1,27 @@ +Apache POI +Copyright 2003-2017 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (https://www.apache.org/). + +This product contains parts that were originally based on software from BEA. +Copyright (c) 2000-2003, BEA Systems, (dead link), +which was acquired by Oracle Corporation in 2008. + + + +This product contains W3C XML Schema documents. Copyright 2001-2003 (c) +World Wide Web Consortium (Massachusetts Institute of Technology, European +Research Consortium for Informatics and Mathematics, Keio University) + +This product contains the Piccolo XML Parser for Java +(http://piccolo.sourceforge.net/). Copyright 2002 Yuval Oren. + +This product contains the chunks_parse_cmds.tbl file from the vsdump program. +Copyright (C) 2006-2007 Valek Filippov (frob@df.ru) + +This product contains parts of the eID Applet project + and . +Copyright (c) 2009-2014 +FedICT (federal ICT department of Belgium), e-Contract.be BVBA (https://www.e-contract.be), +Bart Hanssens from FedICT diff --git a/StorageSim/poi-3.17/lib/commons-codec-1.10.jar b/StorageSim/poi-3.17/lib/commons-codec-1.10.jar new file mode 100644 index 0000000..1d7417c Binary files /dev/null and b/StorageSim/poi-3.17/lib/commons-codec-1.10.jar differ diff --git a/StorageSim/poi-3.17/lib/commons-collections4-4.1.jar b/StorageSim/poi-3.17/lib/commons-collections4-4.1.jar new file mode 100644 index 0000000..43a9413 Binary files /dev/null and b/StorageSim/poi-3.17/lib/commons-collections4-4.1.jar differ diff --git a/StorageSim/poi-3.17/lib/commons-logging-1.2.jar b/StorageSim/poi-3.17/lib/commons-logging-1.2.jar new file mode 100644 index 0000000..93a3b9f Binary files /dev/null and b/StorageSim/poi-3.17/lib/commons-logging-1.2.jar differ diff --git a/StorageSim/poi-3.17/lib/junit-4.12.jar b/StorageSim/poi-3.17/lib/junit-4.12.jar new file mode 100644 index 0000000..3a7fc26 Binary files /dev/null and b/StorageSim/poi-3.17/lib/junit-4.12.jar differ diff --git a/StorageSim/poi-3.17/lib/log4j-1.2.17.jar b/StorageSim/poi-3.17/lib/log4j-1.2.17.jar new file mode 100644 index 0000000..1d425cf Binary files /dev/null and b/StorageSim/poi-3.17/lib/log4j-1.2.17.jar differ diff --git a/StorageSim/poi-3.17/ooxml-lib/curvesapi-1.04.jar b/StorageSim/poi-3.17/ooxml-lib/curvesapi-1.04.jar new file mode 100644 index 0000000..f097d0b Binary files /dev/null and b/StorageSim/poi-3.17/ooxml-lib/curvesapi-1.04.jar differ diff --git a/StorageSim/poi-3.17/ooxml-lib/xmlbeans-2.6.0.jar b/StorageSim/poi-3.17/ooxml-lib/xmlbeans-2.6.0.jar new file mode 100644 index 0000000..d1b6627 Binary files /dev/null and b/StorageSim/poi-3.17/ooxml-lib/xmlbeans-2.6.0.jar differ diff --git a/StorageSim/poi-3.17/poi-3.17.jar b/StorageSim/poi-3.17/poi-3.17.jar new file mode 100644 index 0000000..353ce76 Binary files /dev/null and b/StorageSim/poi-3.17/poi-3.17.jar differ diff --git a/StorageSim/poi-3.17/poi-examples-3.17.jar b/StorageSim/poi-3.17/poi-examples-3.17.jar new file mode 100644 index 0000000..a923b04 Binary files /dev/null and b/StorageSim/poi-3.17/poi-examples-3.17.jar differ diff --git a/StorageSim/poi-3.17/poi-excelant-3.17.jar b/StorageSim/poi-3.17/poi-excelant-3.17.jar new file mode 100644 index 0000000..da9f5ed Binary files /dev/null and b/StorageSim/poi-3.17/poi-excelant-3.17.jar differ diff --git a/StorageSim/poi-3.17/poi-ooxml-3.17.jar b/StorageSim/poi-3.17/poi-ooxml-3.17.jar new file mode 100644 index 0000000..68086e8 Binary files /dev/null and b/StorageSim/poi-3.17/poi-ooxml-3.17.jar differ diff --git a/StorageSim/poi-3.17/poi-ooxml-schemas-3.17.jar b/StorageSim/poi-3.17/poi-ooxml-schemas-3.17.jar new file mode 100644 index 0000000..2e9b3e7 Binary files /dev/null and b/StorageSim/poi-3.17/poi-ooxml-schemas-3.17.jar differ diff --git a/StorageSim/poi-3.17/poi-scratchpad-3.17.jar b/StorageSim/poi-3.17/poi-scratchpad-3.17.jar new file mode 100644 index 0000000..12ba1f1 Binary files /dev/null and b/StorageSim/poi-3.17/poi-scratchpad-3.17.jar differ diff --git a/StorageSim/src/Grafische_Oberfläche.java b/StorageSim/src/Grafische_Oberfläche.java new file mode 100644 index 0000000..98d01ae --- /dev/null +++ b/StorageSim/src/Grafische_Oberfläche.java @@ -0,0 +1,269 @@ +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JButton; +import javax.swing.JTextField; +import javax.swing.JComboBox; +import javax.swing.JSlider; +import javax.swing.JLabel; +import javax.swing.SwingConstants; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.awt.event.ActionEvent; +import java.time.LocalDate; +import javax.swing.event.ChangeListener; + +import org.mindrot.BCrypt; + +import storagesim.Simulation; +import storagesim.StorageWindow; + +import javax.swing.event.ChangeEvent; +import java.awt.Toolkit; +import lib.SQLConnection; + +public class Grafische_Oberfläche extends JFrame { + + private static final long serialVersionUID = 1L; + + private JPanel contentPane; + private JTextField textField; + private JTextField txtpw; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Grafische_Oberfläche frame = new Grafische_Oberfläche(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + LocalDate currentTime; + + /** + * Create the frame. + */ + public Grafische_Oberfläche() { + setIconImage(Toolkit.getDefaultToolkit().getImage(Grafische_Oberfläche.class.getResource("/javax/swing/plaf/metal/icons/ocean/homeFolder.gif"))); + setTitle("Lager Verwaltung"); + + currentTime = LocalDate.parse("2018-01-01"); + + SQLConnection db = new SQLConnection("102-012/sven"); + + ArrayList> MaximaleMenge = db.queryToMap("SELECT * FROM t_artikel"); + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 277, 496); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + + JLabel lblMenge = new JLabel("Menge ="); + lblMenge.setHorizontalAlignment(SwingConstants.LEFT); + lblMenge.setBounds(36, 108, 93, 14); + contentPane.add(lblMenge); + lblMenge.setVisible(false); + + JTextField txtDatum = new JTextField(currentTime.toString()); + txtDatum.setBounds(10, 329, 91, 33); + contentPane.add(txtDatum); + txtDatum.setEditable(false); + txtDatum.setVisible(false); + + JButton btnPlus1 = new JButton("+ 1"); + btnPlus1.setBounds(100, 329, 36, 33); + btnPlus1.addActionListener((a) -> { + currentTime = currentTime.plusDays(1); + txtDatum.setText(currentTime.toString()); + }); + contentPane.add(btnPlus1); + btnPlus1.setVisible(false); + + JButton btnPlus7 = new JButton("+ 7"); + btnPlus7.setBounds(136, 329, 36, 33); + btnPlus7.addActionListener((a) -> { + currentTime = currentTime.plusDays(7); + txtDatum.setText(currentTime.toString()); + }); + contentPane.add(btnPlus7); + btnPlus7.setVisible(false); + + JButton btnWchentlichesberprfen = new JButton("Zeitverstreichung simulieren"); + btnWchentlichesberprfen.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + new Simulation().run(currentTime); + System.out.println("Fertiggestellt"); + } + }); + btnWchentlichesberprfen.setBounds(10, 369, 241, 33); + contentPane.add(btnWchentlichesberprfen); + btnWchentlichesberprfen.setVisible(false); + + JButton btnSimulationStarten = new JButton("Lageransicht öffnen"); + btnSimulationStarten.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + try { + StorageWindow w = new StorageWindow(); + w.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + btnSimulationStarten.setBounds(10, 413, 241, 33); + contentPane.add(btnSimulationStarten); + btnSimulationStarten.setVisible(false); + + JSlider slider = new JSlider(); + slider.setMinimum(1); + slider.setMaximum(1); + slider.setPaintTicks(true); + slider.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent arg0) { + lblMenge.setText("Menge = " + slider.getValue()); + } + }); + slider.setOrientation(SwingConstants.VERTICAL); + slider.setMajorTickSpacing(25); + slider.setMinorTickSpacing(1); + slider.setBounds(149, 20, 102, 328); + contentPane.add(slider); + slider.setVisible(false); + + JLabel lblItemId = new JLabel("Item ID"); + lblItemId.setHorizontalAlignment(SwingConstants.CENTER); + lblItemId.setBounds(36, 20, 46, 20); + contentPane.add(lblItemId); + lblItemId.setVisible(false); + + JComboBox comboBox = new JComboBox<>(); + comboBox.setVisible(false); + + + for(int i = 1; i <= 50; i++) + { + comboBox.addItem(i); + } + comboBox.setSelectedIndex(0); + slider.setMaximum(Integer.parseInt(MaximaleMenge.get(comboBox.getSelectedIndex()).get("Anzahl_pro_Palette"))); + lblMenge.setText("Menge = " + slider.getValue()); + comboBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + + if(Integer.parseInt(MaximaleMenge.get(comboBox.getSelectedIndex()).get("Anzahl_pro_Palette")) != 0) + { + slider.setMaximum(Integer.parseInt(MaximaleMenge.get(comboBox.getSelectedIndex()).get("Anzahl_pro_Palette"))); + } + } + }); + comboBox.setBounds(36, 59, 42, 27); + contentPane.add(comboBox); + + JButton btnNachbestellen = new JButton("Nachbestellen"); + btnNachbestellen.setVisible(false); + btnNachbestellen.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + //SQLConnection db = new SQLConnection("192.168.102.16/sven"); + + LocalDate ankunft; + if((comboBox.getSelectedIndex()+1) > 0) + { + ankunft = currentTime.plusDays(Integer.parseInt(MaximaleMenge.get((comboBox.getSelectedIndex())).get("Lieferzeit"))); + db.execute("INSERT INTO `t_bestellungen` (`ID`, `f_Artikel_ID`, `Menge`, `Ankunftsdatum`) VALUES (NULL, " + + (comboBox.getSelectedIndex()+1) + ", " + + slider.getValue() + ", '" + + ankunft + "')"); + } + } + }); + btnNachbestellen.setBounds(10, 209, 119, 33); + contentPane.add(btnNachbestellen); + + JLabel lblBenutzername = new JLabel("Benutzername:"); + lblBenutzername.setBounds(10, 65, 119, 20); + contentPane.add(lblBenutzername); + + textField = new JTextField(); + textField.setBounds(10, 90, 241, 33); + contentPane.add(textField); + textField.setColumns(10); + + JLabel lblPasswort = new JLabel("Passwort:"); + lblPasswort.setBounds(10, 133, 188, 20); + contentPane.add(lblPasswort); + + txtpw = new JTextField(); + txtpw.setBounds(10, 158, 241, 33); + contentPane.add(txtpw); + txtpw.setColumns(10); + + JButton btnAnmelden = new JButton("Anmelden"); + btnAnmelden.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + if(textField.getText() != "") + { + ArrayList> benutzer = db.queryToMap("SELECT * FROM t_benutzer WHERE Name = '" + textField.getText() + "'"); + //System.out.println(benutzer); + if (benutzer.size() == 1) { + + String hash = benutzer.get(0).get("Passwort"); + String password = txtpw.getText(); + //bcrypt prefix backport + if(hash.toCharArray()[2] == 'y') { + char[] hashArray = hash.toCharArray(); + hashArray[2] = 'a'; + hash = String.valueOf(hashArray); + } + + if(BCrypt.checkpw(password, hash)) + { + System.out.println("Eingeloggt"); + lblMenge.setVisible(true); + btnWchentlichesberprfen.setVisible(true); + btnSimulationStarten.setVisible(true); + slider.setVisible(true); + lblItemId.setVisible(true); + txtDatum.setVisible(true); + btnPlus1.setVisible(true); + btnPlus7.setVisible(true); + btnNachbestellen.setVisible(true); + comboBox.setVisible(true); + lblBenutzername.setVisible(false); + textField.setVisible(false); + lblPasswort.setVisible(false); + txtpw.setVisible(false); + btnAnmelden.setVisible(false); + + } + }else + { + System.out.println("Benutzer nicht vorhanden"); + } + } + } + }); + btnAnmelden.setBounds(61, 209, 126, 33); + contentPane.add(btnAnmelden); + } +} diff --git a/StorageSim/src/Main.java b/StorageSim/src/Main.java new file mode 100644 index 0000000..9e0f9d8 --- /dev/null +++ b/StorageSim/src/Main.java @@ -0,0 +1,52 @@ + + +import java.time.LocalDate; +import java.time.temporal.IsoFields; + +import lib.SQLConnection; +import storagesim.Simulation; + +/** + * Holds the main function + */ +public class Main { + + /** + * Invokes the window + * + * @param args program arguments + */ + public static void main(String[] args) { + /* + EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + try { + StorageWindow w = new StorageWindow(); + w.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + });*/ + //new Simulation().run(); + /* +TRUNCATE t_bestellungen; +TRUNCATE t_lager; +TRUNCATE t_mindesthaltbarkeit; +TRUNCATE t_statistik; +TRUNCATE t_verkaufszahlen; + */ + + Simulation s = new Simulation(); + s.currentTime = LocalDate.parse("2018-01-01"); + SQLConnection db = new SQLConnection(); + while (s.currentTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR) <= 48) { + System.out.println("Woche: " + s.currentTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR)); + //s.simulateSales(db); + s.run(s.currentTime); + s.currentTime = s.currentTime.plusDays(7); + } + //s.sortStatistics(db); + } +} diff --git a/StorageSim/src/lib/OpenSimplexNoise.java b/StorageSim/src/lib/OpenSimplexNoise.java new file mode 100644 index 0000000..ea48a9b --- /dev/null +++ b/StorageSim/src/lib/OpenSimplexNoise.java @@ -0,0 +1,2139 @@ +package lib; + +/* + * OpenSimplex Noise in Java. + * by Kurt Spencer + * + * v1.1 (October 5, 2014) + * - Added 2D and 4D implementations. + * - Proper gradient sets for all dimensions, from a + * dimensionally-generalizable scheme with an actual + * rhyme and reason behind it. + * - Removed default permutation array in favor of + * default seed. + * - Changed seed-based constructor to be independent + * of any particular randomization library, so results + * will be the same when ported to other languages. + */ + +public class OpenSimplexNoise { + + private static final double STRETCH_CONSTANT_2D = -0.211324865405187; //(1/Math.sqrt(2+1)-1)/2; + private static final double SQUISH_CONSTANT_2D = 0.366025403784439; //(Math.sqrt(2+1)-1)/2; + private static final double STRETCH_CONSTANT_3D = -1.0 / 6; //(1/Math.sqrt(3+1)-1)/3; + private static final double SQUISH_CONSTANT_3D = 1.0 / 3; //(Math.sqrt(3+1)-1)/3; + private static final double STRETCH_CONSTANT_4D = -0.138196601125011; //(1/Math.sqrt(4+1)-1)/4; + private static final double SQUISH_CONSTANT_4D = 0.309016994374947; //(Math.sqrt(4+1)-1)/4; + + private static final double NORM_CONSTANT_2D = 47; + private static final double NORM_CONSTANT_3D = 103; + private static final double NORM_CONSTANT_4D = 30; + + private static final long DEFAULT_SEED = 0; + + private short[] perm; + private short[] permGradIndex3D; + + public OpenSimplexNoise() { + this(DEFAULT_SEED); + } + + public OpenSimplexNoise(short[] perm) { + this.perm = perm; + permGradIndex3D = new short[256]; + + for (int i = 0; i < 256; i++) { + //Since 3D has 24 gradients, simple bitmask won't work, so precompute modulo array. + permGradIndex3D[i] = (short)((perm[i] % (gradients3D.length / 3)) * 3); + } + } + + //Initializes the class using a permutation array generated from a 64-bit seed. + //Generates a proper permutation (i.e. doesn't merely perform N successive pair swaps on a base array) + //Uses a simple 64-bit LCG. + public OpenSimplexNoise(long seed) { + perm = new short[256]; + permGradIndex3D = new short[256]; + short[] source = new short[256]; + for (short i = 0; i < 256; i++) + source[i] = i; + seed = seed * 6364136223846793005l + 1442695040888963407l; + seed = seed * 6364136223846793005l + 1442695040888963407l; + seed = seed * 6364136223846793005l + 1442695040888963407l; + for (int i = 255; i >= 0; i--) { + seed = seed * 6364136223846793005l + 1442695040888963407l; + int r = (int)((seed + 31) % (i + 1)); + if (r < 0) + r += (i + 1); + perm[i] = source[r]; + permGradIndex3D[i] = (short)((perm[i] % (gradients3D.length / 3)) * 3); + source[r] = source[i]; + } + } + + //2D OpenSimplex Noise. + public double eval(double x, double y) { + + //Place input coordinates onto grid. + double stretchOffset = (x + y) * STRETCH_CONSTANT_2D; + double xs = x + stretchOffset; + double ys = y + stretchOffset; + + //Floor to get grid coordinates of rhombus (stretched square) super-cell origin. + int xsb = fastFloor(xs); + int ysb = fastFloor(ys); + + //Skew out to get actual coordinates of rhombus origin. We'll need these later. + double squishOffset = (xsb + ysb) * SQUISH_CONSTANT_2D; + double xb = xsb + squishOffset; + double yb = ysb + squishOffset; + + //Compute grid coordinates relative to rhombus origin. + double xins = xs - xsb; + double yins = ys - ysb; + + //Sum those together to get a value that determines which region we're in. + double inSum = xins + yins; + + //Positions relative to origin point. + double dx0 = x - xb; + double dy0 = y - yb; + + //We'll be defining these inside the next block and using them afterwards. + double dx_ext, dy_ext; + int xsv_ext, ysv_ext; + + double value = 0; + + //Contribution (1,0) + double dx1 = dx0 - 1 - SQUISH_CONSTANT_2D; + double dy1 = dy0 - 0 - SQUISH_CONSTANT_2D; + double attn1 = 2 - dx1 * dx1 - dy1 * dy1; + if (attn1 > 0) { + attn1 *= attn1; + value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, dx1, dy1); + } + + //Contribution (0,1) + double dx2 = dx0 - 0 - SQUISH_CONSTANT_2D; + double dy2 = dy0 - 1 - SQUISH_CONSTANT_2D; + double attn2 = 2 - dx2 * dx2 - dy2 * dy2; + if (attn2 > 0) { + attn2 *= attn2; + value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, dx2, dy2); + } + + if (inSum <= 1) { //We're inside the triangle (2-Simplex) at (0,0) + double zins = 1 - inSum; + if (zins > xins || zins > yins) { //(0,0) is one of the closest two triangular vertices + if (xins > yins) { + xsv_ext = xsb + 1; + ysv_ext = ysb - 1; + dx_ext = dx0 - 1; + dy_ext = dy0 + 1; + } else { + xsv_ext = xsb - 1; + ysv_ext = ysb + 1; + dx_ext = dx0 + 1; + dy_ext = dy0 - 1; + } + } else { //(1,0) and (0,1) are the closest two vertices. + xsv_ext = xsb + 1; + ysv_ext = ysb + 1; + dx_ext = dx0 - 1 - 2 * SQUISH_CONSTANT_2D; + dy_ext = dy0 - 1 - 2 * SQUISH_CONSTANT_2D; + } + } else { //We're inside the triangle (2-Simplex) at (1,1) + double zins = 2 - inSum; + if (zins < xins || zins < yins) { //(0,0) is one of the closest two triangular vertices + if (xins > yins) { + xsv_ext = xsb + 2; + ysv_ext = ysb + 0; + dx_ext = dx0 - 2 - 2 * SQUISH_CONSTANT_2D; + dy_ext = dy0 + 0 - 2 * SQUISH_CONSTANT_2D; + } else { + xsv_ext = xsb + 0; + ysv_ext = ysb + 2; + dx_ext = dx0 + 0 - 2 * SQUISH_CONSTANT_2D; + dy_ext = dy0 - 2 - 2 * SQUISH_CONSTANT_2D; + } + } else { //(1,0) and (0,1) are the closest two vertices. + dx_ext = dx0; + dy_ext = dy0; + xsv_ext = xsb; + ysv_ext = ysb; + } + xsb += 1; + ysb += 1; + dx0 = dx0 - 1 - 2 * SQUISH_CONSTANT_2D; + dy0 = dy0 - 1 - 2 * SQUISH_CONSTANT_2D; + } + + //Contribution (0,0) or (1,1) + double attn0 = 2 - dx0 * dx0 - dy0 * dy0; + if (attn0 > 0) { + attn0 *= attn0; + value += attn0 * attn0 * extrapolate(xsb, ysb, dx0, dy0); + } + + //Extra Vertex + double attn_ext = 2 - dx_ext * dx_ext - dy_ext * dy_ext; + if (attn_ext > 0) { + attn_ext *= attn_ext; + value += attn_ext * attn_ext * extrapolate(xsv_ext, ysv_ext, dx_ext, dy_ext); + } + + return value / NORM_CONSTANT_2D; + } + + //3D OpenSimplex Noise. + public double eval(double x, double y, double z) { + + //Place input coordinates on simplectic honeycomb. + double stretchOffset = (x + y + z) * STRETCH_CONSTANT_3D; + double xs = x + stretchOffset; + double ys = y + stretchOffset; + double zs = z + stretchOffset; + + //Floor to get simplectic honeycomb coordinates of rhombohedron (stretched cube) super-cell origin. + int xsb = fastFloor(xs); + int ysb = fastFloor(ys); + int zsb = fastFloor(zs); + + //Skew out to get actual coordinates of rhombohedron origin. We'll need these later. + double squishOffset = (xsb + ysb + zsb) * SQUISH_CONSTANT_3D; + double xb = xsb + squishOffset; + double yb = ysb + squishOffset; + double zb = zsb + squishOffset; + + //Compute simplectic honeycomb coordinates relative to rhombohedral origin. + double xins = xs - xsb; + double yins = ys - ysb; + double zins = zs - zsb; + + //Sum those together to get a value that determines which region we're in. + double inSum = xins + yins + zins; + + //Positions relative to origin point. + double dx0 = x - xb; + double dy0 = y - yb; + double dz0 = z - zb; + + //We'll be defining these inside the next block and using them afterwards. + double dx_ext0, dy_ext0, dz_ext0; + double dx_ext1, dy_ext1, dz_ext1; + int xsv_ext0, ysv_ext0, zsv_ext0; + int xsv_ext1, ysv_ext1, zsv_ext1; + + double value = 0; + if (inSum <= 1) { //We're inside the tetrahedron (3-Simplex) at (0,0,0) + + //Determine which two of (0,0,1), (0,1,0), (1,0,0) are closest. + byte aPoint = 0x01; + double aScore = xins; + byte bPoint = 0x02; + double bScore = yins; + if (aScore >= bScore && zins > bScore) { + bScore = zins; + bPoint = 0x04; + } else if (aScore < bScore && zins > aScore) { + aScore = zins; + aPoint = 0x04; + } + + //Now we determine the two lattice points not part of the tetrahedron that may contribute. + //This depends on the closest two tetrahedral vertices, including (0,0,0) + double wins = 1 - inSum; + if (wins > aScore || wins > bScore) { //(0,0,0) is one of the closest two tetrahedral vertices. + byte c = (bScore > aScore ? bPoint : aPoint); //Our other closest vertex is the closest out of a and b. + + if ((c & 0x01) == 0) { + xsv_ext0 = xsb - 1; + xsv_ext1 = xsb; + dx_ext0 = dx0 + 1; + dx_ext1 = dx0; + } else { + xsv_ext0 = xsv_ext1 = xsb + 1; + dx_ext0 = dx_ext1 = dx0 - 1; + } + + if ((c & 0x02) == 0) { + ysv_ext0 = ysv_ext1 = ysb; + dy_ext0 = dy_ext1 = dy0; + if ((c & 0x01) == 0) { + ysv_ext1 -= 1; + dy_ext1 += 1; + } else { + ysv_ext0 -= 1; + dy_ext0 += 1; + } + } else { + ysv_ext0 = ysv_ext1 = ysb + 1; + dy_ext0 = dy_ext1 = dy0 - 1; + } + + if ((c & 0x04) == 0) { + zsv_ext0 = zsb; + zsv_ext1 = zsb - 1; + dz_ext0 = dz0; + dz_ext1 = dz0 + 1; + } else { + zsv_ext0 = zsv_ext1 = zsb + 1; + dz_ext0 = dz_ext1 = dz0 - 1; + } + } else { //(0,0,0) is not one of the closest two tetrahedral vertices. + byte c = (byte)(aPoint | bPoint); //Our two extra vertices are determined by the closest two. + + if ((c & 0x01) == 0) { + xsv_ext0 = xsb; + xsv_ext1 = xsb - 1; + dx_ext0 = dx0 - 2 * SQUISH_CONSTANT_3D; + dx_ext1 = dx0 + 1 - SQUISH_CONSTANT_3D; + } else { + xsv_ext0 = xsv_ext1 = xsb + 1; + dx_ext0 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D; + dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D; + } + + if ((c & 0x02) == 0) { + ysv_ext0 = ysb; + ysv_ext1 = ysb - 1; + dy_ext0 = dy0 - 2 * SQUISH_CONSTANT_3D; + dy_ext1 = dy0 + 1 - SQUISH_CONSTANT_3D; + } else { + ysv_ext0 = ysv_ext1 = ysb + 1; + dy_ext0 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D; + dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D; + } + + if ((c & 0x04) == 0) { + zsv_ext0 = zsb; + zsv_ext1 = zsb - 1; + dz_ext0 = dz0 - 2 * SQUISH_CONSTANT_3D; + dz_ext1 = dz0 + 1 - SQUISH_CONSTANT_3D; + } else { + zsv_ext0 = zsv_ext1 = zsb + 1; + dz_ext0 = dz0 - 1 - 2 * SQUISH_CONSTANT_3D; + dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D; + } + } + + //Contribution (0,0,0) + double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0; + if (attn0 > 0) { + attn0 *= attn0; + value += attn0 * attn0 * extrapolate(xsb + 0, ysb + 0, zsb + 0, dx0, dy0, dz0); + } + + //Contribution (1,0,0) + double dx1 = dx0 - 1 - SQUISH_CONSTANT_3D; + double dy1 = dy0 - 0 - SQUISH_CONSTANT_3D; + double dz1 = dz0 - 0 - SQUISH_CONSTANT_3D; + double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1; + if (attn1 > 0) { + attn1 *= attn1; + value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, dx1, dy1, dz1); + } + + //Contribution (0,1,0) + double dx2 = dx0 - 0 - SQUISH_CONSTANT_3D; + double dy2 = dy0 - 1 - SQUISH_CONSTANT_3D; + double dz2 = dz1; + double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2; + if (attn2 > 0) { + attn2 *= attn2; + value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, dx2, dy2, dz2); + } + + //Contribution (0,0,1) + double dx3 = dx2; + double dy3 = dy1; + double dz3 = dz0 - 1 - SQUISH_CONSTANT_3D; + double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3; + if (attn3 > 0) { + attn3 *= attn3; + value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, dx3, dy3, dz3); + } + } else if (inSum >= 2) { //We're inside the tetrahedron (3-Simplex) at (1,1,1) + + //Determine which two tetrahedral vertices are the closest, out of (1,1,0), (1,0,1), (0,1,1) but not (1,1,1). + byte aPoint = 0x06; + double aScore = xins; + byte bPoint = 0x05; + double bScore = yins; + if (aScore <= bScore && zins < bScore) { + bScore = zins; + bPoint = 0x03; + } else if (aScore > bScore && zins < aScore) { + aScore = zins; + aPoint = 0x03; + } + + //Now we determine the two lattice points not part of the tetrahedron that may contribute. + //This depends on the closest two tetrahedral vertices, including (1,1,1) + double wins = 3 - inSum; + if (wins < aScore || wins < bScore) { //(1,1,1) is one of the closest two tetrahedral vertices. + byte c = (bScore < aScore ? bPoint : aPoint); //Our other closest vertex is the closest out of a and b. + + if ((c & 0x01) != 0) { + xsv_ext0 = xsb + 2; + xsv_ext1 = xsb + 1; + dx_ext0 = dx0 - 2 - 3 * SQUISH_CONSTANT_3D; + dx_ext1 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D; + } else { + xsv_ext0 = xsv_ext1 = xsb; + dx_ext0 = dx_ext1 = dx0 - 3 * SQUISH_CONSTANT_3D; + } + + if ((c & 0x02) != 0) { + ysv_ext0 = ysv_ext1 = ysb + 1; + dy_ext0 = dy_ext1 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D; + if ((c & 0x01) != 0) { + ysv_ext1 += 1; + dy_ext1 -= 1; + } else { + ysv_ext0 += 1; + dy_ext0 -= 1; + } + } else { + ysv_ext0 = ysv_ext1 = ysb; + dy_ext0 = dy_ext1 = dy0 - 3 * SQUISH_CONSTANT_3D; + } + + if ((c & 0x04) != 0) { + zsv_ext0 = zsb + 1; + zsv_ext1 = zsb + 2; + dz_ext0 = dz0 - 1 - 3 * SQUISH_CONSTANT_3D; + dz_ext1 = dz0 - 2 - 3 * SQUISH_CONSTANT_3D; + } else { + zsv_ext0 = zsv_ext1 = zsb; + dz_ext0 = dz_ext1 = dz0 - 3 * SQUISH_CONSTANT_3D; + } + } else { //(1,1,1) is not one of the closest two tetrahedral vertices. + byte c = (byte)(aPoint & bPoint); //Our two extra vertices are determined by the closest two. + + if ((c & 0x01) != 0) { + xsv_ext0 = xsb + 1; + xsv_ext1 = xsb + 2; + dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D; + dx_ext1 = dx0 - 2 - 2 * SQUISH_CONSTANT_3D; + } else { + xsv_ext0 = xsv_ext1 = xsb; + dx_ext0 = dx0 - SQUISH_CONSTANT_3D; + dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; + } + + if ((c & 0x02) != 0) { + ysv_ext0 = ysb + 1; + ysv_ext1 = ysb + 2; + dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D; + dy_ext1 = dy0 - 2 - 2 * SQUISH_CONSTANT_3D; + } else { + ysv_ext0 = ysv_ext1 = ysb; + dy_ext0 = dy0 - SQUISH_CONSTANT_3D; + dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; + } + + if ((c & 0x04) != 0) { + zsv_ext0 = zsb + 1; + zsv_ext1 = zsb + 2; + dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D; + dz_ext1 = dz0 - 2 - 2 * SQUISH_CONSTANT_3D; + } else { + zsv_ext0 = zsv_ext1 = zsb; + dz_ext0 = dz0 - SQUISH_CONSTANT_3D; + dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D; + } + } + + //Contribution (1,1,0) + double dx3 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D; + double dy3 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D; + double dz3 = dz0 - 0 - 2 * SQUISH_CONSTANT_3D; + double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3; + if (attn3 > 0) { + attn3 *= attn3; + value += attn3 * attn3 * extrapolate(xsb + 1, ysb + 1, zsb + 0, dx3, dy3, dz3); + } + + //Contribution (1,0,1) + double dx2 = dx3; + double dy2 = dy0 - 0 - 2 * SQUISH_CONSTANT_3D; + double dz2 = dz0 - 1 - 2 * SQUISH_CONSTANT_3D; + double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2; + if (attn2 > 0) { + attn2 *= attn2; + value += attn2 * attn2 * extrapolate(xsb + 1, ysb + 0, zsb + 1, dx2, dy2, dz2); + } + + //Contribution (0,1,1) + double dx1 = dx0 - 0 - 2 * SQUISH_CONSTANT_3D; + double dy1 = dy3; + double dz1 = dz2; + double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1; + if (attn1 > 0) { + attn1 *= attn1; + value += attn1 * attn1 * extrapolate(xsb + 0, ysb + 1, zsb + 1, dx1, dy1, dz1); + } + + //Contribution (1,1,1) + dx0 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D; + dy0 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D; + dz0 = dz0 - 1 - 3 * SQUISH_CONSTANT_3D; + double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0; + if (attn0 > 0) { + attn0 *= attn0; + value += attn0 * attn0 * extrapolate(xsb + 1, ysb + 1, zsb + 1, dx0, dy0, dz0); + } + } else { //We're inside the octahedron (Rectified 3-Simplex) in between. + double aScore; + byte aPoint; + boolean aIsFurtherSide; + double bScore; + byte bPoint; + boolean bIsFurtherSide; + + //Decide between point (0,0,1) and (1,1,0) as closest + double p1 = xins + yins; + if (p1 > 1) { + aScore = p1 - 1; + aPoint = 0x03; + aIsFurtherSide = true; + } else { + aScore = 1 - p1; + aPoint = 0x04; + aIsFurtherSide = false; + } + + //Decide between point (0,1,0) and (1,0,1) as closest + double p2 = xins + zins; + if (p2 > 1) { + bScore = p2 - 1; + bPoint = 0x05; + bIsFurtherSide = true; + } else { + bScore = 1 - p2; + bPoint = 0x02; + bIsFurtherSide = false; + } + + //The closest out of the two (1,0,0) and (0,1,1) will replace the furthest out of the two decided above, if closer. + double p3 = yins + zins; + if (p3 > 1) { + double score = p3 - 1; + if (aScore <= bScore && aScore < score) { + aScore = score; + aPoint = 0x06; + aIsFurtherSide = true; + } else if (aScore > bScore && bScore < score) { + bScore = score; + bPoint = 0x06; + bIsFurtherSide = true; + } + } else { + double score = 1 - p3; + if (aScore <= bScore && aScore < score) { + aScore = score; + aPoint = 0x01; + aIsFurtherSide = false; + } else if (aScore > bScore && bScore < score) { + bScore = score; + bPoint = 0x01; + bIsFurtherSide = false; + } + } + + //Where each of the two closest points are determines how the extra two vertices are calculated. + if (aIsFurtherSide == bIsFurtherSide) { + if (aIsFurtherSide) { //Both closest points on (1,1,1) side + + //One of the two extra points is (1,1,1) + dx_ext0 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D; + dy_ext0 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D; + dz_ext0 = dz0 - 1 - 3 * SQUISH_CONSTANT_3D; + xsv_ext0 = xsb + 1; + ysv_ext0 = ysb + 1; + zsv_ext0 = zsb + 1; + + //Other extra point is based on the shared axis. + byte c = (byte)(aPoint & bPoint); + if ((c & 0x01) != 0) { + dx_ext1 = dx0 - 2 - 2 * SQUISH_CONSTANT_3D; + dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; + dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D; + xsv_ext1 = xsb + 2; + ysv_ext1 = ysb; + zsv_ext1 = zsb; + } else if ((c & 0x02) != 0) { + dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; + dy_ext1 = dy0 - 2 - 2 * SQUISH_CONSTANT_3D; + dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D; + xsv_ext1 = xsb; + ysv_ext1 = ysb + 2; + zsv_ext1 = zsb; + } else { + dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; + dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; + dz_ext1 = dz0 - 2 - 2 * SQUISH_CONSTANT_3D; + xsv_ext1 = xsb; + ysv_ext1 = ysb; + zsv_ext1 = zsb + 2; + } + } else {//Both closest points on (0,0,0) side + + //One of the two extra points is (0,0,0) + dx_ext0 = dx0; + dy_ext0 = dy0; + dz_ext0 = dz0; + xsv_ext0 = xsb; + ysv_ext0 = ysb; + zsv_ext0 = zsb; + + //Other extra point is based on the omitted axis. + byte c = (byte)(aPoint | bPoint); + if ((c & 0x01) == 0) { + dx_ext1 = dx0 + 1 - SQUISH_CONSTANT_3D; + dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D; + dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D; + xsv_ext1 = xsb - 1; + ysv_ext1 = ysb + 1; + zsv_ext1 = zsb + 1; + } else if ((c & 0x02) == 0) { + dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D; + dy_ext1 = dy0 + 1 - SQUISH_CONSTANT_3D; + dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D; + xsv_ext1 = xsb + 1; + ysv_ext1 = ysb - 1; + zsv_ext1 = zsb + 1; + } else { + dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D; + dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D; + dz_ext1 = dz0 + 1 - SQUISH_CONSTANT_3D; + xsv_ext1 = xsb + 1; + ysv_ext1 = ysb + 1; + zsv_ext1 = zsb - 1; + } + } + } else { //One point on (0,0,0) side, one point on (1,1,1) side + byte c1, c2; + if (aIsFurtherSide) { + c1 = aPoint; + c2 = bPoint; + } else { + c1 = bPoint; + c2 = aPoint; + } + + //One contribution is a permutation of (1,1,-1) + if ((c1 & 0x01) == 0) { + dx_ext0 = dx0 + 1 - SQUISH_CONSTANT_3D; + dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D; + dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D; + xsv_ext0 = xsb - 1; + ysv_ext0 = ysb + 1; + zsv_ext0 = zsb + 1; + } else if ((c1 & 0x02) == 0) { + dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D; + dy_ext0 = dy0 + 1 - SQUISH_CONSTANT_3D; + dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D; + xsv_ext0 = xsb + 1; + ysv_ext0 = ysb - 1; + zsv_ext0 = zsb + 1; + } else { + dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D; + dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D; + dz_ext0 = dz0 + 1 - SQUISH_CONSTANT_3D; + xsv_ext0 = xsb + 1; + ysv_ext0 = ysb + 1; + zsv_ext0 = zsb - 1; + } + + //One contribution is a permutation of (0,0,2) + dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; + dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; + dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D; + xsv_ext1 = xsb; + ysv_ext1 = ysb; + zsv_ext1 = zsb; + if ((c2 & 0x01) != 0) { + dx_ext1 -= 2; + xsv_ext1 += 2; + } else if ((c2 & 0x02) != 0) { + dy_ext1 -= 2; + ysv_ext1 += 2; + } else { + dz_ext1 -= 2; + zsv_ext1 += 2; + } + } + + //Contribution (1,0,0) + double dx1 = dx0 - 1 - SQUISH_CONSTANT_3D; + double dy1 = dy0 - 0 - SQUISH_CONSTANT_3D; + double dz1 = dz0 - 0 - SQUISH_CONSTANT_3D; + double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1; + if (attn1 > 0) { + attn1 *= attn1; + value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, dx1, dy1, dz1); + } + + //Contribution (0,1,0) + double dx2 = dx0 - 0 - SQUISH_CONSTANT_3D; + double dy2 = dy0 - 1 - SQUISH_CONSTANT_3D; + double dz2 = dz1; + double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2; + if (attn2 > 0) { + attn2 *= attn2; + value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, dx2, dy2, dz2); + } + + //Contribution (0,0,1) + double dx3 = dx2; + double dy3 = dy1; + double dz3 = dz0 - 1 - SQUISH_CONSTANT_3D; + double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3; + if (attn3 > 0) { + attn3 *= attn3; + value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, dx3, dy3, dz3); + } + + //Contribution (1,1,0) + double dx4 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D; + double dy4 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D; + double dz4 = dz0 - 0 - 2 * SQUISH_CONSTANT_3D; + double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4; + if (attn4 > 0) { + attn4 *= attn4; + value += attn4 * attn4 * extrapolate(xsb + 1, ysb + 1, zsb + 0, dx4, dy4, dz4); + } + + //Contribution (1,0,1) + double dx5 = dx4; + double dy5 = dy0 - 0 - 2 * SQUISH_CONSTANT_3D; + double dz5 = dz0 - 1 - 2 * SQUISH_CONSTANT_3D; + double attn5 = 2 - dx5 * dx5 - dy5 * dy5 - dz5 * dz5; + if (attn5 > 0) { + attn5 *= attn5; + value += attn5 * attn5 * extrapolate(xsb + 1, ysb + 0, zsb + 1, dx5, dy5, dz5); + } + + //Contribution (0,1,1) + double dx6 = dx0 - 0 - 2 * SQUISH_CONSTANT_3D; + double dy6 = dy4; + double dz6 = dz5; + double attn6 = 2 - dx6 * dx6 - dy6 * dy6 - dz6 * dz6; + if (attn6 > 0) { + attn6 *= attn6; + value += attn6 * attn6 * extrapolate(xsb + 0, ysb + 1, zsb + 1, dx6, dy6, dz6); + } + } + + //First extra vertex + double attn_ext0 = 2 - dx_ext0 * dx_ext0 - dy_ext0 * dy_ext0 - dz_ext0 * dz_ext0; + if (attn_ext0 > 0) + { + attn_ext0 *= attn_ext0; + value += attn_ext0 * attn_ext0 * extrapolate(xsv_ext0, ysv_ext0, zsv_ext0, dx_ext0, dy_ext0, dz_ext0); + } + + //Second extra vertex + double attn_ext1 = 2 - dx_ext1 * dx_ext1 - dy_ext1 * dy_ext1 - dz_ext1 * dz_ext1; + if (attn_ext1 > 0) + { + attn_ext1 *= attn_ext1; + value += attn_ext1 * attn_ext1 * extrapolate(xsv_ext1, ysv_ext1, zsv_ext1, dx_ext1, dy_ext1, dz_ext1); + } + + return value / NORM_CONSTANT_3D; + } + + //4D OpenSimplex Noise. + public double eval(double x, double y, double z, double w) { + + //Place input coordinates on simplectic honeycomb. + double stretchOffset = (x + y + z + w) * STRETCH_CONSTANT_4D; + double xs = x + stretchOffset; + double ys = y + stretchOffset; + double zs = z + stretchOffset; + double ws = w + stretchOffset; + + //Floor to get simplectic honeycomb coordinates of rhombo-hypercube super-cell origin. + int xsb = fastFloor(xs); + int ysb = fastFloor(ys); + int zsb = fastFloor(zs); + int wsb = fastFloor(ws); + + //Skew out to get actual coordinates of stretched rhombo-hypercube origin. We'll need these later. + double squishOffset = (xsb + ysb + zsb + wsb) * SQUISH_CONSTANT_4D; + double xb = xsb + squishOffset; + double yb = ysb + squishOffset; + double zb = zsb + squishOffset; + double wb = wsb + squishOffset; + + //Compute simplectic honeycomb coordinates relative to rhombo-hypercube origin. + double xins = xs - xsb; + double yins = ys - ysb; + double zins = zs - zsb; + double wins = ws - wsb; + + //Sum those together to get a value that determines which region we're in. + double inSum = xins + yins + zins + wins; + + //Positions relative to origin point. + double dx0 = x - xb; + double dy0 = y - yb; + double dz0 = z - zb; + double dw0 = w - wb; + + //We'll be defining these inside the next block and using them afterwards. + double dx_ext0, dy_ext0, dz_ext0, dw_ext0; + double dx_ext1, dy_ext1, dz_ext1, dw_ext1; + double dx_ext2, dy_ext2, dz_ext2, dw_ext2; + int xsv_ext0, ysv_ext0, zsv_ext0, wsv_ext0; + int xsv_ext1, ysv_ext1, zsv_ext1, wsv_ext1; + int xsv_ext2, ysv_ext2, zsv_ext2, wsv_ext2; + + double value = 0; + if (inSum <= 1) { //We're inside the pentachoron (4-Simplex) at (0,0,0,0) + + //Determine which two of (0,0,0,1), (0,0,1,0), (0,1,0,0), (1,0,0,0) are closest. + byte aPoint = 0x01; + double aScore = xins; + byte bPoint = 0x02; + double bScore = yins; + if (aScore >= bScore && zins > bScore) { + bScore = zins; + bPoint = 0x04; + } else if (aScore < bScore && zins > aScore) { + aScore = zins; + aPoint = 0x04; + } + if (aScore >= bScore && wins > bScore) { + bScore = wins; + bPoint = 0x08; + } else if (aScore < bScore && wins > aScore) { + aScore = wins; + aPoint = 0x08; + } + + //Now we determine the three lattice points not part of the pentachoron that may contribute. + //This depends on the closest two pentachoron vertices, including (0,0,0,0) + double uins = 1 - inSum; + if (uins > aScore || uins > bScore) { //(0,0,0,0) is one of the closest two pentachoron vertices. + byte c = (bScore > aScore ? bPoint : aPoint); //Our other closest vertex is the closest out of a and b. + if ((c & 0x01) == 0) { + xsv_ext0 = xsb - 1; + xsv_ext1 = xsv_ext2 = xsb; + dx_ext0 = dx0 + 1; + dx_ext1 = dx_ext2 = dx0; + } else { + xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb + 1; + dx_ext0 = dx_ext1 = dx_ext2 = dx0 - 1; + } + + if ((c & 0x02) == 0) { + ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; + dy_ext0 = dy_ext1 = dy_ext2 = dy0; + if ((c & 0x01) == 0x01) { + ysv_ext0 -= 1; + dy_ext0 += 1; + } else { + ysv_ext1 -= 1; + dy_ext1 += 1; + } + } else { + ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; + dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 1; + } + + if ((c & 0x04) == 0) { + zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; + dz_ext0 = dz_ext1 = dz_ext2 = dz0; + if ((c & 0x03) != 0) { + if ((c & 0x03) == 0x03) { + zsv_ext0 -= 1; + dz_ext0 += 1; + } else { + zsv_ext1 -= 1; + dz_ext1 += 1; + } + } else { + zsv_ext2 -= 1; + dz_ext2 += 1; + } + } else { + zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; + dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 1; + } + + if ((c & 0x08) == 0) { + wsv_ext0 = wsv_ext1 = wsb; + wsv_ext2 = wsb - 1; + dw_ext0 = dw_ext1 = dw0; + dw_ext2 = dw0 + 1; + } else { + wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb + 1; + dw_ext0 = dw_ext1 = dw_ext2 = dw0 - 1; + } + } else { //(0,0,0,0) is not one of the closest two pentachoron vertices. + byte c = (byte)(aPoint | bPoint); //Our three extra vertices are determined by the closest two. + + if ((c & 0x01) == 0) { + xsv_ext0 = xsv_ext2 = xsb; + xsv_ext1 = xsb - 1; + dx_ext0 = dx0 - 2 * SQUISH_CONSTANT_4D; + dx_ext1 = dx0 + 1 - SQUISH_CONSTANT_4D; + dx_ext2 = dx0 - SQUISH_CONSTANT_4D; + } else { + xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb + 1; + dx_ext0 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + dx_ext1 = dx_ext2 = dx0 - 1 - SQUISH_CONSTANT_4D; + } + + if ((c & 0x02) == 0) { + ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; + dy_ext0 = dy0 - 2 * SQUISH_CONSTANT_4D; + dy_ext1 = dy_ext2 = dy0 - SQUISH_CONSTANT_4D; + if ((c & 0x01) == 0x01) { + ysv_ext1 -= 1; + dy_ext1 += 1; + } else { + ysv_ext2 -= 1; + dy_ext2 += 1; + } + } else { + ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; + dy_ext0 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + dy_ext1 = dy_ext2 = dy0 - 1 - SQUISH_CONSTANT_4D; + } + + if ((c & 0x04) == 0) { + zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; + dz_ext0 = dz0 - 2 * SQUISH_CONSTANT_4D; + dz_ext1 = dz_ext2 = dz0 - SQUISH_CONSTANT_4D; + if ((c & 0x03) == 0x03) { + zsv_ext1 -= 1; + dz_ext1 += 1; + } else { + zsv_ext2 -= 1; + dz_ext2 += 1; + } + } else { + zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; + dz_ext0 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + dz_ext1 = dz_ext2 = dz0 - 1 - SQUISH_CONSTANT_4D; + } + + if ((c & 0x08) == 0) { + wsv_ext0 = wsv_ext1 = wsb; + wsv_ext2 = wsb - 1; + dw_ext0 = dw0 - 2 * SQUISH_CONSTANT_4D; + dw_ext1 = dw0 - SQUISH_CONSTANT_4D; + dw_ext2 = dw0 + 1 - SQUISH_CONSTANT_4D; + } else { + wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb + 1; + dw_ext0 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + dw_ext1 = dw_ext2 = dw0 - 1 - SQUISH_CONSTANT_4D; + } + } + + //Contribution (0,0,0,0) + double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0 - dw0 * dw0; + if (attn0 > 0) { + attn0 *= attn0; + value += attn0 * attn0 * extrapolate(xsb + 0, ysb + 0, zsb + 0, wsb + 0, dx0, dy0, dz0, dw0); + } + + //Contribution (1,0,0,0) + double dx1 = dx0 - 1 - SQUISH_CONSTANT_4D; + double dy1 = dy0 - 0 - SQUISH_CONSTANT_4D; + double dz1 = dz0 - 0 - SQUISH_CONSTANT_4D; + double dw1 = dw0 - 0 - SQUISH_CONSTANT_4D; + double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1; + if (attn1 > 0) { + attn1 *= attn1; + value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 0, dx1, dy1, dz1, dw1); + } + + //Contribution (0,1,0,0) + double dx2 = dx0 - 0 - SQUISH_CONSTANT_4D; + double dy2 = dy0 - 1 - SQUISH_CONSTANT_4D; + double dz2 = dz1; + double dw2 = dw1; + double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2; + if (attn2 > 0) { + attn2 *= attn2; + value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 0, dx2, dy2, dz2, dw2); + } + + //Contribution (0,0,1,0) + double dx3 = dx2; + double dy3 = dy1; + double dz3 = dz0 - 1 - SQUISH_CONSTANT_4D; + double dw3 = dw1; + double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3; + if (attn3 > 0) { + attn3 *= attn3; + value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 0, dx3, dy3, dz3, dw3); + } + + //Contribution (0,0,0,1) + double dx4 = dx2; + double dy4 = dy1; + double dz4 = dz1; + double dw4 = dw0 - 1 - SQUISH_CONSTANT_4D; + double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4; + if (attn4 > 0) { + attn4 *= attn4; + value += attn4 * attn4 * extrapolate(xsb + 0, ysb + 0, zsb + 0, wsb + 1, dx4, dy4, dz4, dw4); + } + } else if (inSum >= 3) { //We're inside the pentachoron (4-Simplex) at (1,1,1,1) + //Determine which two of (1,1,1,0), (1,1,0,1), (1,0,1,1), (0,1,1,1) are closest. + byte aPoint = 0x0E; + double aScore = xins; + byte bPoint = 0x0D; + double bScore = yins; + if (aScore <= bScore && zins < bScore) { + bScore = zins; + bPoint = 0x0B; + } else if (aScore > bScore && zins < aScore) { + aScore = zins; + aPoint = 0x0B; + } + if (aScore <= bScore && wins < bScore) { + bScore = wins; + bPoint = 0x07; + } else if (aScore > bScore && wins < aScore) { + aScore = wins; + aPoint = 0x07; + } + + //Now we determine the three lattice points not part of the pentachoron that may contribute. + //This depends on the closest two pentachoron vertices, including (0,0,0,0) + double uins = 4 - inSum; + if (uins < aScore || uins < bScore) { //(1,1,1,1) is one of the closest two pentachoron vertices. + byte c = (bScore < aScore ? bPoint : aPoint); //Our other closest vertex is the closest out of a and b. + + if ((c & 0x01) != 0) { + xsv_ext0 = xsb + 2; + xsv_ext1 = xsv_ext2 = xsb + 1; + dx_ext0 = dx0 - 2 - 4 * SQUISH_CONSTANT_4D; + dx_ext1 = dx_ext2 = dx0 - 1 - 4 * SQUISH_CONSTANT_4D; + } else { + xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb; + dx_ext0 = dx_ext1 = dx_ext2 = dx0 - 4 * SQUISH_CONSTANT_4D; + } + + if ((c & 0x02) != 0) { + ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; + dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 1 - 4 * SQUISH_CONSTANT_4D; + if ((c & 0x01) != 0) { + ysv_ext1 += 1; + dy_ext1 -= 1; + } else { + ysv_ext0 += 1; + dy_ext0 -= 1; + } + } else { + ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; + dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 4 * SQUISH_CONSTANT_4D; + } + + if ((c & 0x04) != 0) { + zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; + dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 1 - 4 * SQUISH_CONSTANT_4D; + if ((c & 0x03) != 0x03) { + if ((c & 0x03) == 0) { + zsv_ext0 += 1; + dz_ext0 -= 1; + } else { + zsv_ext1 += 1; + dz_ext1 -= 1; + } + } else { + zsv_ext2 += 1; + dz_ext2 -= 1; + } + } else { + zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; + dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 4 * SQUISH_CONSTANT_4D; + } + + if ((c & 0x08) != 0) { + wsv_ext0 = wsv_ext1 = wsb + 1; + wsv_ext2 = wsb + 2; + dw_ext0 = dw_ext1 = dw0 - 1 - 4 * SQUISH_CONSTANT_4D; + dw_ext2 = dw0 - 2 - 4 * SQUISH_CONSTANT_4D; + } else { + wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb; + dw_ext0 = dw_ext1 = dw_ext2 = dw0 - 4 * SQUISH_CONSTANT_4D; + } + } else { //(1,1,1,1) is not one of the closest two pentachoron vertices. + byte c = (byte)(aPoint & bPoint); //Our three extra vertices are determined by the closest two. + + if ((c & 0x01) != 0) { + xsv_ext0 = xsv_ext2 = xsb + 1; + xsv_ext1 = xsb + 2; + dx_ext0 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + dx_ext1 = dx0 - 2 - 3 * SQUISH_CONSTANT_4D; + dx_ext2 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; + } else { + xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb; + dx_ext0 = dx0 - 2 * SQUISH_CONSTANT_4D; + dx_ext1 = dx_ext2 = dx0 - 3 * SQUISH_CONSTANT_4D; + } + + if ((c & 0x02) != 0) { + ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; + dy_ext0 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + dy_ext1 = dy_ext2 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; + if ((c & 0x01) != 0) { + ysv_ext2 += 1; + dy_ext2 -= 1; + } else { + ysv_ext1 += 1; + dy_ext1 -= 1; + } + } else { + ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; + dy_ext0 = dy0 - 2 * SQUISH_CONSTANT_4D; + dy_ext1 = dy_ext2 = dy0 - 3 * SQUISH_CONSTANT_4D; + } + + if ((c & 0x04) != 0) { + zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; + dz_ext0 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + dz_ext1 = dz_ext2 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D; + if ((c & 0x03) != 0) { + zsv_ext2 += 1; + dz_ext2 -= 1; + } else { + zsv_ext1 += 1; + dz_ext1 -= 1; + } + } else { + zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; + dz_ext0 = dz0 - 2 * SQUISH_CONSTANT_4D; + dz_ext1 = dz_ext2 = dz0 - 3 * SQUISH_CONSTANT_4D; + } + + if ((c & 0x08) != 0) { + wsv_ext0 = wsv_ext1 = wsb + 1; + wsv_ext2 = wsb + 2; + dw_ext0 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + dw_ext1 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D; + dw_ext2 = dw0 - 2 - 3 * SQUISH_CONSTANT_4D; + } else { + wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb; + dw_ext0 = dw0 - 2 * SQUISH_CONSTANT_4D; + dw_ext1 = dw_ext2 = dw0 - 3 * SQUISH_CONSTANT_4D; + } + } + + //Contribution (1,1,1,0) + double dx4 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; + double dy4 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; + double dz4 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D; + double dw4 = dw0 - 3 * SQUISH_CONSTANT_4D; + double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4; + if (attn4 > 0) { + attn4 *= attn4; + value += attn4 * attn4 * extrapolate(xsb + 1, ysb + 1, zsb + 1, wsb + 0, dx4, dy4, dz4, dw4); + } + + //Contribution (1,1,0,1) + double dx3 = dx4; + double dy3 = dy4; + double dz3 = dz0 - 3 * SQUISH_CONSTANT_4D; + double dw3 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D; + double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3; + if (attn3 > 0) { + attn3 *= attn3; + value += attn3 * attn3 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 1, dx3, dy3, dz3, dw3); + } + + //Contribution (1,0,1,1) + double dx2 = dx4; + double dy2 = dy0 - 3 * SQUISH_CONSTANT_4D; + double dz2 = dz4; + double dw2 = dw3; + double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2; + if (attn2 > 0) { + attn2 *= attn2; + value += attn2 * attn2 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 1, dx2, dy2, dz2, dw2); + } + + //Contribution (0,1,1,1) + double dx1 = dx0 - 3 * SQUISH_CONSTANT_4D; + double dz1 = dz4; + double dy1 = dy4; + double dw1 = dw3; + double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1; + if (attn1 > 0) { + attn1 *= attn1; + value += attn1 * attn1 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 1, dx1, dy1, dz1, dw1); + } + + //Contribution (1,1,1,1) + dx0 = dx0 - 1 - 4 * SQUISH_CONSTANT_4D; + dy0 = dy0 - 1 - 4 * SQUISH_CONSTANT_4D; + dz0 = dz0 - 1 - 4 * SQUISH_CONSTANT_4D; + dw0 = dw0 - 1 - 4 * SQUISH_CONSTANT_4D; + double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0 - dw0 * dw0; + if (attn0 > 0) { + attn0 *= attn0; + value += attn0 * attn0 * extrapolate(xsb + 1, ysb + 1, zsb + 1, wsb + 1, dx0, dy0, dz0, dw0); + } + } else if (inSum <= 2) { //We're inside the first dispentachoron (Rectified 4-Simplex) + double aScore; + byte aPoint; + boolean aIsBiggerSide = true; + double bScore; + byte bPoint; + boolean bIsBiggerSide = true; + + //Decide between (1,1,0,0) and (0,0,1,1) + if (xins + yins > zins + wins) { + aScore = xins + yins; + aPoint = 0x03; + } else { + aScore = zins + wins; + aPoint = 0x0C; + } + + //Decide between (1,0,1,0) and (0,1,0,1) + if (xins + zins > yins + wins) { + bScore = xins + zins; + bPoint = 0x05; + } else { + bScore = yins + wins; + bPoint = 0x0A; + } + + //Closer between (1,0,0,1) and (0,1,1,0) will replace the further of a and b, if closer. + if (xins + wins > yins + zins) { + double score = xins + wins; + if (aScore >= bScore && score > bScore) { + bScore = score; + bPoint = 0x09; + } else if (aScore < bScore && score > aScore) { + aScore = score; + aPoint = 0x09; + } + } else { + double score = yins + zins; + if (aScore >= bScore && score > bScore) { + bScore = score; + bPoint = 0x06; + } else if (aScore < bScore && score > aScore) { + aScore = score; + aPoint = 0x06; + } + } + + //Decide if (1,0,0,0) is closer. + double p1 = 2 - inSum + xins; + if (aScore >= bScore && p1 > bScore) { + bScore = p1; + bPoint = 0x01; + bIsBiggerSide = false; + } else if (aScore < bScore && p1 > aScore) { + aScore = p1; + aPoint = 0x01; + aIsBiggerSide = false; + } + + //Decide if (0,1,0,0) is closer. + double p2 = 2 - inSum + yins; + if (aScore >= bScore && p2 > bScore) { + bScore = p2; + bPoint = 0x02; + bIsBiggerSide = false; + } else if (aScore < bScore && p2 > aScore) { + aScore = p2; + aPoint = 0x02; + aIsBiggerSide = false; + } + + //Decide if (0,0,1,0) is closer. + double p3 = 2 - inSum + zins; + if (aScore >= bScore && p3 > bScore) { + bScore = p3; + bPoint = 0x04; + bIsBiggerSide = false; + } else if (aScore < bScore && p3 > aScore) { + aScore = p3; + aPoint = 0x04; + aIsBiggerSide = false; + } + + //Decide if (0,0,0,1) is closer. + double p4 = 2 - inSum + wins; + if (aScore >= bScore && p4 > bScore) { + bScore = p4; + bPoint = 0x08; + bIsBiggerSide = false; + } else if (aScore < bScore && p4 > aScore) { + aScore = p4; + aPoint = 0x08; + aIsBiggerSide = false; + } + + //Where each of the two closest points are determines how the extra three vertices are calculated. + if (aIsBiggerSide == bIsBiggerSide) { + if (aIsBiggerSide) { //Both closest points on the bigger side + byte c1 = (byte)(aPoint | bPoint); + byte c2 = (byte)(aPoint & bPoint); + if ((c1 & 0x01) == 0) { + xsv_ext0 = xsb; + xsv_ext1 = xsb - 1; + dx_ext0 = dx0 - 3 * SQUISH_CONSTANT_4D; + dx_ext1 = dx0 + 1 - 2 * SQUISH_CONSTANT_4D; + } else { + xsv_ext0 = xsv_ext1 = xsb + 1; + dx_ext0 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; + dx_ext1 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + } + + if ((c1 & 0x02) == 0) { + ysv_ext0 = ysb; + ysv_ext1 = ysb - 1; + dy_ext0 = dy0 - 3 * SQUISH_CONSTANT_4D; + dy_ext1 = dy0 + 1 - 2 * SQUISH_CONSTANT_4D; + } else { + ysv_ext0 = ysv_ext1 = ysb + 1; + dy_ext0 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; + dy_ext1 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + } + + if ((c1 & 0x04) == 0) { + zsv_ext0 = zsb; + zsv_ext1 = zsb - 1; + dz_ext0 = dz0 - 3 * SQUISH_CONSTANT_4D; + dz_ext1 = dz0 + 1 - 2 * SQUISH_CONSTANT_4D; + } else { + zsv_ext0 = zsv_ext1 = zsb + 1; + dz_ext0 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D; + dz_ext1 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + } + + if ((c1 & 0x08) == 0) { + wsv_ext0 = wsb; + wsv_ext1 = wsb - 1; + dw_ext0 = dw0 - 3 * SQUISH_CONSTANT_4D; + dw_ext1 = dw0 + 1 - 2 * SQUISH_CONSTANT_4D; + } else { + wsv_ext0 = wsv_ext1 = wsb + 1; + dw_ext0 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D; + dw_ext1 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + } + + //One combination is a permutation of (0,0,0,2) based on c2 + xsv_ext2 = xsb; + ysv_ext2 = ysb; + zsv_ext2 = zsb; + wsv_ext2 = wsb; + dx_ext2 = dx0 - 2 * SQUISH_CONSTANT_4D; + dy_ext2 = dy0 - 2 * SQUISH_CONSTANT_4D; + dz_ext2 = dz0 - 2 * SQUISH_CONSTANT_4D; + dw_ext2 = dw0 - 2 * SQUISH_CONSTANT_4D; + if ((c2 & 0x01) != 0) { + xsv_ext2 += 2; + dx_ext2 -= 2; + } else if ((c2 & 0x02) != 0) { + ysv_ext2 += 2; + dy_ext2 -= 2; + } else if ((c2 & 0x04) != 0) { + zsv_ext2 += 2; + dz_ext2 -= 2; + } else { + wsv_ext2 += 2; + dw_ext2 -= 2; + } + + } else { //Both closest points on the smaller side + //One of the two extra points is (0,0,0,0) + xsv_ext2 = xsb; + ysv_ext2 = ysb; + zsv_ext2 = zsb; + wsv_ext2 = wsb; + dx_ext2 = dx0; + dy_ext2 = dy0; + dz_ext2 = dz0; + dw_ext2 = dw0; + + //Other two points are based on the omitted axes. + byte c = (byte)(aPoint | bPoint); + + if ((c & 0x01) == 0) { + xsv_ext0 = xsb - 1; + xsv_ext1 = xsb; + dx_ext0 = dx0 + 1 - SQUISH_CONSTANT_4D; + dx_ext1 = dx0 - SQUISH_CONSTANT_4D; + } else { + xsv_ext0 = xsv_ext1 = xsb + 1; + dx_ext0 = dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_4D; + } + + if ((c & 0x02) == 0) { + ysv_ext0 = ysv_ext1 = ysb; + dy_ext0 = dy_ext1 = dy0 - SQUISH_CONSTANT_4D; + if ((c & 0x01) == 0x01) + { + ysv_ext0 -= 1; + dy_ext0 += 1; + } else { + ysv_ext1 -= 1; + dy_ext1 += 1; + } + } else { + ysv_ext0 = ysv_ext1 = ysb + 1; + dy_ext0 = dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_4D; + } + + if ((c & 0x04) == 0) { + zsv_ext0 = zsv_ext1 = zsb; + dz_ext0 = dz_ext1 = dz0 - SQUISH_CONSTANT_4D; + if ((c & 0x03) == 0x03) + { + zsv_ext0 -= 1; + dz_ext0 += 1; + } else { + zsv_ext1 -= 1; + dz_ext1 += 1; + } + } else { + zsv_ext0 = zsv_ext1 = zsb + 1; + dz_ext0 = dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_4D; + } + + if ((c & 0x08) == 0) + { + wsv_ext0 = wsb; + wsv_ext1 = wsb - 1; + dw_ext0 = dw0 - SQUISH_CONSTANT_4D; + dw_ext1 = dw0 + 1 - SQUISH_CONSTANT_4D; + } else { + wsv_ext0 = wsv_ext1 = wsb + 1; + dw_ext0 = dw_ext1 = dw0 - 1 - SQUISH_CONSTANT_4D; + } + + } + } else { //One point on each "side" + byte c1, c2; + if (aIsBiggerSide) { + c1 = aPoint; + c2 = bPoint; + } else { + c1 = bPoint; + c2 = aPoint; + } + + //Two contributions are the bigger-sided point with each 0 replaced with -1. + if ((c1 & 0x01) == 0) { + xsv_ext0 = xsb - 1; + xsv_ext1 = xsb; + dx_ext0 = dx0 + 1 - SQUISH_CONSTANT_4D; + dx_ext1 = dx0 - SQUISH_CONSTANT_4D; + } else { + xsv_ext0 = xsv_ext1 = xsb + 1; + dx_ext0 = dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_4D; + } + + if ((c1 & 0x02) == 0) { + ysv_ext0 = ysv_ext1 = ysb; + dy_ext0 = dy_ext1 = dy0 - SQUISH_CONSTANT_4D; + if ((c1 & 0x01) == 0x01) { + ysv_ext0 -= 1; + dy_ext0 += 1; + } else { + ysv_ext1 -= 1; + dy_ext1 += 1; + } + } else { + ysv_ext0 = ysv_ext1 = ysb + 1; + dy_ext0 = dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_4D; + } + + if ((c1 & 0x04) == 0) { + zsv_ext0 = zsv_ext1 = zsb; + dz_ext0 = dz_ext1 = dz0 - SQUISH_CONSTANT_4D; + if ((c1 & 0x03) == 0x03) { + zsv_ext0 -= 1; + dz_ext0 += 1; + } else { + zsv_ext1 -= 1; + dz_ext1 += 1; + } + } else { + zsv_ext0 = zsv_ext1 = zsb + 1; + dz_ext0 = dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_4D; + } + + if ((c1 & 0x08) == 0) { + wsv_ext0 = wsb; + wsv_ext1 = wsb - 1; + dw_ext0 = dw0 - SQUISH_CONSTANT_4D; + dw_ext1 = dw0 + 1 - SQUISH_CONSTANT_4D; + } else { + wsv_ext0 = wsv_ext1 = wsb + 1; + dw_ext0 = dw_ext1 = dw0 - 1 - SQUISH_CONSTANT_4D; + } + + //One contribution is a permutation of (0,0,0,2) based on the smaller-sided point + xsv_ext2 = xsb; + ysv_ext2 = ysb; + zsv_ext2 = zsb; + wsv_ext2 = wsb; + dx_ext2 = dx0 - 2 * SQUISH_CONSTANT_4D; + dy_ext2 = dy0 - 2 * SQUISH_CONSTANT_4D; + dz_ext2 = dz0 - 2 * SQUISH_CONSTANT_4D; + dw_ext2 = dw0 - 2 * SQUISH_CONSTANT_4D; + if ((c2 & 0x01) != 0) { + xsv_ext2 += 2; + dx_ext2 -= 2; + } else if ((c2 & 0x02) != 0) { + ysv_ext2 += 2; + dy_ext2 -= 2; + } else if ((c2 & 0x04) != 0) { + zsv_ext2 += 2; + dz_ext2 -= 2; + } else { + wsv_ext2 += 2; + dw_ext2 -= 2; + } + } + + //Contribution (1,0,0,0) + double dx1 = dx0 - 1 - SQUISH_CONSTANT_4D; + double dy1 = dy0 - 0 - SQUISH_CONSTANT_4D; + double dz1 = dz0 - 0 - SQUISH_CONSTANT_4D; + double dw1 = dw0 - 0 - SQUISH_CONSTANT_4D; + double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1; + if (attn1 > 0) { + attn1 *= attn1; + value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 0, dx1, dy1, dz1, dw1); + } + + //Contribution (0,1,0,0) + double dx2 = dx0 - 0 - SQUISH_CONSTANT_4D; + double dy2 = dy0 - 1 - SQUISH_CONSTANT_4D; + double dz2 = dz1; + double dw2 = dw1; + double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2; + if (attn2 > 0) { + attn2 *= attn2; + value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 0, dx2, dy2, dz2, dw2); + } + + //Contribution (0,0,1,0) + double dx3 = dx2; + double dy3 = dy1; + double dz3 = dz0 - 1 - SQUISH_CONSTANT_4D; + double dw3 = dw1; + double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3; + if (attn3 > 0) { + attn3 *= attn3; + value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 0, dx3, dy3, dz3, dw3); + } + + //Contribution (0,0,0,1) + double dx4 = dx2; + double dy4 = dy1; + double dz4 = dz1; + double dw4 = dw0 - 1 - SQUISH_CONSTANT_4D; + double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4; + if (attn4 > 0) { + attn4 *= attn4; + value += attn4 * attn4 * extrapolate(xsb + 0, ysb + 0, zsb + 0, wsb + 1, dx4, dy4, dz4, dw4); + } + + //Contribution (1,1,0,0) + double dx5 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dy5 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dz5 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dw5 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D; + double attn5 = 2 - dx5 * dx5 - dy5 * dy5 - dz5 * dz5 - dw5 * dw5; + if (attn5 > 0) { + attn5 *= attn5; + value += attn5 * attn5 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 0, dx5, dy5, dz5, dw5); + } + + //Contribution (1,0,1,0) + double dx6 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dy6 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dz6 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dw6 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D; + double attn6 = 2 - dx6 * dx6 - dy6 * dy6 - dz6 * dz6 - dw6 * dw6; + if (attn6 > 0) { + attn6 *= attn6; + value += attn6 * attn6 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 0, dx6, dy6, dz6, dw6); + } + + //Contribution (1,0,0,1) + double dx7 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dy7 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dz7 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dw7 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + double attn7 = 2 - dx7 * dx7 - dy7 * dy7 - dz7 * dz7 - dw7 * dw7; + if (attn7 > 0) { + attn7 *= attn7; + value += attn7 * attn7 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 1, dx7, dy7, dz7, dw7); + } + + //Contribution (0,1,1,0) + double dx8 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dy8 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dz8 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dw8 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D; + double attn8 = 2 - dx8 * dx8 - dy8 * dy8 - dz8 * dz8 - dw8 * dw8; + if (attn8 > 0) { + attn8 *= attn8; + value += attn8 * attn8 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 0, dx8, dy8, dz8, dw8); + } + + //Contribution (0,1,0,1) + double dx9 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dy9 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dz9 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dw9 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + double attn9 = 2 - dx9 * dx9 - dy9 * dy9 - dz9 * dz9 - dw9 * dw9; + if (attn9 > 0) { + attn9 *= attn9; + value += attn9 * attn9 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 1, dx9, dy9, dz9, dw9); + } + + //Contribution (0,0,1,1) + double dx10 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dy10 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dz10 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dw10 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + double attn10 = 2 - dx10 * dx10 - dy10 * dy10 - dz10 * dz10 - dw10 * dw10; + if (attn10 > 0) { + attn10 *= attn10; + value += attn10 * attn10 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 1, dx10, dy10, dz10, dw10); + } + } else { //We're inside the second dispentachoron (Rectified 4-Simplex) + double aScore; + byte aPoint; + boolean aIsBiggerSide = true; + double bScore; + byte bPoint; + boolean bIsBiggerSide = true; + + //Decide between (0,0,1,1) and (1,1,0,0) + if (xins + yins < zins + wins) { + aScore = xins + yins; + aPoint = 0x0C; + } else { + aScore = zins + wins; + aPoint = 0x03; + } + + //Decide between (0,1,0,1) and (1,0,1,0) + if (xins + zins < yins + wins) { + bScore = xins + zins; + bPoint = 0x0A; + } else { + bScore = yins + wins; + bPoint = 0x05; + } + + //Closer between (0,1,1,0) and (1,0,0,1) will replace the further of a and b, if closer. + if (xins + wins < yins + zins) { + double score = xins + wins; + if (aScore <= bScore && score < bScore) { + bScore = score; + bPoint = 0x06; + } else if (aScore > bScore && score < aScore) { + aScore = score; + aPoint = 0x06; + } + } else { + double score = yins + zins; + if (aScore <= bScore && score < bScore) { + bScore = score; + bPoint = 0x09; + } else if (aScore > bScore && score < aScore) { + aScore = score; + aPoint = 0x09; + } + } + + //Decide if (0,1,1,1) is closer. + double p1 = 3 - inSum + xins; + if (aScore <= bScore && p1 < bScore) { + bScore = p1; + bPoint = 0x0E; + bIsBiggerSide = false; + } else if (aScore > bScore && p1 < aScore) { + aScore = p1; + aPoint = 0x0E; + aIsBiggerSide = false; + } + + //Decide if (1,0,1,1) is closer. + double p2 = 3 - inSum + yins; + if (aScore <= bScore && p2 < bScore) { + bScore = p2; + bPoint = 0x0D; + bIsBiggerSide = false; + } else if (aScore > bScore && p2 < aScore) { + aScore = p2; + aPoint = 0x0D; + aIsBiggerSide = false; + } + + //Decide if (1,1,0,1) is closer. + double p3 = 3 - inSum + zins; + if (aScore <= bScore && p3 < bScore) { + bScore = p3; + bPoint = 0x0B; + bIsBiggerSide = false; + } else if (aScore > bScore && p3 < aScore) { + aScore = p3; + aPoint = 0x0B; + aIsBiggerSide = false; + } + + //Decide if (1,1,1,0) is closer. + double p4 = 3 - inSum + wins; + if (aScore <= bScore && p4 < bScore) { + bScore = p4; + bPoint = 0x07; + bIsBiggerSide = false; + } else if (aScore > bScore && p4 < aScore) { + aScore = p4; + aPoint = 0x07; + aIsBiggerSide = false; + } + + //Where each of the two closest points are determines how the extra three vertices are calculated. + if (aIsBiggerSide == bIsBiggerSide) { + if (aIsBiggerSide) { //Both closest points on the bigger side + byte c1 = (byte)(aPoint & bPoint); + byte c2 = (byte)(aPoint | bPoint); + + //Two contributions are permutations of (0,0,0,1) and (0,0,0,2) based on c1 + xsv_ext0 = xsv_ext1 = xsb; + ysv_ext0 = ysv_ext1 = ysb; + zsv_ext0 = zsv_ext1 = zsb; + wsv_ext0 = wsv_ext1 = wsb; + dx_ext0 = dx0 - SQUISH_CONSTANT_4D; + dy_ext0 = dy0 - SQUISH_CONSTANT_4D; + dz_ext0 = dz0 - SQUISH_CONSTANT_4D; + dw_ext0 = dw0 - SQUISH_CONSTANT_4D; + dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_4D; + dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_4D; + dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_4D; + dw_ext1 = dw0 - 2 * SQUISH_CONSTANT_4D; + if ((c1 & 0x01) != 0) { + xsv_ext0 += 1; + dx_ext0 -= 1; + xsv_ext1 += 2; + dx_ext1 -= 2; + } else if ((c1 & 0x02) != 0) { + ysv_ext0 += 1; + dy_ext0 -= 1; + ysv_ext1 += 2; + dy_ext1 -= 2; + } else if ((c1 & 0x04) != 0) { + zsv_ext0 += 1; + dz_ext0 -= 1; + zsv_ext1 += 2; + dz_ext1 -= 2; + } else { + wsv_ext0 += 1; + dw_ext0 -= 1; + wsv_ext1 += 2; + dw_ext1 -= 2; + } + + //One contribution is a permutation of (1,1,1,-1) based on c2 + xsv_ext2 = xsb + 1; + ysv_ext2 = ysb + 1; + zsv_ext2 = zsb + 1; + wsv_ext2 = wsb + 1; + dx_ext2 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + dy_ext2 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + dz_ext2 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + dw_ext2 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + if ((c2 & 0x01) == 0) { + xsv_ext2 -= 2; + dx_ext2 += 2; + } else if ((c2 & 0x02) == 0) { + ysv_ext2 -= 2; + dy_ext2 += 2; + } else if ((c2 & 0x04) == 0) { + zsv_ext2 -= 2; + dz_ext2 += 2; + } else { + wsv_ext2 -= 2; + dw_ext2 += 2; + } + } else { //Both closest points on the smaller side + //One of the two extra points is (1,1,1,1) + xsv_ext2 = xsb + 1; + ysv_ext2 = ysb + 1; + zsv_ext2 = zsb + 1; + wsv_ext2 = wsb + 1; + dx_ext2 = dx0 - 1 - 4 * SQUISH_CONSTANT_4D; + dy_ext2 = dy0 - 1 - 4 * SQUISH_CONSTANT_4D; + dz_ext2 = dz0 - 1 - 4 * SQUISH_CONSTANT_4D; + dw_ext2 = dw0 - 1 - 4 * SQUISH_CONSTANT_4D; + + //Other two points are based on the shared axes. + byte c = (byte)(aPoint & bPoint); + + if ((c & 0x01) != 0) { + xsv_ext0 = xsb + 2; + xsv_ext1 = xsb + 1; + dx_ext0 = dx0 - 2 - 3 * SQUISH_CONSTANT_4D; + dx_ext1 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; + } else { + xsv_ext0 = xsv_ext1 = xsb; + dx_ext0 = dx_ext1 = dx0 - 3 * SQUISH_CONSTANT_4D; + } + + if ((c & 0x02) != 0) { + ysv_ext0 = ysv_ext1 = ysb + 1; + dy_ext0 = dy_ext1 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; + if ((c & 0x01) == 0) + { + ysv_ext0 += 1; + dy_ext0 -= 1; + } else { + ysv_ext1 += 1; + dy_ext1 -= 1; + } + } else { + ysv_ext0 = ysv_ext1 = ysb; + dy_ext0 = dy_ext1 = dy0 - 3 * SQUISH_CONSTANT_4D; + } + + if ((c & 0x04) != 0) { + zsv_ext0 = zsv_ext1 = zsb + 1; + dz_ext0 = dz_ext1 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D; + if ((c & 0x03) == 0) + { + zsv_ext0 += 1; + dz_ext0 -= 1; + } else { + zsv_ext1 += 1; + dz_ext1 -= 1; + } + } else { + zsv_ext0 = zsv_ext1 = zsb; + dz_ext0 = dz_ext1 = dz0 - 3 * SQUISH_CONSTANT_4D; + } + + if ((c & 0x08) != 0) + { + wsv_ext0 = wsb + 1; + wsv_ext1 = wsb + 2; + dw_ext0 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D; + dw_ext1 = dw0 - 2 - 3 * SQUISH_CONSTANT_4D; + } else { + wsv_ext0 = wsv_ext1 = wsb; + dw_ext0 = dw_ext1 = dw0 - 3 * SQUISH_CONSTANT_4D; + } + } + } else { //One point on each "side" + byte c1, c2; + if (aIsBiggerSide) { + c1 = aPoint; + c2 = bPoint; + } else { + c1 = bPoint; + c2 = aPoint; + } + + //Two contributions are the bigger-sided point with each 1 replaced with 2. + if ((c1 & 0x01) != 0) { + xsv_ext0 = xsb + 2; + xsv_ext1 = xsb + 1; + dx_ext0 = dx0 - 2 - 3 * SQUISH_CONSTANT_4D; + dx_ext1 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; + } else { + xsv_ext0 = xsv_ext1 = xsb; + dx_ext0 = dx_ext1 = dx0 - 3 * SQUISH_CONSTANT_4D; + } + + if ((c1 & 0x02) != 0) { + ysv_ext0 = ysv_ext1 = ysb + 1; + dy_ext0 = dy_ext1 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; + if ((c1 & 0x01) == 0) { + ysv_ext0 += 1; + dy_ext0 -= 1; + } else { + ysv_ext1 += 1; + dy_ext1 -= 1; + } + } else { + ysv_ext0 = ysv_ext1 = ysb; + dy_ext0 = dy_ext1 = dy0 - 3 * SQUISH_CONSTANT_4D; + } + + if ((c1 & 0x04) != 0) { + zsv_ext0 = zsv_ext1 = zsb + 1; + dz_ext0 = dz_ext1 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D; + if ((c1 & 0x03) == 0) { + zsv_ext0 += 1; + dz_ext0 -= 1; + } else { + zsv_ext1 += 1; + dz_ext1 -= 1; + } + } else { + zsv_ext0 = zsv_ext1 = zsb; + dz_ext0 = dz_ext1 = dz0 - 3 * SQUISH_CONSTANT_4D; + } + + if ((c1 & 0x08) != 0) { + wsv_ext0 = wsb + 1; + wsv_ext1 = wsb + 2; + dw_ext0 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D; + dw_ext1 = dw0 - 2 - 3 * SQUISH_CONSTANT_4D; + } else { + wsv_ext0 = wsv_ext1 = wsb; + dw_ext0 = dw_ext1 = dw0 - 3 * SQUISH_CONSTANT_4D; + } + + //One contribution is a permutation of (1,1,1,-1) based on the smaller-sided point + xsv_ext2 = xsb + 1; + ysv_ext2 = ysb + 1; + zsv_ext2 = zsb + 1; + wsv_ext2 = wsb + 1; + dx_ext2 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + dy_ext2 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + dz_ext2 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + dw_ext2 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + if ((c2 & 0x01) == 0) { + xsv_ext2 -= 2; + dx_ext2 += 2; + } else if ((c2 & 0x02) == 0) { + ysv_ext2 -= 2; + dy_ext2 += 2; + } else if ((c2 & 0x04) == 0) { + zsv_ext2 -= 2; + dz_ext2 += 2; + } else { + wsv_ext2 -= 2; + dw_ext2 += 2; + } + } + + //Contribution (1,1,1,0) + double dx4 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; + double dy4 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; + double dz4 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D; + double dw4 = dw0 - 3 * SQUISH_CONSTANT_4D; + double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4; + if (attn4 > 0) { + attn4 *= attn4; + value += attn4 * attn4 * extrapolate(xsb + 1, ysb + 1, zsb + 1, wsb + 0, dx4, dy4, dz4, dw4); + } + + //Contribution (1,1,0,1) + double dx3 = dx4; + double dy3 = dy4; + double dz3 = dz0 - 3 * SQUISH_CONSTANT_4D; + double dw3 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D; + double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3; + if (attn3 > 0) { + attn3 *= attn3; + value += attn3 * attn3 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 1, dx3, dy3, dz3, dw3); + } + + //Contribution (1,0,1,1) + double dx2 = dx4; + double dy2 = dy0 - 3 * SQUISH_CONSTANT_4D; + double dz2 = dz4; + double dw2 = dw3; + double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2; + if (attn2 > 0) { + attn2 *= attn2; + value += attn2 * attn2 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 1, dx2, dy2, dz2, dw2); + } + + //Contribution (0,1,1,1) + double dx1 = dx0 - 3 * SQUISH_CONSTANT_4D; + double dz1 = dz4; + double dy1 = dy4; + double dw1 = dw3; + double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1; + if (attn1 > 0) { + attn1 *= attn1; + value += attn1 * attn1 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 1, dx1, dy1, dz1, dw1); + } + + //Contribution (1,1,0,0) + double dx5 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dy5 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dz5 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dw5 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D; + double attn5 = 2 - dx5 * dx5 - dy5 * dy5 - dz5 * dz5 - dw5 * dw5; + if (attn5 > 0) { + attn5 *= attn5; + value += attn5 * attn5 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 0, dx5, dy5, dz5, dw5); + } + + //Contribution (1,0,1,0) + double dx6 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dy6 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dz6 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dw6 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D; + double attn6 = 2 - dx6 * dx6 - dy6 * dy6 - dz6 * dz6 - dw6 * dw6; + if (attn6 > 0) { + attn6 *= attn6; + value += attn6 * attn6 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 0, dx6, dy6, dz6, dw6); + } + + //Contribution (1,0,0,1) + double dx7 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dy7 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dz7 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dw7 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + double attn7 = 2 - dx7 * dx7 - dy7 * dy7 - dz7 * dz7 - dw7 * dw7; + if (attn7 > 0) { + attn7 *= attn7; + value += attn7 * attn7 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 1, dx7, dy7, dz7, dw7); + } + + //Contribution (0,1,1,0) + double dx8 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dy8 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dz8 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dw8 = dw0 - 0 - 2 * SQUISH_CONSTANT_4D; + double attn8 = 2 - dx8 * dx8 - dy8 * dy8 - dz8 * dz8 - dw8 * dw8; + if (attn8 > 0) { + attn8 *= attn8; + value += attn8 * attn8 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 0, dx8, dy8, dz8, dw8); + } + + //Contribution (0,1,0,1) + double dx9 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dy9 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dz9 = dz0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dw9 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + double attn9 = 2 - dx9 * dx9 - dy9 * dy9 - dz9 * dz9 - dw9 * dw9; + if (attn9 > 0) { + attn9 *= attn9; + value += attn9 * attn9 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 1, dx9, dy9, dz9, dw9); + } + + //Contribution (0,0,1,1) + double dx10 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dy10 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; + double dz10 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; + double dw10 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; + double attn10 = 2 - dx10 * dx10 - dy10 * dy10 - dz10 * dz10 - dw10 * dw10; + if (attn10 > 0) { + attn10 *= attn10; + value += attn10 * attn10 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 1, dx10, dy10, dz10, dw10); + } + } + + //First extra vertex + double attn_ext0 = 2 - dx_ext0 * dx_ext0 - dy_ext0 * dy_ext0 - dz_ext0 * dz_ext0 - dw_ext0 * dw_ext0; + if (attn_ext0 > 0) + { + attn_ext0 *= attn_ext0; + value += attn_ext0 * attn_ext0 * extrapolate(xsv_ext0, ysv_ext0, zsv_ext0, wsv_ext0, dx_ext0, dy_ext0, dz_ext0, dw_ext0); + } + + //Second extra vertex + double attn_ext1 = 2 - dx_ext1 * dx_ext1 - dy_ext1 * dy_ext1 - dz_ext1 * dz_ext1 - dw_ext1 * dw_ext1; + if (attn_ext1 > 0) + { + attn_ext1 *= attn_ext1; + value += attn_ext1 * attn_ext1 * extrapolate(xsv_ext1, ysv_ext1, zsv_ext1, wsv_ext1, dx_ext1, dy_ext1, dz_ext1, dw_ext1); + } + + //Third extra vertex + double attn_ext2 = 2 - dx_ext2 * dx_ext2 - dy_ext2 * dy_ext2 - dz_ext2 * dz_ext2 - dw_ext2 * dw_ext2; + if (attn_ext2 > 0) + { + attn_ext2 *= attn_ext2; + value += attn_ext2 * attn_ext2 * extrapolate(xsv_ext2, ysv_ext2, zsv_ext2, wsv_ext2, dx_ext2, dy_ext2, dz_ext2, dw_ext2); + } + + return value / NORM_CONSTANT_4D; + } + + private double extrapolate(int xsb, int ysb, double dx, double dy) + { + int index = perm[(perm[xsb & 0xFF] + ysb) & 0xFF] & 0x0E; + return gradients2D[index] * dx + + gradients2D[index + 1] * dy; + } + + private double extrapolate(int xsb, int ysb, int zsb, double dx, double dy, double dz) + { + int index = permGradIndex3D[(perm[(perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF]; + return gradients3D[index] * dx + + gradients3D[index + 1] * dy + + gradients3D[index + 2] * dz; + } + + private double extrapolate(int xsb, int ysb, int zsb, int wsb, double dx, double dy, double dz, double dw) + { + int index = perm[(perm[(perm[(perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF] + wsb) & 0xFF] & 0xFC; + return gradients4D[index] * dx + + gradients4D[index + 1] * dy + + gradients4D[index + 2] * dz + + gradients4D[index + 3] * dw; + } + + private static int fastFloor(double x) { + int xi = (int)x; + return x < xi ? xi - 1 : xi; + } + + //Gradients for 2D. They approximate the directions to the + //vertices of an octagon from the center. + private static byte[] gradients2D = new byte[] { + 5, 2, 2, 5, + -5, 2, -2, 5, + 5, -2, 2, -5, + -5, -2, -2, -5, + }; + + //Gradients for 3D. They approximate the directions to the + //vertices of a rhombicuboctahedron from the center, skewed so + //that the triangular and square facets can be inscribed inside + //circles of the same radius. + private static byte[] gradients3D = new byte[] { + -11, 4, 4, -4, 11, 4, -4, 4, 11, + 11, 4, 4, 4, 11, 4, 4, 4, 11, + -11, -4, 4, -4, -11, 4, -4, -4, 11, + 11, -4, 4, 4, -11, 4, 4, -4, 11, + -11, 4, -4, -4, 11, -4, -4, 4, -11, + 11, 4, -4, 4, 11, -4, 4, 4, -11, + -11, -4, -4, -4, -11, -4, -4, -4, -11, + 11, -4, -4, 4, -11, -4, 4, -4, -11, + }; + + //Gradients for 4D. They approximate the directions to the + //vertices of a disprismatotesseractihexadecachoron from the center, + //skewed so that the tetrahedral and cubic facets can be inscribed inside + //spheres of the same radius. + private static byte[] gradients4D = new byte[] { + 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, + -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, + 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, + -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, + 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, + -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, + 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, + -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, + 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, + -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, + 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, + -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, + 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, + -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, + 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, + -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, + }; +} \ No newline at end of file diff --git a/StorageSim/src/lib/SQLConnection.java b/StorageSim/src/lib/SQLConnection.java new file mode 100644 index 0000000..2975479 --- /dev/null +++ b/StorageSim/src/lib/SQLConnection.java @@ -0,0 +1,135 @@ +package lib; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * SQL helper to interact with the database + * + * @author Manuel + */ +public class SQLConnection { + + Connection con; + + public SQLConnection() { + this("102-012/sven"); + } + + public SQLConnection(String url) { + this(url, "intabi19", "hallo"); + } + + public SQLConnection(String url, String username, String password) { + try { + this.con = DriverManager.getConnection("jdbc:mysql://" + url, username, password); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /** + * Executes a query without storing the return values + * + * @param sqlQuery SQL command to be executed + */ + public void execute(String sqlQuery) { + try { + //System.out.println("SQL: " + sqlQuery); + this.con.createStatement().execute(sqlQuery); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /** + * @returns table headers in a list from an existing meta data object + */ + private ArrayList getColumnNames(ResultSetMetaData metaData) throws SQLException { + int columns = metaData.getColumnCount(); + + ArrayList columnTitles = new ArrayList<>(); + for (int i = 0; i < columns; i++) { + columnTitles.add(metaData.getColumnLabel(i + 1)); + } + + return columnTitles; + } + + /** + * Converts the database return values into a usable format + * + * @param sqlQuery SQL command to be executed + * @return a list of rows that are keyed by their column name + */ + public ArrayList> queryToMap(String sqlQuery) { + ArrayList> data = new ArrayList<>(); + + //System.out.println("SQLq: " + sqlQuery); + + try { + ResultSet result = this.con.createStatement().executeQuery(sqlQuery); + ResultSetMetaData metaData = result.getMetaData(); + + int columns = metaData.getColumnCount(); + + ArrayList columnTitles = getColumnNames(metaData); + + // iterate over all rows + while (result.next()) { + HashMap row = new HashMap<>(); + for (int i = 0; i < columns; i++) { + // copy items from table to row + row.put(columnTitles.get(i), result.getString(i + 1)); + } + data.add(row); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + return data; + } + + @Deprecated + public ArrayList> queryToArray(String sqlQuery) { + ArrayList> data = new ArrayList<>(); + + try { + ResultSet result = this.con.createStatement().executeQuery(sqlQuery); + ResultSetMetaData metaData = result.getMetaData(); + + int columns = metaData.getColumnCount(); + + // iterate over all rows + while (result.next()) { + ArrayList row = new ArrayList<>(); + for (int i = 0; i < columns; i++) { + // copy items from table to row + row.add(result.getString(i + 1)); + } + data.add(row); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + return data; + } + + /** + * Closes the connection with the database + */ + public void close() { + try { + this.con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } +} diff --git a/StorageSim/src/org/mindrot/BCrypt.java b/StorageSim/src/org/mindrot/BCrypt.java new file mode 100644 index 0000000..e68d62e --- /dev/null +++ b/StorageSim/src/org/mindrot/BCrypt.java @@ -0,0 +1,778 @@ +package org.mindrot; + +// Copyright (c) 2006 Damien Miller +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import java.io.UnsupportedEncodingException; + +import java.security.SecureRandom; + +/** + * BCrypt implements OpenBSD-style Blowfish password hashing using + * the scheme described in "A Future-Adaptable Password Scheme" by + * Niels Provos and David Mazieres. + *

+ * This password hashing system tries to thwart off-line password + * cracking using a computationally-intensive hashing algorithm, + * based on Bruce Schneier's Blowfish cipher. The work factor of + * the algorithm is parameterised, so it can be increased as + * computers get faster. + *

+ * Usage is really simple. To hash a password for the first time, + * call the hashpw method with a random salt, like this: + *

+ * + * String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt());
+ *
+ *

+ * To check whether a plaintext password matches one that has been + * hashed previously, use the checkpw method: + *

+ * + * if (BCrypt.checkpw(candidate_password, stored_hash))
+ *     System.out.println("It matches");
+ * else
+ *     System.out.println("It does not match");
+ *
+ *

+ * The gensalt() method takes an optional parameter (log_rounds) + * that determines the computational complexity of the hashing: + *

+ * + * String strong_salt = BCrypt.gensalt(10)
+ * String stronger_salt = BCrypt.gensalt(12)
+ *
+ *

+ * The amount of work increases exponentially (2**log_rounds), so + * each increment is twice as much work. The default log_rounds is + * 10, and the valid range is 4 to 30. + * + * @author Damien Miller + * @version 0.4 + */ +public class BCrypt { + // BCrypt parameters + private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10; + private static final int BCRYPT_SALT_LEN = 16; + + // Blowfish parameters + private static final int BLOWFISH_NUM_ROUNDS = 16; + + // Initial contents of key schedule + private static final int P_orig[] = { + 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, + 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, + 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, + 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, + 0x9216d5d9, 0x8979fb1b + }; + private static final int S_orig[] = { + 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, + 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, + 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, + 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, + 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, + 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, + 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, + 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, + 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, + 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, + 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, + 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, + 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, + 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, + 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, + 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, + 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, + 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, + 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, + 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, + 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, + 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, + 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, + 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, + 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, + 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, + 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, + 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, + 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, + 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, + 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, + 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, + 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, + 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, + 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, + 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, + 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, + 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, + 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, + 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, + 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, + 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, + 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, + 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, + 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, + 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, + 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, + 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, + 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, + 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, + 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, + 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, + 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, + 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, + 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, + 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, + 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, + 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, + 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, + 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, + 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, + 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, + 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, + 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a, + 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, + 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, + 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, + 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, + 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, + 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, + 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, + 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, + 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, + 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, + 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, + 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, + 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, + 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, + 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, + 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, + 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, + 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, + 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, + 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, + 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, + 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, + 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, + 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, + 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, + 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, + 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, + 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, + 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, + 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, + 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, + 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, + 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, + 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, + 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, + 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, + 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, + 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, + 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, + 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, + 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, + 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, + 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, + 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, + 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, + 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, + 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, + 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, + 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, + 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, + 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, + 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, + 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, + 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, + 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, + 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, + 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, + 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, + 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, + 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, + 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, + 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, + 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, + 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7, + 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, + 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, + 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, + 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, + 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, + 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, + 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, + 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, + 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, + 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, + 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, + 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, + 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, + 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, + 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, + 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, + 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, + 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, + 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, + 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, + 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, + 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, + 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, + 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, + 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, + 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, + 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, + 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, + 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, + 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, + 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, + 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, + 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, + 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, + 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, + 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, + 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, + 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, + 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, + 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, + 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, + 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, + 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, + 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, + 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, + 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, + 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, + 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, + 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, + 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, + 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, + 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, + 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, + 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, + 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, + 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, + 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, + 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, + 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, + 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, + 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, + 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, + 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, + 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0, + 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, + 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, + 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, + 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, + 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, + 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, + 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, + 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, + 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, + 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, + 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, + 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, + 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, + 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, + 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, + 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, + 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, + 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, + 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, + 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, + 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, + 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, + 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, + 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, + 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, + 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, + 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, + 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, + 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, + 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, + 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, + 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, + 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, + 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, + 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, + 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, + 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, + 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, + 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, + 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, + 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, + 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, + 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, + 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, + 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, + 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, + 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, + 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, + 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, + 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, + 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, + 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, + 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, + 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, + 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, + 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, + 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, + 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, + 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, + 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, + 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, + 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, + 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, + 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 + }; + + // bcrypt IV: "OrpheanBeholderScryDoubt". The C implementation calls + // this "ciphertext", but it is really plaintext or an IV. We keep + // the name to make code comparison easier. + static private final int bf_crypt_ciphertext[] = { + 0x4f727068, 0x65616e42, 0x65686f6c, + 0x64657253, 0x63727944, 0x6f756274 + }; + + // Table for Base64 encoding + static private final char base64_code[] = { + '.', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', + 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', + '6', '7', '8', '9' + }; + + // Table for Base64 decoding + static private final byte index_64[] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 0, 1, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, -1, -1, + -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + -1, -1, -1, -1, -1, -1, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, -1, -1, -1, -1, -1 + }; + + // Expanded Blowfish key + private int P[]; + private int S[]; + + /** + * Encode a byte array using bcrypt's slightly-modified base64 + * encoding scheme. Note that this is *not* compatible with + * the standard MIME-base64 encoding. + * + * @param d the byte array to encode + * @param len the number of bytes to encode + * @return base64-encoded string + * @exception IllegalArgumentException if the length is invalid + */ + private static String encode_base64(byte d[], int len) + throws IllegalArgumentException { + int off = 0; + StringBuffer rs = new StringBuffer(); + int c1, c2; + + if (len <= 0 || len > d.length) + throw new IllegalArgumentException ("Invalid len"); + + while (off < len) { + c1 = d[off++] & 0xff; + rs.append(base64_code[(c1 >> 2) & 0x3f]); + c1 = (c1 & 0x03) << 4; + if (off >= len) { + rs.append(base64_code[c1 & 0x3f]); + break; + } + c2 = d[off++] & 0xff; + c1 |= (c2 >> 4) & 0x0f; + rs.append(base64_code[c1 & 0x3f]); + c1 = (c2 & 0x0f) << 2; + if (off >= len) { + rs.append(base64_code[c1 & 0x3f]); + break; + } + c2 = d[off++] & 0xff; + c1 |= (c2 >> 6) & 0x03; + rs.append(base64_code[c1 & 0x3f]); + rs.append(base64_code[c2 & 0x3f]); + } + return rs.toString(); + } + + /** + * Look up the 3 bits base64-encoded by the specified character, + * range-checking againt conversion table + * @param x the base64-encoded value + * @return the decoded value of x + */ + private static byte char64(char x) { + if ((int)x < 0 || (int)x > index_64.length) + return -1; + return index_64[(int)x]; + } + + /** + * Decode a string encoded using bcrypt's base64 scheme to a + * byte array. Note that this is *not* compatible with + * the standard MIME-base64 encoding. + * @param s the string to decode + * @param maxolen the maximum number of bytes to decode + * @return an array containing the decoded bytes + * @throws IllegalArgumentException if maxolen is invalid + */ + private static byte[] decode_base64(String s, int maxolen) + throws IllegalArgumentException { + StringBuffer rs = new StringBuffer(); + int off = 0, slen = s.length(), olen = 0; + byte ret[]; + byte c1, c2, c3, c4, o; + + if (maxolen <= 0) + throw new IllegalArgumentException ("Invalid maxolen"); + + while (off < slen - 1 && olen < maxolen) { + c1 = char64(s.charAt(off++)); + c2 = char64(s.charAt(off++)); + if (c1 == -1 || c2 == -1) + break; + o = (byte)(c1 << 2); + o |= (c2 & 0x30) >> 4; + rs.append((char)o); + if (++olen >= maxolen || off >= slen) + break; + c3 = char64(s.charAt(off++)); + if (c3 == -1) + break; + o = (byte)((c2 & 0x0f) << 4); + o |= (c3 & 0x3c) >> 2; + rs.append((char)o); + if (++olen >= maxolen || off >= slen) + break; + c4 = char64(s.charAt(off++)); + o = (byte)((c3 & 0x03) << 6); + o |= c4; + rs.append((char)o); + ++olen; + } + + ret = new byte[olen]; + for (off = 0; off < olen; off++) + ret[off] = (byte)rs.charAt(off); + return ret; + } + + /** + * Blowfish encipher a single 64-bit block encoded as + * two 32-bit halves + * @param lr an array containing the two 32-bit half blocks + * @param off the position in the array of the blocks + */ + private final void encipher(int lr[], int off) { + int i, n, l = lr[off], r = lr[off + 1]; + + l ^= P[0]; + for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;) { + // Feistel substitution on left word + n = S[(l >> 24) & 0xff]; + n += S[0x100 | ((l >> 16) & 0xff)]; + n ^= S[0x200 | ((l >> 8) & 0xff)]; + n += S[0x300 | (l & 0xff)]; + r ^= n ^ P[++i]; + + // Feistel substitution on right word + n = S[(r >> 24) & 0xff]; + n += S[0x100 | ((r >> 16) & 0xff)]; + n ^= S[0x200 | ((r >> 8) & 0xff)]; + n += S[0x300 | (r & 0xff)]; + l ^= n ^ P[++i]; + } + lr[off] = r ^ P[BLOWFISH_NUM_ROUNDS + 1]; + lr[off + 1] = l; + } + + /** + * Cycically extract a word of key material + * @param data the string to extract the data from + * @param offp a "pointer" (as a one-entry array) to the + * current offset into data + * @return the next word of material from data + */ + private static int streamtoword(byte data[], int offp[]) { + int i; + int word = 0; + int off = offp[0]; + + for (i = 0; i < 4; i++) { + word = (word << 8) | (data[off] & 0xff); + off = (off + 1) % data.length; + } + + offp[0] = off; + return word; + } + + /** + * Initialise the Blowfish key schedule + */ + private void init_key() { + P = (int[])P_orig.clone(); + S = (int[])S_orig.clone(); + } + + /** + * Key the Blowfish cipher + * @param key an array containing the key + */ + private void key(byte key[]) { + int i; + int koffp[] = { 0 }; + int lr[] = { 0, 0 }; + int plen = P.length, slen = S.length; + + for (i = 0; i < plen; i++) + P[i] = P[i] ^ streamtoword(key, koffp); + + for (i = 0; i < plen; i += 2) { + encipher(lr, 0); + P[i] = lr[0]; + P[i + 1] = lr[1]; + } + + for (i = 0; i < slen; i += 2) { + encipher(lr, 0); + S[i] = lr[0]; + S[i + 1] = lr[1]; + } + } + + /** + * Perform the "enhanced key schedule" step described by + * Provos and Mazieres in "A Future-Adaptable Password Scheme" + * http://www.openbsd.org/papers/bcrypt-paper.ps + * @param data salt information + * @param key password information + */ + private void ekskey(byte data[], byte key[]) { + int i; + int koffp[] = { 0 }, doffp[] = { 0 }; + int lr[] = { 0, 0 }; + int plen = P.length, slen = S.length; + + for (i = 0; i < plen; i++) + P[i] = P[i] ^ streamtoword(key, koffp); + + for (i = 0; i < plen; i += 2) { + lr[0] ^= streamtoword(data, doffp); + lr[1] ^= streamtoword(data, doffp); + encipher(lr, 0); + P[i] = lr[0]; + P[i + 1] = lr[1]; + } + + for (i = 0; i < slen; i += 2) { + lr[0] ^= streamtoword(data, doffp); + lr[1] ^= streamtoword(data, doffp); + encipher(lr, 0); + S[i] = lr[0]; + S[i + 1] = lr[1]; + } + } + + /** + * Perform the central password hashing step in the + * bcrypt scheme + * @param password the password to hash + * @param salt the binary salt to hash with the password + * @param log_rounds the binary logarithm of the number + * of rounds of hashing to apply + * @param cdata the plaintext to encrypt + * @return an array containing the binary hashed password + */ + public byte[] crypt_raw(byte password[], byte salt[], int log_rounds, + int cdata[]) { + int rounds, i, j; + int clen = cdata.length; + byte ret[]; + + if (log_rounds < 4 || log_rounds > 30) + throw new IllegalArgumentException ("Bad number of rounds"); + rounds = 1 << log_rounds; + if (salt.length != BCRYPT_SALT_LEN) + throw new IllegalArgumentException ("Bad salt length"); + + init_key(); + ekskey(salt, password); + for (i = 0; i != rounds; i++) { + key(password); + key(salt); + } + + for (i = 0; i < 64; i++) { + for (j = 0; j < (clen >> 1); j++) + encipher(cdata, j << 1); + } + + ret = new byte[clen * 4]; + for (i = 0, j = 0; i < clen; i++) { + ret[j++] = (byte)((cdata[i] >> 24) & 0xff); + ret[j++] = (byte)((cdata[i] >> 16) & 0xff); + ret[j++] = (byte)((cdata[i] >> 8) & 0xff); + ret[j++] = (byte)(cdata[i] & 0xff); + } + return ret; + } + + /** + * Hash a password using the OpenBSD bcrypt scheme + * @param password the password to hash + * @param salt the salt to hash with (perhaps generated + * using BCrypt.gensalt) + * @return the hashed password + */ + public static String hashpw(String password, String salt) { + BCrypt B; + String real_salt; + byte passwordb[], saltb[], hashed[]; + char minor = (char)0; + int rounds, off = 0; + StringBuffer rs = new StringBuffer(); + + if (salt.charAt(0) != '$' || salt.charAt(1) != '2') + throw new IllegalArgumentException ("Invalid salt version"); + if (salt.charAt(2) == '$') + off = 3; + else { + minor = salt.charAt(2); + if (minor != 'a' || salt.charAt(3) != '$') + throw new IllegalArgumentException ("Invalid salt revision"); + off = 4; + } + + // Extract number of rounds + if (salt.charAt(off + 2) > '$') + throw new IllegalArgumentException ("Missing salt rounds"); + rounds = Integer.parseInt(salt.substring(off, off + 2)); + + real_salt = salt.substring(off + 3, off + 25); + try { + passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8"); + } catch (UnsupportedEncodingException uee) { + throw new AssertionError("UTF-8 is not supported"); + } + + saltb = decode_base64(real_salt, BCRYPT_SALT_LEN); + + B = new BCrypt(); + hashed = B.crypt_raw(passwordb, saltb, rounds, + (int[])bf_crypt_ciphertext.clone()); + + rs.append("$2"); + if (minor >= 'a') + rs.append(minor); + rs.append("$"); + if (rounds < 10) + rs.append("0"); + if (rounds > 30) { + throw new IllegalArgumentException( + "rounds exceeds maximum (30)"); + } + rs.append(Integer.toString(rounds)); + rs.append("$"); + rs.append(encode_base64(saltb, saltb.length)); + rs.append(encode_base64(hashed, + bf_crypt_ciphertext.length * 4 - 1)); + return rs.toString(); + } + + /** + * Generate a salt for use with the BCrypt.hashpw() method + * @param log_rounds the log2 of the number of rounds of + * hashing to apply - the work factor therefore increases as + * 2**log_rounds. + * @param random an instance of SecureRandom to use + * @return an encoded salt value + */ + public static String gensalt(int log_rounds, SecureRandom random) { + StringBuffer rs = new StringBuffer(); + byte rnd[] = new byte[BCRYPT_SALT_LEN]; + + random.nextBytes(rnd); + + rs.append("$2a$"); + if (log_rounds < 10) + rs.append("0"); + if (log_rounds > 30) { + throw new IllegalArgumentException( + "log_rounds exceeds maximum (30)"); + } + rs.append(Integer.toString(log_rounds)); + rs.append("$"); + rs.append(encode_base64(rnd, rnd.length)); + return rs.toString(); + } + + /** + * Generate a salt for use with the BCrypt.hashpw() method + * @param log_rounds the log2 of the number of rounds of + * hashing to apply - the work factor therefore increases as + * 2**log_rounds. + * @return an encoded salt value + */ + public static String gensalt(int log_rounds) { + return gensalt(log_rounds, new SecureRandom()); + } + + /** + * Generate a salt for use with the BCrypt.hashpw() method, + * selecting a reasonable default for the number of hashing + * rounds to apply + * @return an encoded salt value + */ + public static String gensalt() { + return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS); + } + + /** + * Check that a plaintext password matches a previously hashed + * one + * @param plaintext the plaintext password to verify + * @param hashed the previously-hashed password + * @return true if the passwords match, false otherwise + */ + public static boolean checkpw(String plaintext, String hashed) { + byte hashed_bytes[]; + byte try_bytes[]; + try { + String try_pw = hashpw(plaintext, hashed); + hashed_bytes = hashed.getBytes("UTF-8"); + try_bytes = try_pw.getBytes("UTF-8"); + } catch (UnsupportedEncodingException uee) { + return false; + } + if (hashed_bytes.length != try_bytes.length) + return false; + byte ret = 0; + for (int i = 0; i < try_bytes.length; i++) + ret |= hashed_bytes[i] ^ try_bytes[i]; + return ret == 0; + } +} \ No newline at end of file diff --git a/StorageSim/src/res/Roboter_1.png b/StorageSim/src/res/Roboter_1.png new file mode 100644 index 0000000..0dce4fa Binary files /dev/null and b/StorageSim/src/res/Roboter_1.png differ diff --git a/StorageSim/src/res/Roboter_2.png b/StorageSim/src/res/Roboter_2.png new file mode 100644 index 0000000..d08cfd8 Binary files /dev/null and b/StorageSim/src/res/Roboter_2.png differ diff --git a/StorageSim/src/res/Template.xlsx b/StorageSim/src/res/Template.xlsx new file mode 100644 index 0000000..8346a9a Binary files /dev/null and b/StorageSim/src/res/Template.xlsx differ diff --git a/StorageSim/src/res/palette.png b/StorageSim/src/res/palette.png new file mode 100644 index 0000000..72908b7 Binary files /dev/null and b/StorageSim/src/res/palette.png differ diff --git a/StorageSim/src/res/pixelart/1.png b/StorageSim/src/res/pixelart/1.png new file mode 100644 index 0000000..da56220 Binary files /dev/null and b/StorageSim/src/res/pixelart/1.png differ diff --git a/StorageSim/src/res/pixelart/10.png b/StorageSim/src/res/pixelart/10.png new file mode 100644 index 0000000..2c7f034 Binary files /dev/null and b/StorageSim/src/res/pixelart/10.png differ diff --git a/StorageSim/src/res/pixelart/11.png b/StorageSim/src/res/pixelart/11.png new file mode 100644 index 0000000..de862ff Binary files /dev/null and b/StorageSim/src/res/pixelart/11.png differ diff --git a/StorageSim/src/res/pixelart/12.png b/StorageSim/src/res/pixelart/12.png new file mode 100644 index 0000000..feacb1c Binary files /dev/null and b/StorageSim/src/res/pixelart/12.png differ diff --git a/StorageSim/src/res/pixelart/13.png b/StorageSim/src/res/pixelart/13.png new file mode 100644 index 0000000..090d702 Binary files /dev/null and b/StorageSim/src/res/pixelart/13.png differ diff --git a/StorageSim/src/res/pixelart/14.png b/StorageSim/src/res/pixelart/14.png new file mode 100644 index 0000000..fbdeee5 Binary files /dev/null and b/StorageSim/src/res/pixelart/14.png differ diff --git a/StorageSim/src/res/pixelart/15.png b/StorageSim/src/res/pixelart/15.png new file mode 100644 index 0000000..febeb9d Binary files /dev/null and b/StorageSim/src/res/pixelart/15.png differ diff --git a/StorageSim/src/res/pixelart/16.png b/StorageSim/src/res/pixelart/16.png new file mode 100644 index 0000000..211e8ce Binary files /dev/null and b/StorageSim/src/res/pixelart/16.png differ diff --git a/StorageSim/src/res/pixelart/17.png b/StorageSim/src/res/pixelart/17.png new file mode 100644 index 0000000..69d7304 Binary files /dev/null and b/StorageSim/src/res/pixelart/17.png differ diff --git a/StorageSim/src/res/pixelart/18.png b/StorageSim/src/res/pixelart/18.png new file mode 100644 index 0000000..a541fe3 Binary files /dev/null and b/StorageSim/src/res/pixelart/18.png differ diff --git a/StorageSim/src/res/pixelart/19.png b/StorageSim/src/res/pixelart/19.png new file mode 100644 index 0000000..69196dd Binary files /dev/null and b/StorageSim/src/res/pixelart/19.png differ diff --git a/StorageSim/src/res/pixelart/2.png b/StorageSim/src/res/pixelart/2.png new file mode 100644 index 0000000..bfde7a0 Binary files /dev/null and b/StorageSim/src/res/pixelart/2.png differ diff --git a/StorageSim/src/res/pixelart/20.png b/StorageSim/src/res/pixelart/20.png new file mode 100644 index 0000000..384b117 Binary files /dev/null and b/StorageSim/src/res/pixelart/20.png differ diff --git a/StorageSim/src/res/pixelart/21.png b/StorageSim/src/res/pixelart/21.png new file mode 100644 index 0000000..166c87a Binary files /dev/null and b/StorageSim/src/res/pixelart/21.png differ diff --git a/StorageSim/src/res/pixelart/22.png b/StorageSim/src/res/pixelart/22.png new file mode 100644 index 0000000..aad7ead Binary files /dev/null and b/StorageSim/src/res/pixelart/22.png differ diff --git a/StorageSim/src/res/pixelart/23.png b/StorageSim/src/res/pixelart/23.png new file mode 100644 index 0000000..2f42152 Binary files /dev/null and b/StorageSim/src/res/pixelart/23.png differ diff --git a/StorageSim/src/res/pixelart/24.png b/StorageSim/src/res/pixelart/24.png new file mode 100644 index 0000000..372b412 Binary files /dev/null and b/StorageSim/src/res/pixelart/24.png differ diff --git a/StorageSim/src/res/pixelart/25.png b/StorageSim/src/res/pixelart/25.png new file mode 100644 index 0000000..55d0b53 Binary files /dev/null and b/StorageSim/src/res/pixelart/25.png differ diff --git a/StorageSim/src/res/pixelart/26.png b/StorageSim/src/res/pixelart/26.png new file mode 100644 index 0000000..1cd7f4e Binary files /dev/null and b/StorageSim/src/res/pixelart/26.png differ diff --git a/StorageSim/src/res/pixelart/27.png b/StorageSim/src/res/pixelart/27.png new file mode 100644 index 0000000..0345e55 Binary files /dev/null and b/StorageSim/src/res/pixelart/27.png differ diff --git a/StorageSim/src/res/pixelart/28.png b/StorageSim/src/res/pixelart/28.png new file mode 100644 index 0000000..d978a37 Binary files /dev/null and b/StorageSim/src/res/pixelart/28.png differ diff --git a/StorageSim/src/res/pixelart/29.png b/StorageSim/src/res/pixelart/29.png new file mode 100644 index 0000000..8adbba3 Binary files /dev/null and b/StorageSim/src/res/pixelart/29.png differ diff --git a/StorageSim/src/res/pixelart/3.png b/StorageSim/src/res/pixelart/3.png new file mode 100644 index 0000000..06c1e61 Binary files /dev/null and b/StorageSim/src/res/pixelart/3.png differ diff --git a/StorageSim/src/res/pixelart/30.png b/StorageSim/src/res/pixelart/30.png new file mode 100644 index 0000000..13df259 Binary files /dev/null and b/StorageSim/src/res/pixelart/30.png differ diff --git a/StorageSim/src/res/pixelart/31.png b/StorageSim/src/res/pixelart/31.png new file mode 100644 index 0000000..8583790 Binary files /dev/null and b/StorageSim/src/res/pixelart/31.png differ diff --git a/StorageSim/src/res/pixelart/32.png b/StorageSim/src/res/pixelart/32.png new file mode 100644 index 0000000..1879e10 Binary files /dev/null and b/StorageSim/src/res/pixelart/32.png differ diff --git a/StorageSim/src/res/pixelart/33.png b/StorageSim/src/res/pixelart/33.png new file mode 100644 index 0000000..6388984 Binary files /dev/null and b/StorageSim/src/res/pixelart/33.png differ diff --git a/StorageSim/src/res/pixelart/34.png b/StorageSim/src/res/pixelart/34.png new file mode 100644 index 0000000..a9ea101 Binary files /dev/null and b/StorageSim/src/res/pixelart/34.png differ diff --git a/StorageSim/src/res/pixelart/35.png b/StorageSim/src/res/pixelart/35.png new file mode 100644 index 0000000..a722b65 Binary files /dev/null and b/StorageSim/src/res/pixelart/35.png differ diff --git a/StorageSim/src/res/pixelart/36.png b/StorageSim/src/res/pixelart/36.png new file mode 100644 index 0000000..f3eafa2 Binary files /dev/null and b/StorageSim/src/res/pixelart/36.png differ diff --git a/StorageSim/src/res/pixelart/37.png b/StorageSim/src/res/pixelart/37.png new file mode 100644 index 0000000..0fec0b4 Binary files /dev/null and b/StorageSim/src/res/pixelart/37.png differ diff --git a/StorageSim/src/res/pixelart/38.png b/StorageSim/src/res/pixelart/38.png new file mode 100644 index 0000000..dcba85c Binary files /dev/null and b/StorageSim/src/res/pixelart/38.png differ diff --git a/StorageSim/src/res/pixelart/39.png b/StorageSim/src/res/pixelart/39.png new file mode 100644 index 0000000..bdc0c57 Binary files /dev/null and b/StorageSim/src/res/pixelart/39.png differ diff --git a/StorageSim/src/res/pixelart/4.png b/StorageSim/src/res/pixelart/4.png new file mode 100644 index 0000000..e3bc964 Binary files /dev/null and b/StorageSim/src/res/pixelart/4.png differ diff --git a/StorageSim/src/res/pixelart/40.png b/StorageSim/src/res/pixelart/40.png new file mode 100644 index 0000000..0d20776 Binary files /dev/null and b/StorageSim/src/res/pixelart/40.png differ diff --git a/StorageSim/src/res/pixelart/41.png b/StorageSim/src/res/pixelart/41.png new file mode 100644 index 0000000..cfa8a9a Binary files /dev/null and b/StorageSim/src/res/pixelart/41.png differ diff --git a/StorageSim/src/res/pixelart/42.png b/StorageSim/src/res/pixelart/42.png new file mode 100644 index 0000000..4384555 Binary files /dev/null and b/StorageSim/src/res/pixelart/42.png differ diff --git a/StorageSim/src/res/pixelart/43.png b/StorageSim/src/res/pixelart/43.png new file mode 100644 index 0000000..f7c4c7f Binary files /dev/null and b/StorageSim/src/res/pixelart/43.png differ diff --git a/StorageSim/src/res/pixelart/44.png b/StorageSim/src/res/pixelart/44.png new file mode 100644 index 0000000..5678351 Binary files /dev/null and b/StorageSim/src/res/pixelart/44.png differ diff --git a/StorageSim/src/res/pixelart/45.png b/StorageSim/src/res/pixelart/45.png new file mode 100644 index 0000000..2c813d7 Binary files /dev/null and b/StorageSim/src/res/pixelart/45.png differ diff --git a/StorageSim/src/res/pixelart/46.png b/StorageSim/src/res/pixelart/46.png new file mode 100644 index 0000000..6674bfd Binary files /dev/null and b/StorageSim/src/res/pixelart/46.png differ diff --git a/StorageSim/src/res/pixelart/47.png b/StorageSim/src/res/pixelart/47.png new file mode 100644 index 0000000..7eaac0d Binary files /dev/null and b/StorageSim/src/res/pixelart/47.png differ diff --git a/StorageSim/src/res/pixelart/48.png b/StorageSim/src/res/pixelart/48.png new file mode 100644 index 0000000..238d81b Binary files /dev/null and b/StorageSim/src/res/pixelart/48.png differ diff --git a/StorageSim/src/res/pixelart/49.png b/StorageSim/src/res/pixelart/49.png new file mode 100644 index 0000000..24d7dd1 Binary files /dev/null and b/StorageSim/src/res/pixelart/49.png differ diff --git a/StorageSim/src/res/pixelart/5.png b/StorageSim/src/res/pixelart/5.png new file mode 100644 index 0000000..1fa61f6 Binary files /dev/null and b/StorageSim/src/res/pixelart/5.png differ diff --git a/StorageSim/src/res/pixelart/50.png b/StorageSim/src/res/pixelart/50.png new file mode 100644 index 0000000..a56ca0a Binary files /dev/null and b/StorageSim/src/res/pixelart/50.png differ diff --git a/StorageSim/src/res/pixelart/6.png b/StorageSim/src/res/pixelart/6.png new file mode 100644 index 0000000..a38bfbc Binary files /dev/null and b/StorageSim/src/res/pixelart/6.png differ diff --git a/StorageSim/src/res/pixelart/7.png b/StorageSim/src/res/pixelart/7.png new file mode 100644 index 0000000..832c77f Binary files /dev/null and b/StorageSim/src/res/pixelart/7.png differ diff --git a/StorageSim/src/res/pixelart/8.png b/StorageSim/src/res/pixelart/8.png new file mode 100644 index 0000000..0fca22d Binary files /dev/null and b/StorageSim/src/res/pixelart/8.png differ diff --git a/StorageSim/src/res/pixelart/9.png b/StorageSim/src/res/pixelart/9.png new file mode 100644 index 0000000..833498a Binary files /dev/null and b/StorageSim/src/res/pixelart/9.png differ diff --git a/StorageSim/src/res/store.png b/StorageSim/src/res/store.png new file mode 100644 index 0000000..fc3ec09 Binary files /dev/null and b/StorageSim/src/res/store.png differ diff --git a/StorageSim/src/storagesim/BWLHelper.java b/StorageSim/src/storagesim/BWLHelper.java new file mode 100644 index 0000000..05dc875 --- /dev/null +++ b/StorageSim/src/storagesim/BWLHelper.java @@ -0,0 +1,245 @@ +package storagesim; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.HashMap; + +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import lib.SQLConnection; + +public class BWLHelper { + + public static final String PATH = System.getProperty("user.home") + "/Desktop/Bestellungen/"; + + public static void sys1(SQLConnection db, LocalDate date, int produkt_ID, float ZinsenProzent) { + HashMap ProduktInformationen = db.queryToMap("SELECT Name, Lieferzeit, Einkaufspreis, Verkaufspreis FROM t_artikel WHERE ID = '" + produkt_ID + "'").get(0); + + int lieferzeit = Integer.parseInt(ProduktInformationen.get("Lieferzeit")); + ArrayList> stat = db.queryToMap("SELECT Menge FROM t_verkaufszahlen WHERE f_Artikel_ID = '" + produkt_ID + "' ORDER BY Woche DESC LIMIT 1"); + int statMenge = 1; + if (stat.size() > 0) { + statMenge = Integer.parseInt(stat.get(0).get("Menge")); + } + LocalDate ankunft = date.plusDays(lieferzeit); + + int jahresBedarf = 48 * statMenge; + int menge = gesamtMenge(db, produkt_ID); + float bestellKosten = (float) (menge * Float.parseFloat(ProduktInformationen.get("Einkaufspreis")) + 8.3); + float EinnahmenPMenge = Float.parseFloat(ProduktInformationen.get("Verkaufspreis")); + float lagerWert = dWert(db) / Integer.parseInt(db.queryToMap("SELECT Woche FROM t_lagerstatistik ORDER BY Woche DESC LIMIT 1").get(0).get("Woche")); + float lagerKostenSatz, lagerKosten, lagerHaltungsKostenSatz, StromPreisLager; + int sicherheitsBestand, meldeBestand; + + ArrayList> elemente = db.queryToMap("SELECT f_Artikel_ID, Gekühlt FROM t_lager INNER JOIN t_artikel ON t_lager.f_Artikel_ID = t_artikel.ID"); + + int gekuehlteProdukte = 0; + int ungekuehlteProdukte = 0; + + for (HashMap elem : elemente) { + if (elem.get("Gekühlt").equals("1")) { + gekuehlteProdukte++; + } else { + ungekuehlteProdukte++; + } + } + + StromPreisLager = gekuehlteProdukte * 85.68f + ungekuehlteProdukte * 1.71f; + + lagerKosten = 80 * 4 + 360 * 6 + StromPreisLager; + + lagerKostenSatz = lagerKosten / lagerWert * 100; + + lagerHaltungsKostenSatz = lagerKostenSatz + ZinsenProzent; + + int bestellMenge = (int) Math.sqrt((2 * jahresBedarf * bestellKosten) / (EinnahmenPMenge * lagerHaltungsKostenSatz)); + + sicherheitsBestand = statMenge * lieferzeit; + + meldeBestand = statMenge * lieferzeit + sicherheitsBestand; + + if (menge <= meldeBestand) { + System.out.printf("Es wurden %d %s nachbestellt.\n", bestellMenge, ProduktInformationen.get("Name")); + db.execute("INSERT INTO t_bestellungen SET f_Artikel_ID = " + produkt_ID + + ", Menge = " + bestellMenge + + ", Ankunftsdatum = ('" + ankunft.toString() + "')"); + } + } + + public static void sys2(SQLConnection db, LocalDate date, int produkt_ID, int bestellIntervall, int maxMenge, int ZinsenProzent, boolean sBestand) { + HashMap ProduktInformationen = db.queryToMap("SELECT Name, Lieferzeit FROM t_artikel WHERE ID = '" + produkt_ID + "'").get(0); + + int lieferzeit = Integer.parseInt(ProduktInformationen.get("Lieferzeit")); + LocalDate ankunft = date.plusDays(lieferzeit); + + LocalDate nächsteBestellung = date; + ArrayList> artikel = db.queryToMap("SELECT Ankunft FROM t_lager WHERE f_Artikel_ID = '" + produkt_ID + "'"); + if (artikel.size() > 0) { + nächsteBestellung = LocalDate.parse(artikel.get(0).get("Ankunft")).minusDays(lieferzeit).plusDays(bestellIntervall); + } + + int pMenge = gesamtMenge(db, produkt_ID); + + if (pMenge < maxMenge) { + if (sBestand == true) { + int sicherheitsBestand, meldeBestand; + + int bestellMenge = maxMenge - pMenge; + + if ((bestellMenge + pMenge) > maxMenge) { + bestellMenge = bestellMenge - ((bestellMenge + pMenge) - maxMenge); + } + + ArrayList> stat = db.queryToMap("SELECT Menge FROM t_verkaufszahlen WHERE f_Artikel_ID = '" + produkt_ID + "' ORDER BY Woche DESC LIMIT 1"); + int statMenge = 1; + if (stat.size() > 0) { + statMenge = Integer.parseInt(stat.get(0).get("Menge")); + } + + sicherheitsBestand = statMenge * lieferzeit; + + meldeBestand = statMenge * lieferzeit + sicherheitsBestand; + + if (pMenge <= meldeBestand) { + System.out.printf("Es wurden %d %s nachbestellt.\n", bestellMenge, ProduktInformationen.get("Name")); + + db.execute("INSERT INTO t_bestellungen SET f_Artikel_ID = " + produkt_ID + + ", Menge = " + bestellMenge + + ", Ankunftsdatum = ('" + ankunft.toString() + "')"); + } else if (date.isEqual(nächsteBestellung) || date.isAfter(nächsteBestellung)) { + System.out.printf("Es wurden %d %s nachbestellt.\n", bestellMenge, ProduktInformationen.get("Name")); + + db.execute("INSERT INTO t_bestellungen SET f_Artikel_ID = " + produkt_ID + + ", Menge = " + bestellMenge + + ", Ankunftsdatum = ('" + ankunft.toString() + "')"); + } + } else { + int bestellMenge = maxMenge - pMenge; + + if (date.isEqual(nächsteBestellung) || date.isAfter(nächsteBestellung)) { + System.out.printf("Es wurden %d %s nachbestellt.\n", bestellMenge, ProduktInformationen.get("Name")); + + db.execute("INSERT INTO t_bestellungen SET f_Artikel_ID = " + produkt_ID + + ", Menge = " + bestellMenge + + ", Ankunftsdatum = ('" + ankunft.toString() + "')"); + } + } + } + } + + public static void Bestellungen(SQLConnection db, LocalDate date, ArrayList> bestellungen, String Name) { + // name of the excel files + String templateFileName = StorageMap.class.getResource("/res/Template.xlsx").getFile(); + String outputFileName = PATH + "/Out_" + date.toString() + "_" + System.currentTimeMillis() % 1000 + ".xlsx"; + + XSSFWorkbook wb; + try { + InputStream ExcelFileToRead = new FileInputStream(templateFileName); + wb = new XSSFWorkbook(ExcelFileToRead); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return; + } catch (IOException e) { + e.printStackTrace(); + return; + } + + XSSFSheet sheet = wb.getSheetAt(0); + + sheet.getRow(11).getCell(2).setCellValue(date.toString()); + sheet.getRow(13).getCell(2).setCellValue(Name); + + int offset = 5; + + for (int Reihe = 0; Reihe < 5; Reihe++) { + if (Reihe >= bestellungen.size()) { + sheet.getRow(Reihe + offset).getCell(1).setCellValue(""); + sheet.getRow(Reihe + offset).getCell(2).setCellValue(""); + sheet.getRow(Reihe + offset).getCell(3).setCellValue(""); + sheet.getRow(Reihe + offset).getCell(4).setCellValue(""); + sheet.getRow(Reihe + offset).getCell(5).setCellValue(""); + sheet.getRow(Reihe + offset).getCell(6).setCellValue(""); + } else { + HashMap produkt = bestellungen.get(0); + + String Hersteller = produkt.get("Marke"); + + int ProduktID = Integer.parseInt(produkt.get("f_Artikel_ID")); + String Beschreibung = produkt.get("Name"); + int Menge = Integer.parseInt(produkt.get("Menge")); + float Stückpreis = Float.parseFloat(produkt.get("Einkaufspreis")); + float Gesamtpreis = Stückpreis * Menge; + + sheet.getRow(Reihe + offset).getCell(1).setCellValue(ProduktID); + sheet.getRow(Reihe + offset).getCell(2).setCellValue(Hersteller); + sheet.getRow(Reihe + offset).getCell(3).setCellValue(Beschreibung); + sheet.getRow(Reihe + offset).getCell(4).setCellValue(Menge); + sheet.getRow(Reihe + offset).getCell(5).setCellValue(String.format("%.2f", Stückpreis)); + sheet.getRow(Reihe + offset).getCell(6).setCellValue(String.format("%.2f", Gesamtpreis)); + + bestellungen.remove(produkt); + } + } + + try { + File outputFile = new File(outputFileName); + outputFile.getParentFile().mkdirs(); + outputFile.createNewFile(); + FileOutputStream fileOut = new FileOutputStream(outputFile); + + // write this workbook to an OutputStream. + wb.write(fileOut); + wb.close(); + fileOut.flush(); + fileOut.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void lagerStatistik(SQLConnection db, int Woche) { + int eWoche = Woche + 48; + + db.execute("DELETE FROM t_lagerstatistik WHERE Woche = " + eWoche); + db.execute("INSERT INTO t_lagerstatistik SET Woche = " + eWoche + ", Wert = " + gMenge(db)); + } + + public static float dWert(SQLConnection db) { + float wert = 0; + ArrayList> Wert = db.queryToMap("SELECT * FROM `t_lagerstatistik` ORDER BY `t_lagerstatistik`.`Woche` DESC LIMIT 48"); + for (HashMap row : Wert) { + wert += Float.parseFloat(row.get("Wert")); + } + return wert; + } + + public static int gesamtMenge(SQLConnection db, int produkt_ID) { + ArrayList> storage = db.queryToMap("SELECT Menge FROM t_lager WHERE f_Artikel_ID = " + produkt_ID); + storage.addAll(db.queryToMap("SELECT Menge FROM t_bestellungen WHERE f_Artikel_ID = " + produkt_ID)); + + int gesamt = 0; + for (HashMap row : storage) { + gesamt += Integer.parseInt(row.get("Menge")); + } + return gesamt; + } + + public static float gMenge(SQLConnection db) { + float menge = 0; + ArrayList> produkte = db.queryToMap( + "SELECT Verkaufspreis, Menge FROM t_lager INNER JOIN t_artikel ON t_lager.f_Artikel_ID = t_artikel.ID"); + for (int i = 0; i < produkte.size(); i++) { + menge = menge + (Float.parseFloat(produkte.get(i).get("Verkaufspreis")) * Integer.parseInt(produkte.get(i).get("Menge"))); + } + return menge; + } +} diff --git a/StorageSim/src/storagesim/MapPanel.java b/StorageSim/src/storagesim/MapPanel.java new file mode 100644 index 0000000..3d84f19 --- /dev/null +++ b/StorageSim/src/storagesim/MapPanel.java @@ -0,0 +1,206 @@ +package storagesim; + +import java.awt.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; + +import javax.swing.JPanel; + +/** + * Draws a {@link StorageMap} inside a {@link javax.swing.JPanel} + * + * @author Manuel + */ +public class MapPanel extends JPanel { + private static final long serialVersionUID = 1L; + + double scale; + double translateX, translateY; + + Point prevMouse; + + StorageWindow parent; + + StorageMap map; + + public MapPanel(StorageWindow parent) { + super(); + + this.parent = parent; + + this.scale = 1.0; + this.translateX = 0.0; + this.translateY = 0.0; + + this.setSize(720, 480); + + map = new StorageMap(24, 15); + map.updateMap(parent.db); + + this.setPreferredSize(this.getSize()); + this.setBackground(Color.MAGENTA); + + Controls c = new Controls(); + this.addMouseListener(c); + this.addMouseMotionListener(c); + this.addMouseWheelListener(c); + + this.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + super.componentResized(e); + applyTransform(0, 0, 0, 0, 0); + } + }); + } + + /** + * Draws the map inside the panel + */ + @Override + public void paint(Graphics g) { + super.paint(g); + + Graphics2D g2 = (Graphics2D) g; + + g2.translate(this.translateX, this.translateY); + g2.scale(this.scale, this.scale); + + g2.drawImage(this.map.img, 0, 0, null); + + if (this.map.selectedTile >= 0) { + int selectedX = (this.map.selectedTile % this.map.tileColumns) * this.map.tileSize; + int selectedY = (this.map.selectedTile / this.map.tileColumns) * this.map.tileSize; + + g2.setColor(Color.YELLOW); + g2.drawRect(selectedX, selectedY, this.map.tileSize, this.map.tileSize); + } + + // TODO bot entities + } + + /** + * Reset the view + */ + public void resetView() { + this.scale = 1.0; + this.translateX = 0.0; + this.translateY = 0.0; + + this.applyTransform(0, 0, 0, 0, 0); + } + + /** + * PURE FUCKING MAGIC; DON'T TOUCH! + */ + private void applyTransform(double dTranslateX, double dTranslateY, double dScale, int mouseX, int mouseY) { + this.scale += dScale; + + double scaleMinX = (double)getWidth() / map.img.getWidth(); + double scaleMinY = (double)getHeight() / map.img.getHeight(); + double scaleMin = scaleMinX < scaleMinY ? scaleMinY : scaleMinX; + + double scaleMax = 24; + + // limit scale to image limits + if(this.scale < scaleMin) { + dScale = (this.scale - dScale) % scaleMin; + this.scale = scaleMin; + } else if (this.scale > scaleMax) { + dScale -= (this.scale - scaleMax); + this.scale = scaleMax; + } + + // adjust position according to zoom: (new pos - prev pos) * scale + this.translateX += (((mouseX - this.translateX) / this.scale) - + ((mouseX - this.translateX) / (this.scale - dScale))) * this.scale; + this.translateY += (((mouseY - this.translateY) / this.scale) - + ((mouseY - this.translateY) / (this.scale - dScale))) * this.scale; + + this.translateX += dTranslateX; + this.translateY += dTranslateY; + + // limit translation to image borders + if (this.translateX > 0) { + this.translateX = 0; + } else if (this.translateX < (getWidth() - (map.img.getWidth() * this.scale))) { + this.translateX = getWidth() - (map.img.getWidth() * this.scale); + } + if (this.translateY > 0) { + this.translateY = 0; + } else if (this.translateY < (getHeight() - (map.img.getHeight() * this.scale))) { + this.translateY = getHeight() - (map.img.getHeight() * this.scale); + } + } + + /** + * Holds the interaction controls + */ + private class Controls extends MouseAdapter { + /** + * Updates mouse position on click + * + * @param e mouse event with coordinates + */ + @Override + public void mousePressed(MouseEvent e) { + prevMouse = e.getPoint(); + repaint(); + } + + /** + * Listens to mouse drags to transform the map + * + * @param e mouse event with coordinates + */ + @Override + public void mouseDragged(MouseEvent e) { + if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK) { + applyTransform( + e.getX() - prevMouse.getX(), + e.getY() - prevMouse.getY(), + 0.0, e.getX(), e.getY()); + + prevMouse = e.getPoint(); + repaint(); + } + } + + /** + * Listens to scroll to scale the map + * + * @param e mouse event with scroll information + */ + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { + double scaleChange = e.getPreciseWheelRotation() * (scale / -16.0); + + applyTransform(0.0, 0.0, scaleChange, e.getX(), e.getY()); + + repaint(); + } + } + + /** + * Listens to mouse clicks to change which tile is in focus + * + * @param e mouse event with position information + */ + public void mouseClicked(MouseEvent e) { + double xOnMap = (e.getX() - translateX) / scale; + double yOnMap = (e.getY() - translateY) / scale; + + int xTile = (int) (xOnMap / map.tileSize); + int yTile = (int) (yOnMap / map.tileSize); + + map.selectedTile = yTile * map.tileColumns + xTile; + parent.updateSidebar(parent.db); + + repaint(); + } + } +} diff --git a/StorageSim/src/storagesim/Simulation.java b/StorageSim/src/storagesim/Simulation.java new file mode 100644 index 0000000..a9e4476 --- /dev/null +++ b/StorageSim/src/storagesim/Simulation.java @@ -0,0 +1,391 @@ +package storagesim; + +import java.time.LocalDate; +import java.time.temporal.IsoFields; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Random; +import java.util.stream.Collectors; + +import lib.OpenSimplexNoise; +import lib.SQLConnection; + +/** + * Runs a loop with a strict interval to simulate time passing + * + * @author Manuel + */ + +public class Simulation { + + boolean running; + + public LocalDate currentTime; + + OpenSimplexNoise noise; + + final float STEPS_PER_SECOND = 1 / 30f; + final int MAX_STEPS = 1; + final int TOLERANCE = 200; + + public Simulation() { + this.running = false; + + this.currentTime = LocalDate.now(); + //this.currentTime = LocalDate.parse("2020-02-06"); + + this.noise = new OpenSimplexNoise(); + } + + /** + * Starts and contains the loop + * + * @author Manuel + */ + public void run(LocalDate time) { + // initialise timing values + double interval = 1000f / (STEPS_PER_SECOND); + double previousMillis = System.currentTimeMillis() - interval; + + this.currentTime = time; + + do { + // update current time + double currentMillis = System.currentTimeMillis(); + double deltaMillis = currentMillis - previousMillis; + + // run code if enough time has passed + int steps = 0; + while (deltaMillis >= interval && steps < MAX_STEPS) { + // -------------------- + // this is the code that is executed in the specified interval + SQLConnection db = new SQLConnection(); + System.out.println("Date: " + this.currentTime.toString()); + simulateSales(db); + sellItems(db); + disposeItems(db); + receiveOrders(db); + sortStorage(db); + checkStorage(db); + sortStatistics(db); + db.close(); + this.currentTime.plusDays(1); + // this.running = false; + // -------------------- + steps++; + deltaMillis -= interval; + } + if (steps > 0) { + // only change time if any code was executed + previousMillis = currentMillis; + } + } while (this.running); + } + + /** + * Removes all Items sold in the last time frame + * + * @author Johann + */ + public void sellItems(SQLConnection db) { + // Liste der verkauften waren wird erstellt + ArrayList> Verkauft = db.queryToMap( + "SELECT * FROM t_statistik WHERE `Woche` = " + this.currentTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR)); + int MengePalette; // Zwischenspeicher für die Menge der Items auf einer Palette + + for (HashMap Artikel : Verkauft) { + int VerkaufteID = Integer.parseInt(Artikel.get("f_Artikel_ID")); // ID des momentan Bearbeiteten Produktes + + // Alle Paletten werden zwischengespeichert + ArrayList> Paletten = db.queryToMap("SELECT * FROM t_mindesthaltbarkeit WHERE `f_ProduktID` = " + VerkaufteID + " ORDER BY Menge"); + + int Zähler = 0; // in einer späteren for() schleife wird ein weiterer Zähler benötigt + + for (int VerkaufteMenge = Integer.parseInt(Artikel.get("Menge")); VerkaufteMenge > 0; Zähler++) { + if (Paletten.size() > Zähler) { + // Der Rest auf einer Palette an Items + MengePalette = Integer.parseInt(Paletten.get(Zähler).get("Menge")); + + if (VerkaufteMenge <= MengePalette) // Wenn mehr auf der einen Palette ist als verkauft wurde + { + MengePalette -= VerkaufteMenge; + VerkaufteMenge = 0; // Alles wurde entfernt und die Palette wurde neu beschrieben + } else // Wenn mehr verkauft wurde als auf der einen Palette war + { + VerkaufteMenge -= MengePalette; + // Die Palette wird gelert, und die Variable neu beschrieben, es wird die + // nächste Palette zu rate gezogen + MengePalette = 0; + } + db.execute("UPDATE t_mindesthaltbarkeit SET `Menge` = " + MengePalette + + " WHERE t_mindesthaltbarkeit.`ID` = " + Paletten.get(Zähler).get("ID")); + db.execute("UPDATE t_lager SET `Menge` = " + MengePalette + + " WHERE t_lager.`Paletten_ID` = " + Paletten.get(Zähler).get("ID")); + } else { + break; + } + } + } + } + + /** + * Disposes of all items that have expired + * + * @author Johann + */ + public void disposeItems(SQLConnection db) { + ArrayList> Waren = db.queryToMap("SELECT t_mindesthaltbarkeit.ID, t_mindesthaltbarkeit.Haltbarkeit, t_mindesthaltbarkeit.Menge, t_artikel.Name FROM t_mindesthaltbarkeit INNER JOIN t_artikel ON t_mindesthaltbarkeit.f_ProduktID = t_artikel.ID"); + // Waren liste wird erstellt + + // Nach Produkten die verworfen werden müssen suchen + + for (HashMap Ware : Waren) { + LocalDate Datum2 = LocalDate.parse(Ware.get("Haltbarkeit")); // Das DAtum des wahrscheinlich nichtmehr + // Haltbaren abfragen + + // Compare + if (this.currentTime.isAfter(Datum2)) // Abfagen ob das Item abgelaufen ist + { + int ID = Integer.parseInt(Ware.get("ID")); // Speichern welches Produkt abgelaufen ist + + System.out.printf("Eine Pallette mit %s %s ist abgelaufen.\n", Ware.get("Menge"), Ware.get("Name")); + + db.execute("UPDATE t_mindesthaltbarkeit SET `Menge` = '0' WHERE t_mindesthaltbarkeit.`ID` = " + + ID); // produkt verwerfen + db.execute("UPDATE t_lager SET `Menge` = '0' WHERE t_lager.`Paletten_ID` = " + + ID); + } + } + + // Leere Paletten wegwerfen + + Waren = db.queryToMap("SELECT * FROM t_mindesthaltbarkeit"); // Liste mit allen Palette wird aufgerufen + + for (HashMap Ware : Waren) { + if (Integer.parseInt(Ware.get("Menge")) == 0) // Wenn eine Palette leer ist + { + db.execute("DELETE FROM t_mindesthaltbarkeit WHERE t_mindesthaltbarkeit.`ID` = " + Ware.get("ID")); // Palette + // wir + // geleert + } + } + + // Leere Paletten in der Haupttabelle werden verworfen + + Waren = db.queryToMap("SELECT * FROM t_lager"); // Liste der Waren in der Haupttabelle wird erstellt + + for (HashMap Ware : Waren) { + if (Integer.parseInt(Ware.get("Menge")) == 0) // Leere Paletten werden gesucht + { + // leere Palette wird gelöscht + db.execute("DELETE FROM t_lager WHERE t_lager.`Lagerplatz` = " + Ware.get("Lagerplatz")); + } + } + } + + /** + * Receive orders and puts them into storage + * + * @author Johann, Manuel + */ + public void receiveOrders(SQLConnection db) { + ArrayList> Angekommen = db.queryToMap( + "SELECT t_bestellungen.ID, f_Artikel_ID, Einkaufspreis, Ankunftsdatum, Menge, Marke, Name FROM t_bestellungen " + + "INNER JOIN t_artikel ON t_bestellungen.f_Artikel_ID = t_artikel.ID " + + "WHERE Ankunftsdatum <= ('" + this.currentTime.toString() + "')"); + ArrayList> Artikel = db + .queryToMap("SELECT ID, `MHK in Tagen`, Anzahl_pro_Palette FROM t_artikel"); + ArrayList> Haltbarkeit; + + LocalDate HaltbarBis; + int MHKinTagen; + + for (HashMap row : Angekommen) { + int Artikel_ID = Integer.parseInt(row.get("f_Artikel_ID")); + + MHKinTagen = Integer.parseInt(Artikel.get(Artikel_ID - 1).get("MHK in Tagen")); + if (MHKinTagen >= 0) { + HaltbarBis = this.currentTime.plusDays(MHKinTagen); + } else { + HaltbarBis = LocalDate.parse("9999-12-31"); + } + + int PalettenMenge = Integer.parseInt(Artikel.get(Artikel_ID - 1).get("Anzahl_pro_Palette")); + int BestellMenge = Integer.parseInt(row.get("Menge")); + + while (BestellMenge > 0) { + int Menge = BestellMenge > PalettenMenge ? PalettenMenge : BestellMenge; + BestellMenge -= Menge; + + db.execute("INSERT INTO t_mindesthaltbarkeit SET f_ProduktID = " + row.get("f_Artikel_ID") + + ", Haltbarkeit = ('" + HaltbarBis.toString() + "')" + ", Menge = " + Menge); + + Haltbarkeit = db.queryToMap("SELECT ID, f_ProduktID, Haltbarkeit, Menge FROM t_mindesthaltbarkeit"); + String palettenID = Haltbarkeit.get(Haltbarkeit.size()-1).get("ID") ; + int lagerplatz = findStorageSpace(db); + + db.execute("INSERT INTO t_lager SET Lagerplatz = " + lagerplatz + ", Paletten_ID = " + palettenID + ", f_Artikel_ID = " + + row.get("f_Artikel_ID") + ", Ankunft = ('" + row.get("Ankunftsdatum") + "')" + ", Menge = " + + Menge); + } + + db.execute("DELETE FROM t_bestellungen WHERE ID = " + row.get("ID")); + } + + while (Angekommen.size() > 0) { + BWLHelper.Bestellungen(db, this.currentTime, Angekommen, "Pascal"); + } + } + + /** + * Goes through all available storage locations and finds the first empty in + * line + * + * @author Manuel + */ + public int findStorageSpace(SQLConnection db) { + ArrayList> Lagerplätze = db.queryToMap("SELECT Lagerplatz FROM t_lager"); + ArrayList BelegteLagerplätze = new ArrayList<>( + Lagerplätze.stream().filter((map) -> map.containsKey("Lagerplatz")) + .map(map -> Integer.parseInt(map.get("Lagerplatz"))).collect(Collectors.toList())); + BelegteLagerplätze.sort((a, b) -> Integer.compare(a, b)); + int val = 1; + for (int i = 0; i < BelegteLagerplätze.size(); i++) { + if (val < BelegteLagerplätze.get(i)) { + break; + } else { + val = BelegteLagerplätze.get(i) + 1; + } + } + return val; + } + + /** + * Sorts storage to group products by type and removes gaps + * + * @author Johann + */ + public void sortStorage(SQLConnection db) { + ArrayList> products = db.queryToMap("SELECT ID FROM t_artikel"); + int Lagerplatz = 1; + + ArrayList> Waren = db.queryToMap("SELECT * FROM t_lager"); + ArrayList> Waren_unverändert = db.queryToMap("SELECT * FROM t_lager"); + String[][] Waren_sortiert = new String[Waren.size()][5]; + + for (HashMap product : products) { + int productID = Integer.parseInt(product.get("ID")); + + Waren = db.queryToMap("SELECT * FROM t_lager WHERE f_Artikel_ID = " + productID); + + if (Waren.size() != 0) { + for (HashMap Ware : Waren) { + Waren_sortiert[Lagerplatz - 1][0] = Integer.toString(Lagerplatz); + Waren_sortiert[Lagerplatz - 1][1] = Ware.get("Paletten_ID"); + Waren_sortiert[Lagerplatz - 1][2] = Ware.get("f_Artikel_ID"); + Waren_sortiert[Lagerplatz - 1][3] = Ware.get("Ankunft"); + Waren_sortiert[Lagerplatz - 1][4] = Ware.get("Menge"); + Lagerplatz++; + } + } + } + + for (int u = 0; u <= Waren_sortiert.length - 1; u++) { + db.execute("UPDATE `t_lager` SET `Lagerplatz` = " + Waren_sortiert[u][0] + ", Paletten_ID = " + Waren_sortiert[u][1] + ", `f_Artikel_ID` = " + + Waren_sortiert[u][2] + ", `Ankunft` = ('" + Waren_sortiert[u][3] + "')" + ", `Menge` = " + + Waren_sortiert[u][4] + " WHERE `t_lager`.`Lagerplatz` = " + + Waren_unverändert.get(u).get("Lagerplatz")); + } + + System.out.println("Lager wurde sortiert."); + } + + /** + * Check if items have to be restocked and order them accordingly + * + * @author Pascal + */ + public void checkStorage(SQLConnection db) { + ArrayList> produkte = db.queryToMap("SELECT * FROM t_artikel"); + for (HashMap produkt : produkte) { + int produktID = Integer.parseInt(produkt.get("ID")); + + int sollbestand = Integer.parseInt(produkt.get("Sollbestand")); + + int ZinsenProzent = 8; + + if (sollbestand > 0) { + boolean sicherheitsbestand = produkt.get("Sicherheitsbestand") == "1"; + + BWLHelper.sys2(db, this.currentTime, produktID, 7, sollbestand, ZinsenProzent, sicherheitsbestand); + } else { + BWLHelper.sys1(db, this.currentTime, produktID, ZinsenProzent); + } + } + + BWLHelper.lagerStatistik(db, this.currentTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR)); + } + + /** + * Summarises sales statistics in extra table + * + * @author Johann + */ + public void sortStatistics(SQLConnection db) { + ArrayList> products = db.queryToMap("SELECT ID FROM t_artikel"); + ArrayList> Verkaufszahlen; + int KWoche = currentTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); + int Verkauft; + + db.execute("TRUNCATE t_verkaufszahlen"); + + for(int n = 1; n < KWoche; n++) + { + Verkaufszahlen = db.queryToMap("SELECT * FROM `t_statistik` WHERE `Woche` = " + n); + if(Verkaufszahlen.size() > 0) + { + for (HashMap product : products) { + int productID = Integer.parseInt(product.get("ID")); + + Verkauft = 0; + + Verkaufszahlen = db.queryToMap("SELECT * FROM `t_statistik` WHERE `f_Artikel_ID` = " + productID + " AND `Woche` = " + n); + if(Verkaufszahlen.size() > 0) + { + for(int u = 0; u < Verkaufszahlen.size(); u++) + { + Verkauft += Integer.parseInt(Verkaufszahlen.get(u).get("Menge")); + } + db.execute("INSERT INTO `t_verkaufszahlen` (`ID`, `f_Artikel_ID`, `Woche`, `Menge`, `Verkaufspreis`) VALUES (NULL, '" + productID + "', '" + n + "', '" + Verkauft + "', '" + Verkaufszahlen.get(0).get("Verkaufspreis") + "')"); + } + } + } + } + } + + /** + * Simulate sales through random noise + * + * @author Manuel + */ + public void simulateSales(SQLConnection db) { + ArrayList> products = db.queryToMap("SELECT ID, Verkaufspreis, Anzahl_pro_Palette FROM t_artikel"); + Random r = new Random(); + + for (HashMap product : products) { + int productID = Integer.parseInt(product.get("ID")); + int variance = Integer.parseInt(product.get("Anzahl_pro_Palette")); + + double stepSize = 52f * (r.nextDouble() + 0.00001) * 4; + double val = (1 + this.noise.eval(productID * 100, this.currentTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR) / stepSize)) / 20.0; + int sales = (int)(val * variance) + 1; + + //TODO somewhere we should check if we have enough of a product in storage + + db.execute("INSERT INTO t_statistik SET f_Artikel_ID = " + productID + + ", Woche = " + this.currentTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR) + + ", Menge = " + sales + + ", Verkaufspreis = " + product.get("Verkaufspreis")); + } + } +} diff --git a/StorageSim/src/storagesim/StorageMap.java b/StorageSim/src/storagesim/StorageMap.java new file mode 100644 index 0000000..92bca24 --- /dev/null +++ b/StorageSim/src/storagesim/StorageMap.java @@ -0,0 +1,150 @@ +package storagesim; + +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import javax.imageio.ImageIO; + +import lib.SQLConnection; + +public class StorageMap { + public static BufferedImage STORE_TILE = null; + public static BufferedImage PALETTE_TILE = null; + public static HashMap PRODUCT_TILES = null; + + int tileSize = 15; + int tileColumns, tileRows; + + int selectedTile; + + private ArrayList tiles; + + /** + * Stores the drawn map as a single image for caching purposes + */ + BufferedImage img; + + public StorageMap(int tileColumns, int tileRows) { + this.tileColumns = tileColumns; + this.tileRows = tileRows; + + this.selectedTile = -1; + + this.tiles = new ArrayList<>(Arrays.asList(new Tile[this.tileColumns * this.tileRows])); + + // fill the map with tile objects + for (int x = 0; x < this.tileColumns; x++) { + for (int y = 0; y < this.tileRows; y++) { + this.setTile(x, y, new Tile()); + } + } + + this.img = new BufferedImage(this.tileColumns * this.tileSize, this.tileRows * this.tileSize, + BufferedImage.TYPE_INT_RGB); + + // preload the tile images + try { + if (STORE_TILE == null) { + STORE_TILE = ImageIO.read(StorageMap.class.getResource("/res/store.png")); + } + if (PALETTE_TILE == null) { + PALETTE_TILE = ImageIO.read(StorageMap.class.getResource("/res/palette.png")); + } + if (PRODUCT_TILES == null) { + PRODUCT_TILES = new HashMap<>(); + File[] ls = new File(StorageMap.class.getResource("/res/pixelart/").getFile()).listFiles(); + for (File f : ls) { + if (f.isFile()) { + if (f.getName().endsWith(".png")) { + try { + BufferedImage img = ImageIO.read(f); + PRODUCT_TILES.put(Integer.parseInt(f.getName().replace(".png", "")), img); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Draws the tiles onto the image + */ + public void drawMap() { + this.img = new BufferedImage(this.tileColumns * this.tileSize, this.tileRows * this.tileSize, + BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = this.img.createGraphics(); + for (int x = 0; x < this.tileColumns; x++) { + for (int y = 0; y < this.tileRows; y++) { + BufferedImage[] textures = this.getTile(x, y).getTextures(x, y, this); + for (BufferedImage texture : textures) { + g2.drawImage(texture, x * this.tileSize, y * this.tileSize, this.tileSize, this.tileSize, null); + } + } + } + g2.dispose(); + } + + /** + * Synchronises the tile content with the database + */ + public void updateMap(SQLConnection db) { + for (int i = 0; i < this.tiles.size(); i++) { + ArrayList> product = db.queryToMap("SELECT f_Artikel_ID FROM t_lager WHERE Lagerplatz = " + (i + 1)); + if (product.size() == 0) { + this.tiles.get(i).filled = false; + this.tiles.get(i).product_id = 0; // standartwert + } else { + this.tiles.get(i).filled = true; + this.tiles.get(i).product_id = Integer.parseInt(product.get(0).get("f_Artikel_ID")); + } + } + + this.drawMap(); + } + + private void setTile(int x, int y, Tile t) { + this.tiles.set(y * this.tileColumns + x, t); + } + + public Tile getTile(int x, int y) { + return this.tiles.get(y * this.tileColumns + x); + } + + /** + * Stores the relevant information of all tiles in objects + * + * @author Manuel + */ + private class Tile { + + public boolean filled; + public int product_id; + + private Tile() { + this.filled = false; + this.product_id = 0; + } + + public BufferedImage[] getTextures(int x, int y, StorageMap map) { + if (this.filled) { + if (this.product_id > 0) { + return new BufferedImage[] { STORE_TILE, PRODUCT_TILES.get(this.product_id) }; + } else { + return new BufferedImage[] { STORE_TILE, PALETTE_TILE }; + } + } else { + return new BufferedImage[] { STORE_TILE }; + } + } + } +} diff --git a/StorageSim/src/storagesim/StorageWindow.java b/StorageSim/src/storagesim/StorageWindow.java new file mode 100644 index 0000000..50b434e --- /dev/null +++ b/StorageSim/src/storagesim/StorageWindow.java @@ -0,0 +1,265 @@ +package storagesim; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.Toolkit; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Locale; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JLabel; +import javax.swing.JButton; +import javax.swing.JTextField; +import javax.swing.JToggleButton; +import javax.swing.border.EmptyBorder; + +import lib.SQLConnection; + +/** + * Holds the window setup + */ +public class StorageWindow extends JFrame { + private static final long serialVersionUID = 1L; + + private JPanel contentPane; + + private JTextField txtName; + private JTextField txtMarke; + private JTextField txtKaufpreis; + private JTextField txtVerkaufspreis; + private JTextField txtMenge; + private JTextField txtHaltbarkeit; + private JToggleButton tglbtnGekuehlt; + + private MapPanel mapPanel; + private JButton btnUpdate; + private JButton btnReset; + + SQLConnection db; + + /** + * Initialises the layout + */ + public StorageWindow() { + setIconImage(Toolkit.getDefaultToolkit().getImage(StorageWindow.class.getResource("/javax/swing/plaf/metal/icons/ocean/homeFolder.gif"))); + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(200, 100, 960, 540); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + GridBagLayout gbl_contentPane = new GridBagLayout(); + gbl_contentPane.columnWidths = new int[] {424, 0, 0}; + gbl_contentPane.rowHeights = new int[] {252, 0, 0}; + gbl_contentPane.columnWeights = new double[] {3.0, 1.0, Double.MIN_VALUE}; + gbl_contentPane.rowWeights = new double[] {1.0, 0.0, Double.MIN_VALUE}; + contentPane.setLayout(gbl_contentPane); + setContentPane(contentPane); + + this.setTitle("SVEN Lagerkarte"); + + this.db = new SQLConnection(); + + mapPanel = new MapPanel(this); + GridBagConstraints gbc_mapPanel = new GridBagConstraints(); + gbc_mapPanel.insets = new Insets(0, 0, 5, 0); + gbc_mapPanel.fill = GridBagConstraints.BOTH; + gbc_mapPanel.gridx = 0; + gbc_mapPanel.gridy = 0; + contentPane.add(mapPanel, gbc_mapPanel); + + JPanel sidePanel = new JPanel(); + GridBagConstraints gbc_sidePanel = new GridBagConstraints(); + gbc_sidePanel.fill = GridBagConstraints.VERTICAL; + gbc_sidePanel.insets = new Insets(10, 10, 15, 10); + gbc_sidePanel.gridx = 1; + gbc_sidePanel.gridy = 0; + contentPane.add(sidePanel, gbc_sidePanel); + GridBagLayout gbl_sidePanel = new GridBagLayout(); + gbl_sidePanel.columnWidths = new int[]{40, 0}; + gbl_sidePanel.rowHeights = new int[]{15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + gbl_sidePanel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_sidePanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE}; + sidePanel.setLayout(gbl_sidePanel); + + JLabel lblMarke = new JLabel("Marke"); + GridBagConstraints gbc_lblMarke = new GridBagConstraints(); + gbc_lblMarke.insets = new Insets(0, 0, 5, 0); + gbc_lblMarke.gridx = 0; + gbc_lblMarke.gridy = 0; + sidePanel.add(lblMarke, gbc_lblMarke); + + txtMarke = new JTextField(); + txtMarke.setEditable(false); + GridBagConstraints gbc_txtMarke = new GridBagConstraints(); + gbc_txtMarke.insets = new Insets(0, 0, 5, 0); + gbc_txtMarke.fill = GridBagConstraints.HORIZONTAL; + gbc_txtMarke.gridx = 0; + gbc_txtMarke.gridy = 1; + sidePanel.add(txtMarke, gbc_txtMarke); + txtMarke.setColumns(10); + + JLabel lblName = new JLabel("Name"); + GridBagConstraints gbc_lblName = new GridBagConstraints(); + gbc_lblName.insets = new Insets(0, 0, 5, 0); + gbc_lblName.gridx = 0; + gbc_lblName.gridy = 2; + sidePanel.add(lblName, gbc_lblName); + + txtName = new JTextField(); + txtName.setEditable(false); + GridBagConstraints gbc_txtName = new GridBagConstraints(); + gbc_txtName.insets = new Insets(0, 0, 5, 0); + gbc_txtName.fill = GridBagConstraints.HORIZONTAL; + gbc_txtName.gridx = 0; + gbc_txtName.gridy = 3; + sidePanel.add(txtName, gbc_txtName); + txtName.setColumns(10); + + JLabel lblKaufpreis = new JLabel("Kaufpreis pro Stück"); + GridBagConstraints gbc_lblKaufpreis = new GridBagConstraints(); + gbc_lblKaufpreis.insets = new Insets(0, 0, 5, 0); + gbc_lblKaufpreis.gridx = 0; + gbc_lblKaufpreis.gridy = 4; + sidePanel.add(lblKaufpreis, gbc_lblKaufpreis); + + txtKaufpreis = new JTextField(); + txtKaufpreis.setEditable(false); + GridBagConstraints gbc_txtKaufpreis = new GridBagConstraints(); + gbc_txtKaufpreis.insets = new Insets(0, 0, 5, 0); + gbc_txtKaufpreis.fill = GridBagConstraints.HORIZONTAL; + gbc_txtKaufpreis.gridx = 0; + gbc_txtKaufpreis.gridy = 5; + sidePanel.add(txtKaufpreis, gbc_txtKaufpreis); + txtKaufpreis.setColumns(10); + + JLabel lblVerkaufspreis = new JLabel("Verkaufspreis"); + GridBagConstraints gbc_lblVerkaufspreis = new GridBagConstraints(); + gbc_lblVerkaufspreis.insets = new Insets(0, 0, 5, 0); + gbc_lblVerkaufspreis.gridx = 0; + gbc_lblVerkaufspreis.gridy = 6; + sidePanel.add(lblVerkaufspreis, gbc_lblVerkaufspreis); + + txtVerkaufspreis = new JTextField(); + txtVerkaufspreis.setEditable(false); + GridBagConstraints gbc_txtVerkaufspreis = new GridBagConstraints(); + gbc_txtVerkaufspreis.insets = new Insets(0, 0, 5, 0); + gbc_txtVerkaufspreis.fill = GridBagConstraints.HORIZONTAL; + gbc_txtVerkaufspreis.gridx = 0; + gbc_txtVerkaufspreis.gridy = 7; + sidePanel.add(txtVerkaufspreis, gbc_txtVerkaufspreis); + txtVerkaufspreis.setColumns(10); + + JLabel lblMenge = new JLabel("Menge"); + GridBagConstraints gbc_lblMenge = new GridBagConstraints(); + gbc_lblMenge.insets = new Insets(0, 0, 5, 0); + gbc_lblMenge.gridx = 0; + gbc_lblMenge.gridy = 8; + sidePanel.add(lblMenge, gbc_lblMenge); + + txtMenge = new JTextField(); + txtMenge.setEditable(false); + GridBagConstraints gbc_txtMenge = new GridBagConstraints(); + gbc_txtMenge.insets = new Insets(0, 0, 5, 0); + gbc_txtMenge.fill = GridBagConstraints.HORIZONTAL; + gbc_txtMenge.gridx = 0; + gbc_txtMenge.gridy = 9; + sidePanel.add(txtMenge, gbc_txtMenge); + txtMenge.setColumns(10); + + JLabel lblHaltbarkeit = new JLabel("Haltbar bis"); + GridBagConstraints gbc_lblHaltbarkeit = new GridBagConstraints(); + gbc_lblHaltbarkeit.insets = new Insets(0, 0, 5, 0); + gbc_lblHaltbarkeit.gridx = 0; + gbc_lblHaltbarkeit.gridy = 10; + sidePanel.add(lblHaltbarkeit, gbc_lblHaltbarkeit); + + txtHaltbarkeit = new JTextField(); + txtHaltbarkeit.setEditable(false); + GridBagConstraints gbc_txtHaltbarkeit = new GridBagConstraints(); + gbc_txtHaltbarkeit.insets = new Insets(0, 0, 5, 0); + gbc_txtHaltbarkeit.fill = GridBagConstraints.HORIZONTAL; + gbc_txtHaltbarkeit.gridx = 0; + gbc_txtHaltbarkeit.gridy = 11; + sidePanel.add(txtHaltbarkeit, gbc_txtHaltbarkeit); + txtHaltbarkeit.setColumns(10); + + tglbtnGekuehlt = new JToggleButton("Gekühlt"); + tglbtnGekuehlt.setEnabled(false); + GridBagConstraints gbc_tglbtnGekuehlt = new GridBagConstraints(); + gbc_tglbtnGekuehlt.insets = new Insets(0, 0, 5, 0); + gbc_tglbtnGekuehlt.gridx = 0; + gbc_tglbtnGekuehlt.gridy = 12; + sidePanel.add(tglbtnGekuehlt, gbc_tglbtnGekuehlt); + + JLabel lblClickToSelect = new JLabel("Click to select a storage tile!"); + GridBagConstraints gbc_lblClickToSelect = new GridBagConstraints(); + gbc_lblClickToSelect.insets = new Insets(0, 0, 5, 0); + gbc_lblClickToSelect.gridx = 0; + gbc_lblClickToSelect.gridy = 13; + sidePanel.add(lblClickToSelect, gbc_lblClickToSelect); + + btnUpdate = new JButton("update"); + GridBagConstraints gbc_btnUpdate = new GridBagConstraints(); + gbc_btnUpdate.insets = new Insets(0, 0, 5, 0); + gbc_btnUpdate.gridx = 0; + gbc_btnUpdate.gridy = 15; + sidePanel.add(btnUpdate, gbc_btnUpdate); + btnUpdate.addActionListener(e -> { + mapPanel.map.updateMap(db); + repaint(); + }); + + btnReset = new JButton("reset"); + GridBagConstraints gbc_btnReset = new GridBagConstraints(); + gbc_btnReset.gridx = 0; + gbc_btnReset.gridy = 16; + sidePanel.add(btnReset, gbc_btnReset); + btnReset.addActionListener(e -> { + mapPanel.resetView(); + repaint(); + }); + + this.pack(); + + // reset initial position + mapPanel.resetView(); + } + + /** + * Shows the selected tile's product information + */ + public void updateSidebar(SQLConnection db) { + int lagerplatz = mapPanel.map.selectedTile + 1; + ArrayList> query = db.queryToMap("SELECT t_lager.Lagerplatz, t_artikel.Marke, t_artikel.Name, t_artikel.Einkaufspreis, " + + "t_artikel.Verkaufspreis, t_lager.Menge, t_lager.Ankunft, t_artikel.`MHK in Tagen`, t_artikel.Gekühlt, t_artikel.Anzahl_pro_Palette FROM t_lager " + + "INNER JOIN t_artikel ON t_lager.f_Artikel_ID = t_artikel.ID " + + "WHERE Lagerplatz = " + lagerplatz); + if (query.size() == 1) { + HashMap storage = query.get(0); + + this.txtMarke.setText(storage.get("Marke")); + this.txtName.setText(storage.get("Name")); + this.txtKaufpreis.setText(String.format(Locale.GERMAN, "%.2f €", Float.parseFloat(storage.get("Einkaufspreis")))); + this.txtVerkaufspreis.setText(String.format(Locale.GERMAN, "%.2f €", Float.parseFloat(storage.get("Verkaufspreis")))); + this.txtMenge.setText(storage.get("Menge") + " / " + storage.get("Anzahl_pro_Palette")); + int haltbarkeit = Integer.parseInt(storage.get("MHK in Tagen")); + LocalDate ankunft = LocalDate.parse(storage.get("Ankunft")); + LocalDate ablauf = ankunft.plusDays(haltbarkeit); + this.txtHaltbarkeit.setText(ablauf.toString()); + this.tglbtnGekuehlt.setSelected(storage.get("Gekühlt").equals("1")); + } else { + // reset side + this.txtMarke.setText(""); + this.txtName.setText(""); + this.txtKaufpreis.setText(""); + this.txtVerkaufspreis.setText(""); + this.txtMenge.setText(""); + this.txtHaltbarkeit.setText(""); + this.tglbtnGekuehlt.setSelected(false); + } + } +}