├── .github ├── dependabot.yml └── workflows │ └── gradle.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src └── main └── java └── dev └── httpmarco └── aeon ├── Aeon.java ├── adapter ├── TypeAdapter.java ├── TypeAdapterFactory.java ├── TypeAdapterPool.java └── extras │ └── UUIDTypeAdapter.java ├── annotations ├── Comment.java └── Options.java ├── elements ├── ObjectAssortment.java ├── ObjectPrimitive.java ├── ObjectSeries.java └── ObjectUnit.java ├── handler ├── ObjectHandler.java ├── ObjectPattern.java └── layer │ ├── ObjectAssortmentLayer.java │ ├── ObjectCollectionLayer.java │ ├── ObjectEnumerationLayer.java │ ├── ObjectMapLayer.java │ ├── ObjectPrimitiveLayer.java │ ├── ObjectRecordLayer.java │ └── ObjectSeriesLayer.java ├── io ├── DistanceElement.java ├── RecordFileReader.java └── RecordFileWriter.java └── reflections ├── AeonPathFinder.java └── AeonReflections.java /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "gradle" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time 6 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle 7 | 8 | name: Java CI with Gradle 9 | 10 | on: 11 | push: 12 | branches: [ "master" ] 13 | pull_request: 14 | branches: [ "master" ] 15 | 16 | jobs: 17 | build: 18 | 19 | runs-on: ubuntu-latest 20 | permissions: 21 | contents: read 22 | 23 | steps: 24 | - uses: actions/checkout@v4 25 | - name: Set up JDK 17 26 | uses: actions/setup-java@v4 27 | with: 28 | java-version: '17' 29 | distribution: 'temurin' 30 | 31 | # Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies. 32 | # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md 33 | - name: Setup Gradle 34 | uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0 35 | 36 | - name: Make gradlew executable 37 | run: chmod +x ./gradlew 38 | 39 | - name: Build with Gradle Wrapper 40 | run: ./gradlew build 41 | 42 | # NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html). 43 | # If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version. 44 | # 45 | # - name: Setup Gradle 46 | # uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0 47 | # with: 48 | # gradle-version: '8.5' 49 | # 50 | # - name: Build with Gradle 8.5 51 | # run: gradle build -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse stuff 2 | .classpath 3 | .project 4 | .settings/ 5 | 6 | # netbeans 7 | nbproject/ 8 | nbactions.xml 9 | 10 | # we use maven! 11 | build.xml 12 | 13 | # maven 14 | target/ 15 | dependency-reduced-pom.xml 16 | 17 | # vim 18 | .*.sw[a-p] 19 | 20 | # various other potential build files 21 | build/ 22 | bin/ 23 | dist/ 24 | manifest.mf 25 | 26 | # Mac filesystem dust 27 | .DS_Store/ 28 | 29 | # intellij 30 | *.iml 31 | *.ipr 32 | *.iws 33 | .idea/ 34 | 35 | # gradle 36 | .gradle/ 37 | 38 | # other files 39 | *.log* 40 | 41 | # delombok 42 | */src/main/lombok 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | Stars Badge 5 | Forks Badge 6 | Pull Requests Badge 7 | Issues Badge 8 | GitHub contributors 9 | [![](https://jitpack.io/v/HttpMarco/Aeon.svg)](https://jitpack.io/#HttpMarco/Aeon) 10 |
11 | SUPPORT DISCORD 12 |
13 |
14 | 15 | **** 16 | 17 | Gradle Dependency 18 | 19 | ````groovy 20 | implementation 'com.github.HttpMarco:Aeon:TAG' 21 | ```` 22 | **** 23 | 24 | Maven Dependency 25 | ````xml 26 | 27 | com.github.HttpMarco 28 | Aeon 29 | Tag 30 | 31 | ```` 32 | *** 33 | 34 | Examples 35 | (Simple property object) 36 | 37 | ````java 38 | 39 | @Getter 40 | @Options(path = "src/test/java/net/http/aeon/", name = "config") 41 | public class TestConfiguration { 42 | 43 | private final String name; 44 | private final int testValue; 45 | private final TestObject testObject; 46 | 47 | public TestConfiguration() { 48 | this.name = "test"; 49 | this.testValue = 22; 50 | this.testObject = new TestObject(); 51 | } 52 | } 53 | ```` 54 | 55 | Save, read & auto manage of configuration 56 | 57 | ````java 58 | public void handle(){ 59 | TestConfiguration insert=Aeon.insert(new TestConfiguration()); 60 | System.out.println(insert.getTestValue()); 61 | } 62 | ```` 63 | 64 | Result: 65 | ```` 66 | testObject: [ 67 | value: 20 68 | ] 69 | name: test 70 | testValue: 22 71 | ```` 72 | 73 | Add header or spaces for configuration field 74 | `````java 75 | @Comment(comment = "Test comment", type = Emphasizing.PRIMARY) 76 | ````` 77 | 78 | **** 79 | 80 | Todo 'Release': 81 | 82 | - [ ] Handle of null parameters 83 | - [ ] rename for configuration files 84 | - [ ] Support Map, Pair 85 | - [ ] Add comments for fields 86 | - [ ] remove duplicated renamed fields 87 | - [ ] Customize handler for object serialization -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-library") 3 | alias(libs.plugins.nexus.publish) 4 | } 5 | 6 | apply(plugin = "signing") 7 | apply(plugin = "maven-publish") 8 | 9 | group = "dev.httpmarco" 10 | version = "1.2.0.1-SNAPSHOT" 11 | 12 | dependencies { 13 | testImplementation(libs.jUnit) 14 | testRuntimeOnly(libs.jUnit) 15 | 16 | compileOnly(libs.lombok) 17 | annotationProcessor(libs.lombok) 18 | testCompileOnly(libs.lombok) 19 | testAnnotationProcessor(libs.lombok) 20 | } 21 | 22 | tasks.getByName("test") { 23 | useJUnitPlatform() 24 | } 25 | 26 | tasks.withType { 27 | sourceCompatibility = JavaVersion.VERSION_17.toString() 28 | targetCompatibility = JavaVersion.VERSION_17.toString() 29 | // options 30 | options.encoding = "UTF-8" 31 | options.isIncremental = true 32 | } 33 | 34 | extensions.configure { 35 | publications { 36 | create("library", MavenPublication::class.java) { 37 | from(project.components.getByName("java")) 38 | 39 | pom { 40 | name.set(project.name) 41 | url.set("https://github.com/httpmarco/osgon") 42 | description.set("Reflection/Data libary") 43 | licenses { 44 | license { 45 | name.set("MIT License") 46 | url.set("https://opensource.org/licenses/MIT") 47 | } 48 | } 49 | developers { 50 | developer { 51 | name.set("Mirco Lindenau") 52 | email.set("mirco.lindenau@gmx.de") 53 | } 54 | } 55 | scm { 56 | url.set("https://github.com/httpmarco/osgon") 57 | connection.set("https://github.com/httpmarco/osgon.git") 58 | } 59 | } 60 | } 61 | } 62 | } 63 | 64 | nexusPublishing { 65 | repositories { 66 | sonatype { 67 | nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) 68 | snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) 69 | 70 | username.set(System.getenv("ossrhUsername")?.toString() ?: "") 71 | password.set(System.getenv("ossrhPassword")?.toString() ?: "") 72 | } 73 | } 74 | useStaging.set(!project.rootProject.version.toString().endsWith("-SNAPSHOT")) 75 | } -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | 3 | jUnit = "5.12.0" 4 | lombok = "1.18.36" 5 | nexus-publish = "2.0.0" 6 | 7 | [libraries] 8 | 9 | jUnit = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "jUnit" } 10 | lombok = { group = "org.projectlombok", name = "lombok", version.ref = "lombok" } 11 | 12 | [plugins] 13 | 14 | nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus-publish" } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HttpMarco/aeon/f02fd6c9cb9b7bca8cbb836607c0823347e852e9/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | @file:Suppress("UnstableApiUsage") 2 | 3 | rootProject.name = "aeon" 4 | 5 | dependencyResolutionManagement { 6 | repositories { 7 | maven("https://jitpack.io") 8 | mavenCentral() 9 | } 10 | } 11 | 12 | pluginManagement { 13 | repositories { 14 | mavenCentral() 15 | gradlePluginPortal() 16 | } 17 | } 18 | 19 | 20 | rootProject.name = "aeon" 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/Aeon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon; 18 | 19 | import dev.httpmarco.aeon.adapter.TypeAdapterFactory; 20 | import dev.httpmarco.aeon.annotations.Options; 21 | import dev.httpmarco.aeon.handler.ObjectHandler; 22 | import dev.httpmarco.aeon.io.RecordFileReader; 23 | import dev.httpmarco.aeon.io.RecordFileWriter; 24 | import dev.httpmarco.aeon.reflections.AeonPathFinder; 25 | import lombok.Getter; 26 | import lombok.NonNull; 27 | 28 | import java.nio.file.Files; 29 | import java.nio.file.Path; 30 | 31 | @SuppressWarnings("ALL") 32 | public final class Aeon { 33 | 34 | @Getter 35 | private static final ObjectHandler objectHandler = new ObjectHandler(); 36 | @Getter 37 | private static final TypeAdapterFactory typeAdapterFactory = new TypeAdapterFactory(); 38 | 39 | public static T insert(@NonNull T value, Path path) { 40 | if (value.getClass().isAnnotationPresent(Options.class)) { 41 | Options options = value.getClass().getDeclaredAnnotation(Options.class); 42 | if (options.name().length() > 0) { 43 | path = path.resolve(Path.of(options.name())); 44 | } 45 | } 46 | path = Path.of(path + ".ae"); 47 | 48 | if (Files.exists(path)) { 49 | var element = (T) objectHandler.read(value.getClass(), new RecordFileReader(path).getObjectAssortment()); 50 | //overwrite existing property 51 | new RecordFileWriter(objectHandler.write(element), path); 52 | return element; 53 | } 54 | new RecordFileWriter(objectHandler.write(value), path); 55 | return value; 56 | } 57 | 58 | public static T insert(@NonNull T value) { 59 | return insert(value, AeonPathFinder.find(value)); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/adapter/TypeAdapter.java: -------------------------------------------------------------------------------- 1 | package dev.httpmarco.aeon.adapter; 2 | 3 | import dev.httpmarco.aeon.elements.ObjectUnit; 4 | 5 | public abstract class TypeAdapter { 6 | 7 | public ObjectUnit writeInstance(T value) { 8 | return this.write(value); 9 | } 10 | 11 | @SuppressWarnings("unchecked") 12 | public Object readInstance(Class value, ObjectUnit unit) { 13 | return this.read((Class) value, unit); 14 | } 15 | 16 | public abstract ObjectUnit write(T value); 17 | 18 | public abstract T read(Class value, ObjectUnit unit); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/adapter/TypeAdapterFactory.java: -------------------------------------------------------------------------------- 1 | package dev.httpmarco.aeon.adapter; 2 | 3 | import lombok.Getter; 4 | import dev.httpmarco.aeon.adapter.extras.UUIDTypeAdapter; 5 | 6 | @Getter 7 | public final class TypeAdapterFactory { 8 | 9 | private final TypeAdapterPool typeAdapterPool = new TypeAdapterPool(); 10 | 11 | public TypeAdapterFactory() { 12 | 13 | //default uuid type adapter 14 | this.typeAdapterPool.registerTypeAdapter(new UUIDTypeAdapter()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/adapter/TypeAdapterPool.java: -------------------------------------------------------------------------------- 1 | package dev.httpmarco.aeon.adapter; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | 5 | import java.util.*; 6 | 7 | public final class TypeAdapterPool { 8 | 9 | private final List> typeAdapters = new ArrayList<>(); 10 | 11 | @SuppressWarnings("unchecked") 12 | public Optional> findIf(Class clazz) { 13 | return typeAdapters.stream().filter(it -> { 14 | Class type = (Class) ((ParameterizedType) it.getClass().getGenericSuperclass()).getActualTypeArguments()[0]; 15 | return type.equals(clazz) 16 | || (!clazz.isEnum() && findAllInterfaces(clazz).contains(type)) 17 | || (type.getSuperclass() != null && type.getSuperclass().equals(clazz)); 18 | }).map(typeAdapter -> (TypeAdapter) typeAdapter).findFirst(); 19 | } 20 | 21 | public void registerTypeAdapter(TypeAdapter typeAdapter) { 22 | this.typeAdapters.add(typeAdapter); 23 | } 24 | 25 | public List> findAllInterfaces(Class clazz) { 26 | var interfaces = new ArrayList>(); 27 | for (var aClass : clazz.getInterfaces()) { 28 | interfaces.add(aClass); 29 | interfaces.addAll(findAllInterfaces(aClass)); 30 | } 31 | return interfaces; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/adapter/extras/UUIDTypeAdapter.java: -------------------------------------------------------------------------------- 1 | package dev.httpmarco.aeon.adapter.extras; 2 | 3 | import dev.httpmarco.aeon.elements.ObjectPrimitive; 4 | import dev.httpmarco.aeon.elements.ObjectUnit; 5 | import dev.httpmarco.aeon.adapter.TypeAdapter; 6 | 7 | import java.util.UUID; 8 | 9 | public final class UUIDTypeAdapter extends TypeAdapter { 10 | 11 | @Override 12 | public ObjectUnit write(UUID value) { 13 | return new ObjectPrimitive(value.toString()); 14 | } 15 | 16 | @Override 17 | public UUID read(Class value, ObjectUnit unit) { 18 | return UUID.fromString(unit.primitives().getValue().toString()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/annotations/Comment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | @Target({ElementType.TYPE, ElementType.FIELD}) 25 | @Retention(RetentionPolicy.RUNTIME) 26 | public @interface Comment { 27 | 28 | String[] comment(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/annotations/Options.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Target(ElementType.TYPE) 26 | public @interface Options { 27 | 28 | String name() default ""; 29 | 30 | String[] path() default ""; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/elements/ObjectAssortment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.elements; 18 | 19 | import lombok.Getter; 20 | import dev.httpmarco.aeon.Aeon; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | @Getter 26 | public final class ObjectAssortment extends ObjectUnit { 27 | 28 | private final Map units = new HashMap<>(); 29 | 30 | public void append(String key, ObjectUnit unit) { 31 | this.units.put(key, unit); 32 | } 33 | 34 | public void append(String key, Object serialazibleObject) { 35 | this.units.put(key, Aeon.getObjectHandler().write(serialazibleObject)); 36 | } 37 | 38 | public void append(String key, String element) { 39 | if (element == null) { 40 | this.units.put(key, NULL); 41 | return; 42 | } 43 | this.units.put(key, new ObjectPrimitive(element)); 44 | } 45 | 46 | public void append(String key, int element) { 47 | this.units.put(key, new ObjectPrimitive(element)); 48 | } 49 | 50 | public void append(String key, double element) { 51 | this.units.put(key, new ObjectPrimitive(element)); 52 | } 53 | 54 | public void append(String key, float element) { 55 | this.units.put(key, new ObjectPrimitive(element)); 56 | } 57 | 58 | public void append(String key, boolean element) { 59 | this.units.put(key, new ObjectPrimitive(element)); 60 | } 61 | 62 | public ObjectUnit get(String key) { 63 | return this.units.get(key); 64 | } 65 | 66 | public boolean has(String key) { 67 | return this.units.containsKey(key); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/elements/ObjectPrimitive.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.elements; 18 | 19 | import dev.httpmarco.aeon.reflections.AeonReflections; 20 | import lombok.AllArgsConstructor; 21 | import lombok.Getter; 22 | import dev.httpmarco.aeon.Aeon; 23 | 24 | @Getter 25 | @AllArgsConstructor 26 | public final class ObjectPrimitive extends ObjectUnit { 27 | 28 | private Object value; 29 | 30 | public String asString() { 31 | return value.toString(); 32 | } 33 | 34 | public int asInt() { 35 | return Integer.parseInt(value.toString()); 36 | } 37 | 38 | public boolean asBoolean() { 39 | return Boolean.parseBoolean(value.toString()); 40 | } 41 | 42 | public double asDouble() { 43 | return Double.parseDouble(value.toString()); 44 | } 45 | 46 | public short asShort() { 47 | return Short.parseShort(value.toString()); 48 | } 49 | 50 | public float asFloat() { 51 | return Float.parseFloat(value.toString()); 52 | } 53 | 54 | public T as(Class clazz) { 55 | if (clazz.isPrimitive() || AeonReflections.isDefaultElement(clazz)) { 56 | return (T) this.value; 57 | } else { 58 | return (T) Aeon.getObjectHandler().read(clazz, this); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/elements/ObjectSeries.java: -------------------------------------------------------------------------------- 1 | package dev.httpmarco.aeon.elements; 2 | 3 | import lombok.Getter; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | @Getter 9 | public final class ObjectSeries extends ObjectUnit { 10 | 11 | private final List units = new ArrayList<>(); 12 | 13 | public void add(ObjectUnit unit) { 14 | this.units.add(unit); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/elements/ObjectUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.elements; 18 | 19 | import lombok.Getter; 20 | import lombok.Setter; 21 | 22 | @Setter 23 | @Getter 24 | public abstract class ObjectUnit { 25 | 26 | public static final ObjectUnit NULL = new ObjectUnit() {}; 27 | 28 | private String[] comments; 29 | 30 | public ObjectAssortment assortment() { 31 | return (ObjectAssortment) this; 32 | } 33 | 34 | public ObjectPrimitive primitives() { 35 | return (ObjectPrimitive) this; 36 | } 37 | 38 | public ObjectSeries series() { 39 | return (ObjectSeries) this; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/handler/ObjectHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.handler; 18 | 19 | import java.lang.reflect.ParameterizedType; 20 | 21 | import dev.httpmarco.aeon.elements.ObjectUnit; 22 | import dev.httpmarco.aeon.handler.layer.*; 23 | import lombok.Getter; 24 | import dev.httpmarco.aeon.Aeon; 25 | 26 | import java.lang.reflect.Type; 27 | import java.util.Arrays; 28 | import java.util.Optional; 29 | 30 | @Getter 31 | public final class ObjectHandler { 32 | 33 | private final ObjectPattern[] patterns = new ObjectPattern[]{ 34 | new ObjectSeriesLayer(), new ObjectCollectionLayer(), new ObjectEnumerationLayer(), new ObjectPrimitiveLayer(), 35 | new ObjectMapLayer(), new ObjectRecordLayer(), new ObjectAssortmentLayer(), 36 | }; 37 | 38 | public ObjectUnit write(T object) { 39 | if (object == null) { 40 | return ObjectUnit.NULL; 41 | } 42 | @SuppressWarnings("unchecked") 43 | final var clazz = (Class) object.getClass(); 44 | final var adapter = Aeon.getTypeAdapterFactory().getTypeAdapterPool().findIf(clazz); 45 | if (adapter.isPresent()) { 46 | return adapter.get().writeInstance(object); 47 | } else { 48 | var optional = Aeon.getObjectHandler().findPattern(clazz); 49 | if (optional.isEmpty()) { 50 | return ObjectUnit.NULL; 51 | } 52 | return optional.get().write(object); 53 | } 54 | } 55 | 56 | 57 | public Object read(Type type, ObjectUnit unit) { 58 | if (unit == ObjectUnit.NULL) { 59 | return null; 60 | } 61 | Class clazz = null; 62 | if (type instanceof Class) { 63 | clazz = (Class) type; 64 | } else if (type instanceof ParameterizedType parameterizedType) { 65 | clazz = (Class) parameterizedType.getRawType(); 66 | } 67 | 68 | final var adapter = Aeon.getTypeAdapterFactory() 69 | .getTypeAdapterPool().findIf(clazz); 70 | if (adapter.isPresent()) { 71 | try { 72 | return adapter.get().readInstance(clazz, unit); 73 | } catch (Exception exception) { 74 | // return adapter.get(clazz).readCaughtException(exception); 75 | exception.printStackTrace(); 76 | return null; 77 | } 78 | } else { 79 | return Aeon.getObjectHandler().findPattern(clazz) 80 | .map(objectPattern -> objectPattern.read(type, unit)) 81 | .orElse(null); 82 | } 83 | } 84 | 85 | public Optional findPattern(Class clazz) { 86 | return Arrays.stream(this.patterns).filter(it -> it.isElement(clazz)).findFirst(); 87 | } 88 | } -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/handler/ObjectPattern.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.handler; 18 | 19 | import dev.httpmarco.aeon.elements.ObjectUnit; 20 | 21 | import java.lang.reflect.Type; 22 | 23 | public interface ObjectPattern { 24 | 25 | boolean isElement(Class clazz); 26 | 27 | ObjectUnit write(Object o); 28 | 29 | Object read(Type type, ObjectUnit unit); 30 | 31 | default Object readCaughtException(Exception exception) { 32 | exception.printStackTrace(); 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/handler/layer/ObjectAssortmentLayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.handler.layer; 18 | 19 | import dev.httpmarco.aeon.annotations.Comment; 20 | import dev.httpmarco.aeon.elements.ObjectAssortment; 21 | import dev.httpmarco.aeon.elements.ObjectUnit; 22 | import dev.httpmarco.aeon.handler.ObjectPattern; 23 | import dev.httpmarco.aeon.reflections.AeonReflections; 24 | import dev.httpmarco.aeon.Aeon; 25 | 26 | import java.lang.reflect.Type; 27 | 28 | public final class ObjectAssortmentLayer implements ObjectPattern { 29 | 30 | public static ObjectAssortmentLayer INSTANCE; 31 | 32 | public ObjectAssortmentLayer() { 33 | INSTANCE = this; 34 | } 35 | 36 | @Override 37 | public boolean isElement(Class clazz) { 38 | return true; 39 | } 40 | 41 | @Override 42 | public ObjectUnit write(Object value) { 43 | var assortment = new ObjectAssortment(); 44 | for (final var field : value.getClass().getDeclaredFields()) { 45 | var unit = Aeon.getObjectHandler().write(AeonReflections.get(field, value)); 46 | if (field.isAnnotationPresent(Comment.class)) { 47 | unit.setComments(field.getDeclaredAnnotation(Comment.class).comment()); 48 | } 49 | assortment.append(field.getName(), unit); 50 | } 51 | return assortment; 52 | } 53 | 54 | @Override 55 | public Object read(Type type, ObjectUnit unit) { 56 | final var clazz = (Class) type; 57 | var object = AeonReflections.allocate(clazz); 58 | if (unit instanceof ObjectAssortment assortment) { 59 | for (final var field : clazz.getDeclaredFields()) { 60 | if (assortment.has(field.getName())) { 61 | AeonReflections.modify(field, object, Aeon.getObjectHandler() 62 | .read(field.getGenericType(), assortment.get(field.getName()))); 63 | } else { 64 | AeonReflections.modify(field, object, null); 65 | } 66 | } 67 | } 68 | return object; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/handler/layer/ObjectCollectionLayer.java: -------------------------------------------------------------------------------- 1 | package dev.httpmarco.aeon.handler.layer; 2 | 3 | import dev.httpmarco.aeon.elements.ObjectSeries; 4 | import dev.httpmarco.aeon.elements.ObjectUnit; 5 | import dev.httpmarco.aeon.Aeon; 6 | import dev.httpmarco.aeon.handler.ObjectPattern; 7 | 8 | import java.lang.reflect.ParameterizedType; 9 | import java.lang.reflect.Type; 10 | import java.util.Collection; 11 | import java.util.stream.Collectors; 12 | 13 | public final class ObjectCollectionLayer implements ObjectPattern { 14 | 15 | @Override 16 | public boolean isElement(Class clazz) { 17 | return Collection.class.isAssignableFrom(clazz); 18 | } 19 | 20 | @Override 21 | public ObjectUnit write(Object o) { 22 | var series = new ObjectSeries(); 23 | for (Object elements : (Collection) o) { 24 | series.add(Aeon.getObjectHandler().write(elements)); 25 | } 26 | return series; 27 | } 28 | 29 | @Override 30 | public Object read(Type type, ObjectUnit unit) { 31 | if (!(unit instanceof ObjectSeries series)) throw new UnsupportedOperationException(); 32 | return series.getUnits().stream().map(it -> Aeon.getObjectHandler() 33 | .read(((ParameterizedType) type).getActualTypeArguments()[0], it)) 34 | .collect(Collectors.toList()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/handler/layer/ObjectEnumerationLayer.java: -------------------------------------------------------------------------------- 1 | package dev.httpmarco.aeon.handler.layer; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import dev.httpmarco.aeon.elements.ObjectPrimitive; 6 | import dev.httpmarco.aeon.elements.ObjectUnit; 7 | import dev.httpmarco.aeon.handler.ObjectPattern; 8 | 9 | import java.util.Locale; 10 | 11 | public final class ObjectEnumerationLayer implements ObjectPattern { 12 | 13 | @Override 14 | public boolean isElement(Class clazz) { 15 | return clazz.isEnum(); 16 | } 17 | 18 | @Override 19 | public ObjectUnit write(Object object) { 20 | return new ObjectPrimitive(((Enum) object).name()); 21 | } 22 | 23 | @SuppressWarnings("unchecked") 24 | @Override 25 | public Object read(Type type, ObjectUnit unit) { 26 | if (unit instanceof ObjectPrimitive primitive) { 27 | var enumClass = (Class) type; 28 | try { 29 | return Enum.valueOf(enumClass, primitive.getValue().toString().toUpperCase(Locale.ROOT)); 30 | } catch (IllegalArgumentException exception) { 31 | var constants = enumClass.getEnumConstants(); 32 | var notPresentConstant = "Enum constant is not present: " + primitive.getValue().toString().toUpperCase(Locale.ROOT); 33 | if (constants.length == 0) { 34 | throw new UnsupportedOperationException(notPresentConstant + ", no default value is present."); 35 | } 36 | System.out.println(notPresentConstant + " <-> change to default value: " + constants[0].name()); 37 | return constants[0]; 38 | } 39 | } 40 | throw new UnsupportedOperationException("The given unit is not an enumeration"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/handler/layer/ObjectMapLayer.java: -------------------------------------------------------------------------------- 1 | package dev.httpmarco.aeon.handler.layer; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import dev.httpmarco.aeon.elements.ObjectAssortment; 6 | import dev.httpmarco.aeon.elements.ObjectUnit; 7 | import dev.httpmarco.aeon.Aeon; 8 | import dev.httpmarco.aeon.handler.ObjectPattern; 9 | 10 | import java.lang.reflect.ParameterizedType; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public final class ObjectMapLayer implements ObjectPattern { 15 | 16 | @Override 17 | public boolean isElement(Class clazz) { 18 | return Map.class.isAssignableFrom(clazz); 19 | } 20 | 21 | @Override 22 | public ObjectUnit write(Object o) { 23 | var map = (Map) o; 24 | var assortment = new ObjectAssortment(); 25 | map.forEach((o1, o2) -> assortment.append(o1.toString(), Aeon.getObjectHandler().write(o2))); 26 | return assortment; 27 | } 28 | 29 | @Override 30 | public Object read(Type type, ObjectUnit unit) { 31 | var map = new HashMap<>(); 32 | 33 | var typeCurrent = ((ParameterizedType) type).getActualTypeArguments()[1]; 34 | 35 | unit.assortment().getUnits().forEach((s, unit1) -> map.put(s, Aeon.getObjectHandler() 36 | .read(typeCurrent, unit1))); 37 | return map; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/handler/layer/ObjectPrimitiveLayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.handler.layer; 18 | 19 | import java.lang.reflect.Type; 20 | 21 | import dev.httpmarco.aeon.elements.ObjectPrimitive; 22 | import dev.httpmarco.aeon.reflections.AeonReflections; 23 | import dev.httpmarco.aeon.elements.ObjectUnit; 24 | import dev.httpmarco.aeon.handler.ObjectPattern; 25 | 26 | import java.beans.PropertyEditorManager; 27 | 28 | public final class ObjectPrimitiveLayer implements ObjectPattern { 29 | 30 | @Override 31 | public boolean isElement(Class clazz) { 32 | return clazz.isPrimitive() || AeonReflections.isDefaultElement(clazz); 33 | } 34 | 35 | @Override 36 | public ObjectUnit write(Object value) { 37 | return new ObjectPrimitive(value); 38 | } 39 | 40 | @Override 41 | public Object read(Type type, ObjectUnit unit) { 42 | if (!(unit instanceof ObjectPrimitive primitive)) { 43 | throw new UnsupportedOperationException("This is not a correct primitive type."); 44 | } 45 | var editor = PropertyEditorManager.findEditor((Class) type); 46 | editor.setAsText(primitive.getValue().toString()); 47 | return editor.getValue(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/handler/layer/ObjectRecordLayer.java: -------------------------------------------------------------------------------- 1 | package dev.httpmarco.aeon.handler.layer; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import dev.httpmarco.aeon.elements.ObjectAssortment; 6 | import dev.httpmarco.aeon.elements.ObjectUnit; 7 | import lombok.SneakyThrows; 8 | import dev.httpmarco.aeon.Aeon; 9 | import dev.httpmarco.aeon.handler.ObjectPattern; 10 | 11 | import java.lang.reflect.Constructor; 12 | import java.lang.reflect.Field; 13 | import java.util.ArrayList; 14 | import java.util.Arrays; 15 | 16 | public final class ObjectRecordLayer implements ObjectPattern { 17 | 18 | @Override 19 | public boolean isElement(Class clazz) { 20 | return clazz.isRecord(); 21 | } 22 | 23 | @Override 24 | public ObjectUnit write(Object value) { 25 | return ObjectAssortmentLayer.INSTANCE.write(value); 26 | } 27 | 28 | @SneakyThrows 29 | @Override 30 | public Object read(Type type, ObjectUnit unit) { 31 | final var clazz = (Class) type; 32 | var types = Arrays.stream(clazz.getDeclaredFields()) 33 | .map(Field::getType) 34 | .toArray(value -> new Class[value]); 35 | var typeObjects = new ArrayList<>(); 36 | if (unit instanceof ObjectAssortment assortment) { 37 | for (final var field : clazz.getDeclaredFields()) { 38 | if (assortment.get(field.getName()) != null) { 39 | typeObjects.add(Aeon.getObjectHandler() 40 | .read(field.getGenericType(), assortment.get(field.getName()))); 41 | } 42 | } 43 | } 44 | Constructor constructor = clazz.getDeclaredConstructor(types); 45 | constructor.setAccessible(true); 46 | return constructor.newInstance(typeObjects.toArray()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/handler/layer/ObjectSeriesLayer.java: -------------------------------------------------------------------------------- 1 | package dev.httpmarco.aeon.handler.layer; 2 | 3 | import dev.httpmarco.aeon.elements.ObjectSeries; 4 | import dev.httpmarco.aeon.elements.ObjectUnit; 5 | import dev.httpmarco.aeon.Aeon; 6 | import dev.httpmarco.aeon.handler.ObjectPattern; 7 | 8 | import java.lang.reflect.Array; 9 | import java.lang.reflect.Type; 10 | 11 | public final class ObjectSeriesLayer implements ObjectPattern { 12 | 13 | @Override 14 | public boolean isElement(Class clazz) { 15 | return clazz.isArray(); 16 | } 17 | 18 | @Override 19 | public ObjectUnit write(Object o) { 20 | var series = new ObjectSeries(); 21 | for (var i = 0; i < Array.getLength(o); i++) { 22 | var element = Array.get(o, i); 23 | series.add(Aeon.getObjectHandler().write(element)); 24 | } 25 | return series; 26 | } 27 | 28 | @Override 29 | public Object read(Type type, ObjectUnit unit) { 30 | final var clazz = (Class) type; 31 | if (!(unit instanceof ObjectSeries series)) throw new UnsupportedOperationException(); 32 | var array = Array.newInstance(clazz.getComponentType(), series.getUnits().size()); 33 | for (var i = 0; i < series.getUnits().size(); i++) { 34 | Array.set(array, i, Aeon.getObjectHandler().read(clazz.getComponentType(), series.getUnits().get(i))); 35 | } 36 | return array; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/io/DistanceElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.io; 18 | 19 | public abstract class DistanceElement { 20 | 21 | public static final String NEXT_LINE = "\n"; 22 | 23 | private int distance = 0; 24 | 25 | public String space() { 26 | return " ".repeat(distance * 3); 27 | } 28 | 29 | public void expand() { 30 | distance++; 31 | } 32 | 33 | public void reduce() { 34 | distance--; 35 | } 36 | 37 | public void blockSet(Runnable runnable) { 38 | this.expand(); 39 | runnable.run(); 40 | this.reduce(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/io/RecordFileReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.io; 18 | 19 | import dev.httpmarco.aeon.elements.ObjectAssortment; 20 | import dev.httpmarco.aeon.elements.ObjectPrimitive; 21 | import dev.httpmarco.aeon.elements.ObjectSeries; 22 | import dev.httpmarco.aeon.elements.ObjectUnit; 23 | import lombok.Getter; 24 | import lombok.SneakyThrows; 25 | 26 | import java.nio.file.Files; 27 | import java.nio.file.Path; 28 | import java.util.List; 29 | 30 | @Getter 31 | public final class RecordFileReader extends DistanceElement { 32 | 33 | private final ObjectAssortment objectAssortment = new ObjectAssortment(); 34 | 35 | @SneakyThrows 36 | public RecordFileReader(Path path) { 37 | var lines = Files.readAllLines(path).stream() 38 | .map(String::trim) 39 | .filter(it -> !(it.isEmpty() || it.startsWith("#"))) 40 | .toList(); 41 | for (var index = 0; index < lines.size(); index++) { 42 | index += readElement(lines.subList(index, lines.size()), objectAssortment); 43 | } 44 | } 45 | 46 | private int readElement(List lines, ObjectUnit unit) { 47 | var line = lines.get(0); 48 | if (line.contains(": [")) { 49 | return this.readAssortment(lines.subList(1, lines.size()), unit, line.split(": ")[0]); 50 | } else if (line.contains(": {")) { 51 | return this.readSeries(lines.subList(1, lines.size()), unit, line.split(": ")[0]); 52 | } else if (line.contains(": ")) { 53 | return this.readPrimitive(unit, line.split(": "), line); 54 | } else { 55 | throw new UnsupportedOperationException("Element: " + line); 56 | } 57 | } 58 | 59 | private int readPrimitive(ObjectUnit unit, String[] elements, String line) { 60 | if (!(unit instanceof ObjectAssortment assortment)) return 1; 61 | assortment.append(elements[0], new ObjectPrimitive(line.substring(elements[0].length() + 2))); 62 | return 0; 63 | } 64 | 65 | private int readAssortment(List lines, ObjectUnit unit, String key) { 66 | var id = 0; 67 | var instance = new ObjectAssortment(); 68 | for (id = 0; id < lines.size(); id++) { 69 | if (lines.get(id).equals("]") || lines.get(id).equals("],")) break; 70 | id += readElement(lines.subList(id, lines.size()), instance); 71 | } 72 | this.add(unit, key, instance); 73 | return ++id; 74 | } 75 | 76 | private int readSeries(List lines, ObjectUnit unit, String key) { 77 | var id = 0; 78 | var series = new ObjectSeries(); 79 | for (id = 0; id < lines.size(); id++) { 80 | var line = lines.get(id); 81 | if (line.contains("}")) break; 82 | if (line.contains("[")) { 83 | id += readAssortment(lines.subList(id + 1, lines.size()), series, null); 84 | } else { 85 | series.add(new ObjectPrimitive(line.substring(0, line.endsWith(",") ? line.length() - 1 : line.length()))); 86 | } 87 | } 88 | this.add(unit, key, series); 89 | return ++id; 90 | } 91 | 92 | private void add(ObjectUnit unit, String key, ObjectUnit instance) { 93 | if (unit instanceof ObjectAssortment assortment) { 94 | assortment.append(key, instance); 95 | } else if (unit instanceof ObjectSeries series) { 96 | series.add(instance); 97 | } 98 | } 99 | } -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/io/RecordFileWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.io; 18 | 19 | import java.util.regex.Pattern; 20 | 21 | import dev.httpmarco.aeon.elements.ObjectAssortment; 22 | import dev.httpmarco.aeon.elements.ObjectPrimitive; 23 | import dev.httpmarco.aeon.elements.ObjectSeries; 24 | import dev.httpmarco.aeon.elements.ObjectUnit; 25 | 26 | import java.io.IOException; 27 | import java.nio.charset.StandardCharsets; 28 | import java.nio.file.Files; 29 | import java.nio.file.Path; 30 | 31 | public final class RecordFileWriter extends DistanceElement { 32 | 33 | private static final Pattern PATTERN = Pattern.compile("\n"); 34 | 35 | private final StringBuilder builder = new StringBuilder(); 36 | 37 | public RecordFileWriter(ObjectUnit unit, Path path) { 38 | this.writeElement(null, unit, false); 39 | 40 | if (!Files.exists(path) && path.getParent() != null) { 41 | try { 42 | Files.createDirectories(path.getParent()); 43 | } catch (IOException e) { 44 | throw new RuntimeException(e); 45 | } 46 | } 47 | 48 | try (var reader = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { 49 | reader.write(this.builder.toString()); 50 | } catch (IOException exception) { 51 | exception.printStackTrace(); 52 | } 53 | } 54 | 55 | private void writeElement(String key, ObjectUnit unit, boolean seriesElement) { 56 | if (unit.getComments() != null) { 57 | for (String comment : unit.getComments()) { 58 | this.builder 59 | .append(this.space()) 60 | .append("# ") 61 | .append(comment) 62 | .append(NEXT_LINE); 63 | } 64 | } 65 | 66 | if (key == null && unit instanceof ObjectAssortment assortment && !seriesElement) { 67 | assortment.getUnits().forEach((s, unit1) -> writeElement(s, unit1, false)); 68 | } else if (unit == ObjectUnit.NULL) { 69 | this.writeNull(key, seriesElement); 70 | } else if (unit instanceof ObjectAssortment assortment) { 71 | this.writeAssortment(key, assortment, seriesElement); 72 | } else if (unit instanceof ObjectSeries series) { 73 | this.writeSeries(key, series); 74 | } else if (unit instanceof ObjectPrimitive primitive) { 75 | this.writePrimitive(primitive, key, seriesElement); 76 | } else throw new UnsupportedOperationException(); 77 | } 78 | 79 | private void writeNull(final String key, final boolean seriesElement) { 80 | this.writeBasis(key, seriesElement); 81 | this.builder 82 | .append((String) null) 83 | .append(NEXT_LINE); 84 | } 85 | 86 | private void writeAssortment(String key, ObjectAssortment assortment, boolean seriesElement) { 87 | this.writeBlockElement(key, () -> assortment.getUnits().forEach((s, unit) -> writeElement(s, unit, false)), '[', ']', seriesElement); 88 | } 89 | 90 | private void writeSeries(String key, ObjectSeries series) { 91 | this.writeBlockElement(key, () -> { 92 | for (int i = 0; i < series.getUnits().size(); i++) { 93 | this.writeElement(null, series.getUnits().get(i), true); 94 | if (i < series.getUnits().size() - 1) { 95 | this.builder.delete(this.builder.length() - 1, this.builder.length()).append(",\n"); 96 | } 97 | } 98 | }, '{', '}', false); 99 | } 100 | 101 | private void writePrimitive(ObjectPrimitive primitive, String key, boolean seriesElement) { 102 | this.writeBasis(key, seriesElement); 103 | this.builder 104 | .append(PATTERN.matcher(primitive.getValue().toString()).replaceAll("\\\\n")) 105 | .append(NEXT_LINE); 106 | } 107 | 108 | private void writeBlockElement(String key, Runnable handle, char openSymbol, char closeSymbol, boolean seriesElement) { 109 | this.writeBasis(key, seriesElement); 110 | this.builder 111 | .append(openSymbol) 112 | .append(NEXT_LINE); 113 | this.blockSet(handle); 114 | this.builder.append(this.space()) 115 | .append(closeSymbol) 116 | .append(NEXT_LINE); 117 | } 118 | 119 | private void writeBasis(final String key, final boolean seriesElement) { 120 | this.builder.append(this.space()); 121 | if (!seriesElement) { 122 | this.builder.append(key).append(": "); 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/reflections/AeonPathFinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.reflections; 18 | 19 | import dev.httpmarco.aeon.annotations.Options; 20 | 21 | import java.nio.file.Path; 22 | 23 | public final class AeonPathFinder { 24 | 25 | public static Path find(Object value) { 26 | final var options = value.getClass().getAnnotation(Options.class); 27 | if (options != null) { 28 | var path = Path.of(options.path()[0]); 29 | for (int i = 1; i < options.path().length; i++) { 30 | path = path.resolve(options.path()[i]); 31 | } 32 | return path 33 | .resolve((options.name().isEmpty() ? value.getClass().getSimpleName() : options.name())); 34 | } 35 | return Path.of(value.getClass().getSimpleName()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/dev/httpmarco/aeon/reflections/AeonReflections.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Aeon contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.httpmarco.aeon.reflections; 18 | 19 | import java.util.List; 20 | import lombok.SneakyThrows; 21 | import sun.misc.Unsafe; 22 | 23 | import java.lang.reflect.Field; 24 | 25 | public final class AeonReflections { 26 | 27 | @SuppressWarnings("sunapi") 28 | private static final Unsafe unsafe; 29 | private static final List> ELEMENTS = List.of(String.class, Integer.class, 30 | Boolean.class, Short.class, Float.class, Byte.class, Double.class, Long.class); 31 | 32 | static { 33 | try { 34 | var field = Unsafe.class.getDeclaredField("theUnsafe"); 35 | field.setAccessible(true); 36 | unsafe = (Unsafe) field.get(null); 37 | } catch (NoSuchFieldException | IllegalAccessException e) { 38 | throw new RuntimeException(e); 39 | } 40 | } 41 | 42 | @SuppressWarnings("unchecked") 43 | public static T allocate(Class tClass) { 44 | try { 45 | return (T) unsafe.allocateInstance(tClass); 46 | } catch (InstantiationException e) { 47 | throw new RuntimeException(e); 48 | } 49 | } 50 | 51 | public static void modify(Field field, Object object, Object value) { 52 | try { 53 | field.setAccessible(true); 54 | field.set(object, value); 55 | } catch (IllegalAccessException e) { 56 | e.printStackTrace(); 57 | } 58 | } 59 | 60 | public static boolean isDefaultElement(Class type) { 61 | return ELEMENTS.contains(type); 62 | } 63 | 64 | @SneakyThrows 65 | public static Object get(Field field, Object object) { 66 | field.setAccessible(true); 67 | return field.get(object); 68 | } 69 | } 70 | --------------------------------------------------------------------------------