From 6f3918c6b956de996d6a8e673d734789a99bd50e Mon Sep 17 00:00:00 2001
From: water <672684719@qq.com>
Date: Fri, 24 Jul 2026 23:58:56 +0800
Subject: [PATCH] feat: Java/Kotlin lh_standard_adapter for Maven Central
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Implement the LongHun Standard Adapter in Java with Kotlin-friendly
annotations. Full port of the Python reference implementation.
- LongHunAdapter: main wrapper class (wrap, validate, getSchemas)
- DNAGenerator: v∞ DNA traceability with stem-branch + I Ching
- AuditWrapper: seven-factor behavioral audit logging
- Validator: full validation (DNA regex, audit structure, UID, sigma)
- ValidationResult: immutable result with errors/warnings/summary
- Schemas: JSON Schema definitions for DNA and Audit formats
- 99 JUnit 5 tests (4 test classes)
- Maven project with Jackson, JUnit 5, jsr305
- Javadoc on all public methods
- Kotlin-friendly (null-safety annotations)
Closes #4
---
adapters/java/LICENSE | 437 ++++++++++++++++++
adapters/java/README.md | 174 +++++++
adapters/java/pom.xml | 112 +++++
.../java/cn/uid9622/longhun/AuditWrapper.java | 268 +++++++++++
.../java/cn/uid9622/longhun/DNAGenerator.java | 259 +++++++++++
.../cn/uid9622/longhun/LongHunAdapter.java | 280 +++++++++++
.../main/java/cn/uid9622/longhun/Schemas.java | 234 ++++++++++
.../cn/uid9622/longhun/ValidationResult.java | 117 +++++
.../java/cn/uid9622/longhun/Validator.java | 332 +++++++++++++
.../java/cn/uid9622/longhun/package-info.java | 17 +
.../cn/uid9622/longhun/AuditWrapperTest.java | 299 ++++++++++++
.../cn/uid9622/longhun/DNAGeneratorTest.java | 232 ++++++++++
.../uid9622/longhun/LongHunAdapterTest.java | 319 +++++++++++++
.../cn/uid9622/longhun/ValidatorTest.java | 339 ++++++++++++++
14 files changed, 3419 insertions(+)
create mode 100644 adapters/java/LICENSE
create mode 100644 adapters/java/README.md
create mode 100644 adapters/java/pom.xml
create mode 100644 adapters/java/src/main/java/cn/uid9622/longhun/AuditWrapper.java
create mode 100644 adapters/java/src/main/java/cn/uid9622/longhun/DNAGenerator.java
create mode 100644 adapters/java/src/main/java/cn/uid9622/longhun/LongHunAdapter.java
create mode 100644 adapters/java/src/main/java/cn/uid9622/longhun/Schemas.java
create mode 100644 adapters/java/src/main/java/cn/uid9622/longhun/ValidationResult.java
create mode 100644 adapters/java/src/main/java/cn/uid9622/longhun/Validator.java
create mode 100644 adapters/java/src/main/java/cn/uid9622/longhun/package-info.java
create mode 100644 adapters/java/src/test/java/cn/uid9622/longhun/AuditWrapperTest.java
create mode 100644 adapters/java/src/test/java/cn/uid9622/longhun/DNAGeneratorTest.java
create mode 100644 adapters/java/src/test/java/cn/uid9622/longhun/LongHunAdapterTest.java
create mode 100644 adapters/java/src/test/java/cn/uid9622/longhun/ValidatorTest.java
diff --git a/adapters/java/LICENSE b/adapters/java/LICENSE
new file mode 100644
index 0000000..af1380a
--- /dev/null
+++ b/adapters/java/LICENSE
@@ -0,0 +1,437 @@
+1|Attribution-NonCommercial-ShareAlike 4.0 International
+2|
+3|=======================================================================
+4|
+5|Creative Commons Corporation ("Creative Commons") is not a law firm and
+6|does not provide legal services or legal advice. Distribution of
+7|Creative Commons public licenses does not create a lawyer-client or
+8|other relationship. Creative Commons makes its licenses and related
+9|information available on an "as-is" basis. Creative Commons gives no
+10|warranties regarding its licenses, any material licensed under their
+11|terms and conditions, or any related information. Creative Commons
+12|disclaims all liability for damages resulting from their use to the
+13|fullest extent possible.
+14|
+15|Using Creative Commons Public Licenses
+16|
+17|Creative Commons public licenses provide a standard set of terms and
+18|conditions that creators and other rights holders may use to share
+19|original works of authorship and other material subject to copyright
+20|and certain other rights specified in the public license below. The
+21|following considerations are for informational purposes only, are not
+22|exhaustive, and do not form part of our licenses.
+23|
+24| Considerations for licensors: Our public licenses are
+25| intended for use by those authorized to give the public
+26| permission to use material in ways otherwise restricted by
+27| copyright and certain other rights. Our licenses are
+28| irrevocable. Licensors should read and understand the terms
+29| and conditions of the license they choose before applying it.
+30| Licensors should also secure all rights necessary before
+31| applying our licenses so that the public can reuse the
+32| material as expected. Licensors should clearly mark any
+33| material not subject to the license. This includes other CC-
+34| licensed material, or material used under an exception or
+35| limitation to copyright. More considerations for licensors:
+36| wiki.creativecommons.org/Considerations_for_licensors
+37|
+38| Considerations for the public: By using one of our public
+39| licenses, a licensor grants the public permission to use the
+40| licensed material under specified terms and conditions. If
+41| the licensor's permission is not necessary for any reason--for
+42| example, because of any applicable exception or limitation to
+43| copyright--then that use is not regulated by the license. Our
+44| licenses grant only permissions under copyright and certain
+45| other rights that a licensor has authority to grant. Use of
+46| the licensed material may still be restricted for other
+47| reasons, including because others have copyright or other
+48| rights in the material. A licensor may make special requests,
+49| such as asking that all changes be marked or described.
+50| Although not required by our licenses, you are encouraged to
+51| respect those requests where reasonable. More considerations
+52| for the public:
+53| wiki.creativecommons.org/Considerations_for_licensees
+54|
+55|=======================================================================
+56|
+57|Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
+58|Public License
+59|
+60|By exercising the Licensed Rights (defined below), You accept and agree
+61|to be bound by the terms and conditions of this Creative Commons
+62|Attribution-NonCommercial-ShareAlike 4.0 International Public License
+63|("Public License"). To the extent this Public License may be
+64|interpreted as a contract, You are granted the Licensed Rights in
+65|consideration of Your acceptance of these terms and conditions, and the
+66|Licensor grants You such rights in consideration of benefits the
+67|Licensor receives from making the Licensed Material available under
+68|these terms and conditions.
+69|
+70|
+71|Section 1 -- Definitions.
+72|
+73| a. Adapted Material means material subject to Copyright and Similar
+74| Rights that is derived from or based upon the Licensed Material
+75| and in which the Licensed Material is translated, altered,
+76| arranged, transformed, or otherwise modified in a manner requiring
+77| permission under the Copyright and Similar Rights held by the
+78| Licensor. For purposes of this Public License, where the Licensed
+79| Material is a musical work, performance, or sound recording,
+80| Adapted Material is always produced where the Licensed Material is
+81| synched in timed relation with a moving image.
+82|
+83| b. Adapter's License means the license You apply to Your Copyright
+84| and Similar Rights in Your contributions to Adapted Material in
+85| accordance with the terms and conditions of this Public License.
+86|
+87| c. BY-NC-SA Compatible License means a license listed at
+88| creativecommons.org/compatiblelicenses, approved by Creative
+89| Commons as essentially the equivalent of this Public License.
+90|
+91| d. Copyright and Similar Rights means copyright and/or similar rights
+92| closely related to copyright including, without limitation,
+93| performance, broadcast, sound recording, and Sui Generis Database
+94| Rights, without regard to how the rights are labeled or
+95| categorized. For purposes of this Public License, the rights
+96| specified in Section 2(b)(1)-(2) are not Copyright and Similar
+97| Rights.
+98|
+99| e. Effective Technological Measures means those measures that, in the
+100| absence of proper authority, may not be circumvented under laws
+101| fulfilling obligations under Article 11 of the WIPO Copyright
+102| Treaty adopted on December 20, 1996, and/or similar international
+103| agreements.
+104|
+105| f. Exceptions and Limitations means fair use, fair dealing, and/or
+106| any other exception or limitation to Copyright and Similar Rights
+107| that applies to Your use of the Licensed Material.
+108|
+109| g. License Elements means the license attributes listed in the name
+110| of a Creative Commons Public License. The License Elements of this
+111| Public License are Attribution, NonCommercial, and ShareAlike.
+112|
+113| h. Licensed Material means the artistic or literary work, database,
+114| or other material to which the Licensor applied this Public
+115| License.
+116|
+117| i. Licensed Rights means the rights granted to You subject to the
+118| terms and conditions of this Public License, which are limited to
+119| all Copyright and Similar Rights that apply to Your use of the
+120| Licensed Material and that the Licensor has authority to license.
+121|
+122| j. Licensor means the individual(s) or entity(ies) granting rights
+123| under this Public License.
+124|
+125| k. NonCommercial means not primarily intended for or directed towards
+126| commercial advantage or monetary compensation. For purposes of
+127| this Public License, the exchange of the Licensed Material for
+128| other material subject to Copyright and Similar Rights by digital
+129| file-sharing or similar means is NonCommercial provided there is
+130| no payment of monetary compensation in connection with the
+131| exchange.
+132|
+133| l. Share means to provide material to the public by any means or
+134| process that requires permission under the Licensed Rights, such
+135| as reproduction, public display, public performance, distribution,
+136| dissemination, communication, or importation, and to make material
+137| available to the public including in ways that members of the
+138| public may access the material from a place and at a time
+139| individually chosen by them.
+140|
+141| m. Sui Generis Database Rights means rights other than copyright
+142| resulting from Directive 96/9/EC of the European Parliament and of
+143| the Council of 11 March 1996 on the legal protection of databases,
+144| as amended and/or succeeded, as well as other essentially
+145| equivalent rights anywhere in the world.
+146|
+147| n. You means the individual or entity exercising the Licensed Rights
+148| under this Public License. Your has a corresponding meaning.
+149|
+150|
+151|Section 2 -- Scope.
+152|
+153| a. License grant.
+154|
+155| 1. Subject to the terms and conditions of this Public License,
+156| the Licensor hereby grants You a worldwide, royalty-free,
+157| non-sublicensable, non-exclusive, irrevocable license to
+158| exercise the Licensed Rights in the Licensed Material to:
+159|
+160| a. reproduce and Share the Licensed Material, in whole or
+161| in part, for NonCommercial purposes only; and
+162|
+163| b. produce, reproduce, and Share Adapted Material for
+164| NonCommercial purposes only.
+165|
+166| 2. Exceptions and Limitations. For the avoidance of doubt, where
+167| Exceptions and Limitations apply to Your use, this Public
+168| License does not apply, and You do not need to comply with
+169| its terms and conditions.
+170|
+171| 3. Term. The term of this Public License is specified in Section
+172| 6(a).
+173|
+174| 4. Media and formats; technical modifications allowed. The
+175| Licensor authorizes You to exercise the Licensed Rights in
+176| all media and formats whether now known or hereafter created,
+177| and to make technical modifications necessary to do so. The
+178| Licensor waives and/or agrees not to assert any right or
+179| authority to forbid You from making technical modifications
+180| necessary to exercise the Licensed Rights, including
+181| technical modifications necessary to circumvent Effective
+182| Technological Measures. For purposes of this Public License,
+183| simply making modifications authorized by this Section 2(a)
+184| (4) never produces Adapted Material.
+185|
+186| 5. Downstream recipients.
+187|
+188| a. Offer from the Licensor -- Licensed Material. Every
+189| recipient of the Licensed Material automatically
+190| receives an offer from the Licensor to exercise the
+191| Licensed Rights under the terms and conditions of this
+192| Public License.
+193|
+194| b. Additional offer from the Licensor -- Adapted Material.
+195| Every recipient of Adapted Material from You
+196| automatically receives an offer from the Licensor to
+197| exercise the Licensed Rights in the Adapted Material
+198| under the conditions of the Adapter's License You apply.
+199|
+200| c. No downstream restrictions. You may not offer or impose
+201| any additional or different terms or conditions on, or
+202| apply any Effective Technological Measures to, the
+203| Licensed Material if doing so restricts exercise of the
+204| Licensed Rights by any recipient.
+205|
+206| 6. No endorsement. Nothing in this Public License constitutes or
+207| may be construed as permission to assert or imply that You
+208| are, or that Your use of the Licensed Material is, connected
+209| with, or sponsored, or endorsed by, or granted official status
+210| by, the Licensor or others designated to receive attribution
+211| as provided in Section 3(a)(1)(A)(i).
+212|
+213| b. Other rights.
+214|
+215| 1. Moral rights, such as the right of integrity, are not
+216| licensed under this Public License, nor are publicity,
+217| privacy, and/or other similar personality rights; however, to
+218| the extent possible, the Licensor waives and/or agrees not to
+219| assert any such rights held by the Licensor to the limited
+220| extent necessary to allow You to exercise the Licensed
+221| Rights, but not otherwise.
+222|
+223| 2. Patent and trademark rights are not licensed under this
+224| Public License.
+225|
+226| 3. To the extent possible, the Licensor waives any right to
+227| collect royalties from You for the exercise of the Licensed
+228| Rights, whether directly or through a collecting society under
+229| any voluntary or waivable statutory or compulsory licensing
+230| scheme. In all other cases the Licensor expressly reserves
+231| any right to collect such royalties, including when the
+232| Licensed Material is used other than for NonCommercial
+233| purposes.
+234|
+235|
+236|Section 3 -- License Conditions.
+237|
+238|Your exercise of the Licensed Rights is expressly made subject to the
+239|following conditions.
+240|
+241| a. Attribution.
+242|
+243| 1. If You Share the Licensed Material (including in modified
+244| form), You must:
+245|
+246| a. retain the following if it is supplied by the Licensor
+247| with the Licensed Material:
+248|
+249| i. identification of the creator(s) of the Licensed
+250| Material and any others designated to receive
+251| attribution, in any reasonable manner requested by
+252| the Licensor (including by pseudonym if designated);
+253|
+254| ii. a copyright notice;
+255|
+256| iii. a notice that refers to this Public License;
+257|
+258| iv. a notice that refers to the disclaimer of
+259| warranties;
+260|
+261| v. a URI or hyperlink to the Licensed Material to the
+262| extent reasonably practicable;
+263|
+264| b. indicate if You modified the Licensed Material and
+265| retain an indication of any previous modifications; and
+266|
+267| c. indicate the Licensed Material is licensed under this
+268| Public License, and include the text of, or the URI or
+269| hyperlink to, this Public License.
+270|
+271| 2. You may satisfy the conditions in Section 3(a)(1) in any
+272| reasonable manner based on the medium, means, and context in
+273| which You Share the Licensed Material. For example, it may be
+274| reasonable to satisfy the conditions by providing a URI or
+275| hyperlink to a resource that includes the required
+276| information.
+277|
+278| 3. If requested by the Licensor, You must remove any of the
+279| information required by Section 3(a)(1)(A) to the extent
+280| reasonably practicable.
+281|
+282| b. ShareAlike.
+283|
+284| In addition to the conditions in Section 3(a), if You Share
+285| Adapted Material You produce, the following conditions also apply.
+286|
+287| 1. The Adapter's License You apply must be a Creative Commons
+288| license with the same License Elements, this version or
+289| later, or a BY-NC-SA Compatible License.
+290|
+291| 2. You must include the text of, or the URI or hyperlink to, the
+292| Adapter's License You apply. You may satisfy this condition
+293| in any reasonable manner based on the medium, means, and
+294| context in which You Share Adapted Material.
+295|
+296| 3. You may not offer or impose any additional or different terms
+297| or conditions on, or apply any Effective Technological
+298| Measures to, Adapted Material that restrict exercise of the
+299| rights granted under the Adapter's License You apply.
+300|
+301|
+302|Section 4 -- Sui Generis Database Rights.
+303|
+304|Where the Licensed Rights include Sui Generis Database Rights that
+305|apply to Your use of the Licensed Material:
+306|
+307| a. for the avoidance of doubt, Section 2(a)(1) grants You the right
+308| to extract, reuse, reproduce, and Share all or a substantial
+309| portion of the contents of the database for NonCommercial purposes
+310| only;
+311|
+312| b. if You include all or a substantial portion of the database
+313| contents in a database in which You have Sui Generis Database
+314| Rights, then the database in which You have Sui Generis Database
+315| Rights (but not its individual contents) is Adapted Material,
+316|
+317| including for purposes of Section 3(b); and
+318| c. You must comply with the conditions in Section 3(a) if You Share
+319| all or a substantial portion of the contents of the database.
+320|
+321|For the avoidance of doubt, this Section 4 supplements and does not
+322|replace Your obligations under this Public License where the Licensed
+323|Rights include other Copyright and Similar Rights.
+324|
+325|
+326|Section 5 -- Disclaimer of Warranties and Limitation of Liability.
+327|
+328| a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
+329| EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
+330| AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
+331| ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
+332| IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
+333| WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
+334| PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
+335| ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
+336| KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
+337| FULLY ALLOWED IN PART OR IN WHOLE, THIS DISCLAIMER MAY NOT APPLY
+338| TO YOU.
+339|
+340| b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
+341| TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
+342| NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
+343| INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
+344| COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
+345| USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
+346| ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
+347| DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT FULLY ALLOWED IN
+348| PART OR IN WHOLE, THIS LIMITATION MAY NOT APPLY TO YOU.
+349|
+350| c. The disclaimer of warranties and limitation of liability provided
+351| above shall be interpreted in a manner that, to the extent
+352| possible, most closely approximates an absolute disclaimer and
+353| waiver of all liability.
+354|
+355|
+356|Section 6 -- Term and Termination.
+357|
+358| a. This Public License applies for the term of the Copyright and
+359| Similar Rights licensed here. However, if You fail to comply with
+360| this Public License, then Your rights under this Public License
+361| terminate automatically.
+362|
+363| b. Where Your right to use the Licensed Material has terminated under
+364| Section 6(a), it reinstates:
+365|
+366| 1. automatically as of the date the violation is cured, provided
+367| it is cured within 30 days of Your discovery of the
+368| violation; or
+369|
+370| 2. upon express reinstatement by the Licensor.
+371|
+372| For the avoidance of doubt, this Section 6(b) does not affect any
+373| right the Licensor may have to seek remedies for Your violations
+374| of this Public License.
+375|
+376| c. For the avoidance of doubt, the Licensor may also offer the
+377| Licensed Material under separate terms or conditions or stop
+378| distributing the Licensed Material at any time; however, doing so
+379| will not terminate this Public License.
+380|
+381| d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
+382| License.
+383|
+384|
+385|Section 7 -- Other Terms and Conditions.
+386|
+387| a. The Licensor shall not be bound by any additional or different
+388| terms or conditions communicated by You unless expressly agreed.
+389|
+390| b. Any arrangements, understandings, or agreements regarding the
+391| Licensed Material not stated herein are separate from and
+392| independent of the terms and conditions of this Public License.
+393|
+394|
+395|Section 8 -- Interpretation.
+396|
+397| a. For the avoidance of doubt, this Public License does not, and
+398| shall not be interpreted to, reduce, limit, restrict, or impose
+399| conditions on any use of the Licensed Material that could lawfully
+400| be made without permission under this Public License.
+401|
+402| b. To the extent possible, if any provision of this Public License is
+403| held to be unenforceable, it shall be automatically reformed to the
+404| minimum extent necessary to make it enforceable. If the provision
+405| cannot be reformed, it shall be severed from this Public License
+406| without affecting the enforceability of the remaining terms and
+407| conditions.
+408|
+409| c. No term or condition of this Public License will be waived and no
+410| failure to comply consented to unless expressly agreed to by the
+411| Licensor.
+412|
+413| d. Nothing in this Public License constitutes or may be interpreted
+414| as a limitation upon, or waiver of, any privileges and immunities
+415| that apply to the Licensor or You, including from the legal
+416| processes of any jurisdiction or authority.
+417|
+418|=======================================================================
+419|
+420|Creative Commons is not a party to its public
+421|licenses. Notwithstanding, Creative Commons may elect to apply one of
+422|its public licenses to material it publishes and in those instances
+423|will be considered the "Licensor." The text of the Creative Commons
+424|public licenses is dedicated to the public domain under the CC0 Public
+425|Domain Dedication. Except for the limited purpose of indicating that
+426|material is shared under a Creative Commons public license or as
+427|otherwise permitted by the Creative Commons policies published at
+428|creativecommons.org/policies, Creative Commons does not authorize the
+429|use of the trademark "Creative Commons" or any other trademark or logo
+430|of Creative Commons without its prior written consent including,
+431|without limitation, in connection with any unauthorized modifications
+432|to any of its public licenses or any other arrangements,
+433|understandings, or agreements concerning use of licensed material. For
+434|the avoidance of doubt, this paragraph does not form part of the
+435|public licenses.
+436|
+437|=======================================================================
\ No newline at end of file
diff --git a/adapters/java/README.md b/adapters/java/README.md
new file mode 100644
index 0000000..fb94af0
--- /dev/null
+++ b/adapters/java/README.md
@@ -0,0 +1,174 @@
+1|# LongHun Standard Adapter — Java / Kotlin
+2|
+3|> DNA: `#LongHun⚡️BingWu·GuiWei·JiaZi·ZiShi·䷾JiJi-ADAPTER-JAVA-v1.0.0`
+4|> Author: LongHun Core · UID9622 · 龍芯北辰
+5|> License: [CC BY-NC-SA 4.0](LICENSE)
+6|> Java Version: 8+ (JDK 1.8 compatible)
+7|
+8|**Open the standard. Guard the engine.**
+9|
+10|This is the Java/Kotlin implementation of the LongHun Standard Adapter.
+11|It wraps JSON payloads with DNA traceability codes and seven-factor behavioral audit metadata,
+12|following the [AI Traceability and Audit Protocol v1.0](../docs/AI-Traceability-Audit-Protocol-v1.0.md).
+13|
+14|## Features
+15|
+16|- ✅ **DNA Traceability (v∞ format)** — SHA-256 anchored, stem-branch + I Ching hexagram codes
+17|- ✅ **Seven-Factor Behavioral Audit** — P, F, T, E, C, R, A, X, Y, Z signature
+18|- ✅ **Behavior Pattern Classification** — 5 patterns (StableDisciplined, DefensiveDefaulter, etc.)
+19|- ✅ **Three-Color Audit** — 🟢 Green, 🟡 Yellow, 🔴 Red
+20|- ✅ **Bilingual Labels** — Chinese + English behavior labels
+21|- ✅ **Full Validation** — DNA regex, audit structure, signature values, UID consistency
+22|- ✅ **Kotlin-Friendly** — Null-safety annotations (`@Nonnull`, `@Nullable`), immutable data classes
+23|- ✅ **72+ JUnit 5 Tests** — Comprehensive coverage
+24|- ✅ **Java 8 Compatible** — Works with JDK 1.8+
+25|
+26|## Maven
+27|
+28|Add this dependency to your `pom.xml`:
+29|
+30|```xml
+31|
+32| cn.uid9622.longhun
+33| lh-standard-adapter
+34| 1.0.0
+35|
+36|```
+37|
+38|## Java Usage
+39|
+40|### Basic Wrapping
+41|
+42|```java
+43|import cn.uid9622.longhun.LongHunAdapter;
+44|import cn.uid9622.longhun.ValidationResult;
+45|import com.fasterxml.jackson.databind.node.ObjectNode;
+46|
+47|LongHunAdapter adapter = new LongHunAdapter("9622", "HM-9622-001");
+48|
+49|// Wrap any JSON-serializable data
+50|ObjectNode result = adapter.wrap(
+51| Map.of("code", "print('hello')"),
+52| "code",
+53| "P04-Luban"
+54|);
+55|
+56|// Access the DNA traceability code
+57|String dna = result.get("dna").asText();
+58|// → "#LongHun⚡️BingWu·GuiWei·JiaZi·WeiShi·䷾JiJi-ADAPTER-CODE-WRAP-V1.0-a3f8c1d9"
+59|
+60|// Access the audit metadata
+61|String pattern = result.get("audit").get("behavior_pattern").asText();
+62|// → "MODE-StableDisciplined"
+63|
+64|// Validate the wrapped payload
+65|ValidationResult validation = adapter.validate(result);
+66|if (validation.isValid()) {
+67| System.out.println("✅ Valid: " + validation.getSummary());
+68|}
+69|```
+70|
+71|### Getting Schemas
+72|
+73|```java
+74|Map schemas = adapter.getSchemas();
+75|Map dnaSchema = (Map) schemas.get("dna_schema");
+76|Map auditSchema = (Map) schemas.get("audit_schema");
+77|```
+78|
+79|### Customizing Action and Version
+80|
+81|```java
+82|ObjectNode result = adapter.wrap(data, "deploy", "P14-Lvmeng", "DEPLOY", "v2.0");
+83|```
+84|
+85|## Kotlin Usage
+86|
+87|```kotlin
+88|import cn.uid9622.longhun.LongHunAdapter
+89|
+90|val adapter = LongHunAdapter("9622", "HM-9622-001")
+91|val result = adapter.wrap(mapOf("code" to "print('hello')"), "code", "P04-Luban")
+92|val validation = adapter.validate(result)
+93|
+94|println(result["dna"]) // DNA traceability code
+95|println(result["audit"]["behavior_pattern"]) // Behavior pattern
+96|println(validation.summary) // Validation summary
+97|```
+98|
+99|## Building
+100|
+101|```bash
+102|cd adapters/java
+103|mvn clean package
+104|```
+105|
+106|## Running Tests
+107|
+108|```bash
+109|cd adapters/java
+110|mvn test
+111|```
+112|
+113|## API Reference
+114|
+115|### `LongHunAdapter`
+116|
+117|| Method | Returns | Description |
+118||--------|---------|-------------|
+119|| `LongHunAdapter(String uid, String device)` | — | Constructor with default locale |
+120|| `LongHunAdapter(String uid, String device, String locale)` | — | Constructor with custom timezone |
+121|| `wrap(Object data, String taskType, String persona)` | `ObjectNode` | Wrap payload with DNA + audit |
+122|| `wrap(Object data, String taskType, String persona, String action, String version)` | `ObjectNode` | Wrap with custom action/version |
+123|| `validate(ObjectNode wrapped)` | `ValidationResult` | Validate wrapped payload |
+124|| `getSchemas()` | `Map` | Get JSON Schema definitions |
+125|
+126|### `ValidationResult`
+127|
+128|| Method | Returns | Description |
+129||--------|---------|-------------|
+130|| `isValid()` | `boolean` | Whether validation passed |
+131|| `getErrors()` | `List` | Validation error messages |
+132|| `getWarnings()` | `List` | Validation warning messages |
+133|| `getSummary()` | `String` | Human-readable summary |
+134|
+135|## Project Structure
+136|
+137|```
+138|adapters/java/
+139|├── pom.xml
+140|├── LICENSE
+141|├── README.md
+142|└── src/
+143| ├── main/java/cn/uid9622/longhun/
+144| │ ├── LongHunAdapter.java # Main adapter class
+145| │ ├── DNAGenerator.java # DNA traceability code generation
+146| │ ├── AuditWrapper.java # Seven-factor audit wrapping
+147| │ ├── Validator.java # Payload validation
+148| │ ├── ValidationResult.java # Immutable validation result
+149| │ └── Schemas.java # JSON Schema definitions
+150| └── test/java/cn/uid9622/longhun/
+151| ├── LongHunAdapterTest.java
+152| ├── DNAGeneratorTest.java
+153| ├── AuditWrapperTest.java
+154| └── ValidatorTest.java
+155|```
+156|
+157|## License
+158|
+159|This project is licensed under [CC BY-NC-SA 4.0](LICENSE) — Attribution-NonCommercial-ShareAlike 4.0 International.
+160|
+161|## Cross-Validation
+162|
+163|The Java implementation is cross-validated against the Python reference implementation
+164|at `lh_standard_adapter/`. All tests produce identical output structure and validation logic.
+165|
+166|## DNA
+167|
+168|```
+169|#LongHun⚡️BingWu·GuiWei·JiaZi·ZiShi·䷾JiJi-ADAPTER-JAVA-v1.0.0
+170|```
+171|
+172|---
+173|
+174|*Open the standard. Guard the engine.*
\ No newline at end of file
diff --git a/adapters/java/pom.xml b/adapters/java/pom.xml
new file mode 100644
index 0000000..acc6c4a
--- /dev/null
+++ b/adapters/java/pom.xml
@@ -0,0 +1,112 @@
+1|
+2|
+5| 4.0.0
+6|
+7| cn.uid9622.longhun
+8| lh-standard-adapter
+9| 1.0.0
+10| jar
+11|
+12| LongHun Standard Adapter
+13| Java/Kotlin implementation of the LongHun standard adapter – wrap JSON payloads with DNA traceability and seven-factor behavioral audit metadata.
+14| https://github.com/UID9622/lh-standard-adapter
+15|
+16|
+17|
+18| CC BY-NC-SA 4.0
+19| https://creativecommons.org/licenses/by-nc-sa/4.0/
+20|
+21|
+22|
+23|
+24|
+25| LongHun Core · UID9622 · 龍芯北辰
+26| core@uid9622.cn
+27|
+28|
+29|
+30|
+31| 1.8
+32| 1.8
+33| UTF-8
+34| 2.15.3
+35| 5.10.0
+36|
+37|
+38|
+39|
+40|
+41| com.fasterxml.jackson.core
+42| jackson-databind
+43| ${jackson.version}
+44|
+45|
+46| com.fasterxml.jackson.core
+47| jackson-core
+48| ${jackson.version}
+49|
+50|
+51| com.fasterxml.jackson.core
+52| jackson-annotations
+53| ${jackson.version}
+54|
+55|
+56|
+57|
+58| org.junit.jupiter
+59| junit-jupiter
+60| ${junit.version}
+61| test
+62|
+63|
+64|
+65|
+66| com.google.code.findbugs
+67| jsr305
+68| 3.0.2
+69| true
+70|
+71|
+72|
+73|
+74|
+75|
+76| org.apache.maven.plugins
+77| maven-compiler-plugin
+78| 3.11.0
+79|
+80| 1.8
+81| 1.8
+82| UTF-8
+83|
+84|
+85|
+86| org.apache.maven.plugins
+87| maven-surefire-plugin
+88| 3.2.3
+89|
+90|
+91| **/*Test.java
+92|
+93|
+94|
+95|
+96| org.apache.maven.plugins
+97| maven-javadoc-plugin
+98| 3.6.0
+99|
+100| 1.8
+101| UTF-8
+102| none
+103|
+104|
+105|
+106| org.apache.maven.plugins
+107| maven-source-plugin
+108| 3.3.0
+109|
+110|
+111|
+112|
\ No newline at end of file
diff --git a/adapters/java/src/main/java/cn/uid9622/longhun/AuditWrapper.java b/adapters/java/src/main/java/cn/uid9622/longhun/AuditWrapper.java
new file mode 100644
index 0000000..c12a2c4
--- /dev/null
+++ b/adapters/java/src/main/java/cn/uid9622/longhun/AuditWrapper.java
@@ -0,0 +1,268 @@
+1|package cn.uid9622.longhun;
+2|
+3|import javax.annotation.Nonnull;
+4|import java.nio.charset.StandardCharsets;
+5|import java.security.MessageDigest;
+6|import java.security.NoSuchAlgorithmException;
+7|import java.time.ZoneId;
+8|import java.time.ZonedDateTime;
+9|import java.time.format.DateTimeFormatter;
+10|import java.util.*;
+11|
+12|/**
+13| * Wraps payloads with seven-factor behavioral audit metadata.
+14| *
+15| *
Core scoring algorithms (weights, neural network logic) are
+16| * protected engine components and NOT included in this open shell.
+17| *
+18| *
DNA: #LongHun⚡️BingWu·GuiWei·JiaZi·ZiShi·䷝Li-AUDIT-WRAPPER-v1.0.0
+19| *
+20| * @since 1.0.0
+21| */
+22|public final class AuditWrapper {
+23|
+24| // --- Seven-Factor Value Sets ---
+25| private static final Set P_VALUES = setOf("HasPromise", "NoPromise");
+26| private static final Set F_VALUES = setOf("Fulfilled", "Unfulfilled", "Partial");
+27| private static final Set E_VALUES = setOf("Willing", "Perfunctory", "Resentful", "Numb");
+28| private static final Set A_VALUES = setOf("Self", "Partner", "Family", "Outsider", "Public");
+29| private static final Set X_VALUES = setOf("OverExplain", "Silent", "Genuine", "Indifferent");
+30| private static final Set Y_VALUES = setOf("Changed", "Resisted", "Indifferent", "NoResponse");
+31|
+32| // --- Behavior Pattern Classification ---
+33| private static final Map PATTERNS = new LinkedHashMap<>();
+34|
+35| static {
+36| PATTERNS.put("MODE-DefensiveDefaulter", "Promises fail + over-explains to deflect");
+37| PATTERNS.put("MODE-ExternalTrustSpender", "Keeps promises to outsiders at inner-circle expense");
+38| PATTERNS.put("MODE-InternalDestroyer", "Breaks promises with indifference, no correction");
+39| PATTERNS.put("MODE-Fluctuating", "High volatility in commitment-to-fulfillment ratio");
+40| PATTERNS.put("MODE-StableDisciplined", "Consistent, reliable execution");
+41| }
+42|
+43| // --- Factor → Label Mapping (bilingual) ---
+44| private static final Map> LABEL_MAP = new LinkedHashMap<>();
+45|
+46| static {
+47| LABEL_MAP.put("P", mapOf("HasPromise", "7F-P-有承诺", "NoPromise", "7F-P-无承诺"));
+48| LABEL_MAP.put("F", mapOf("Fulfilled", "7F-F-已兑现", "Unfulfilled", "7F-F-未兑现", "Partial", "7F-F-部分兑现"));
+49| LABEL_MAP.put("E", mapOf("Willing", "7F-E-心甘情愿", "Perfunctory", "7F-E-敷衍", "Resentful", "7F-E-怨恨", "Numb", "7F-E-麻木"));
+50| LABEL_MAP.put("A", mapOf("Self", "7F-A-自己", "Partner", "7F-A-伴侣", "Family", "7F-A-家庭", "Outsider", "7F-A-外人", "Public", "7F-A-公众"));
+51| LABEL_MAP.put("X", mapOf("OverExplain", "7F-X-过度解释", "Silent", "7F-X-沉默", "Genuine", "7F-X-真诚", "Indifferent", "7F-X-冷漠"));
+52| LABEL_MAP.put("Y", mapOf("Changed", "7F-Y-改正", "Resisted", "7F-Y-抗拒", "Indifferent", "7F-Y-无视", "NoResponse", "7F-Y-无响应"));
+53| }
+54|
+55| private final String uid;
+56|
+57| /**
+58| * Creates a new {@code AuditWrapper}.
+59| *
+60| * @param uid user identifier (e.g., "9622")
+61| */
+62| public AuditWrapper(String uid) {
+63| this.uid = Objects.requireNonNull(uid, "uid must not be null");
+64| }
+65|
+66| /**
+67| * Generates the audit wrapper with seven-factor signature.
+68| *
+69| * @param payload raw data to wrap (must be JSON-serializable)
+70| * @param taskType task category (code, deploy, audit, default, etc.)
+71| * @param persona persona identifier (e.g., "P04", "P04-Luban")
+72| * @return map of audit metadata
+73| */
+74| @Nonnull
+75| public Map wrap(@Nonnull Object payload,
+76| @Nonnull String taskType,
+77| @Nonnull String persona) {
+78| Objects.requireNonNull(payload, "payload must not be null");
+79| Objects.requireNonNull(taskType, "taskType must not be null");
+80| Objects.requireNonNull(persona, "persona must not be null");
+81|
+82| ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
+83|
+84| // Default signature (StableDisciplined baseline)
+85| Map signature = new LinkedHashMap<>();
+86| signature.put("P", "HasPromise");
+87| signature.put("F", "Fulfilled");
+88| signature.put("T", 0.0);
+89| signature.put("E", "Willing");
+90| signature.put("C", 0);
+91| signature.put("R", 0);
+92| signature.put("A", "Self");
+93| signature.put("X", "Genuine");
+94| signature.put("Y", "NoResponse");
+95| signature.put("Z", 1.0);
+96|
+97| String pattern = classify(signature);
+98| List labels = makeLabels(signature, pattern);
+99| String color = determineColor(pattern, (Integer) signature.get("R"));
+100|
+101| // Payload hash (not for crypto, for integrity check)
+102| String payloadJson = payload.toString(); // simplified; Jackson serialization happens upstream
+103| String payloadHash = sha256Hex(payloadJson).substring(0, 16);
+104|
+105| Map result = new LinkedHashMap<>();
+106| result.put("audit_version", "v1.0");
+107| result.put("uid", "UID" + uid);
+108| result.put("persona", persona);
+109| result.put("task_type", taskType);
+110| result.put("behavior_signature", signature);
+111| result.put("behavior_pattern", pattern);
+112| result.put("behavior_labels", labels);
+113| result.put("color", color);
+114| result.put("timestamp", now.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
+115| result.put("payload_hash", payloadHash);
+116|
+117| return result;
+118| }
+119|
+120| /**
+121| * Classifies a seven-factor signature into a behavior pattern.
+122| *
+123| * @param sig the behavior signature map
+124| * @return behavior pattern string (e.g., "MODE-StableDisciplined")
+125| */
+126| @Nonnull
+127| String classify(@Nonnull Map sig) {
+128| String fVal = (String) sig.getOrDefault("F", "");
+129| String xVal = (String) sig.getOrDefault("X", "");
+130| String aVal = (String) sig.getOrDefault("A", "");
+131| String yVal = (String) sig.getOrDefault("Y", "");
+132| Number zVal = (Number) sig.getOrDefault("Z", 1.0);
+133|
+134| if ("Unfulfilled".equals(fVal) && "OverExplain".equals(xVal)) {
+135| return "MODE-DefensiveDefaulter";
+136| }
+137| if ("Fulfilled".equals(fVal) && "Outsider".equals(aVal)) {
+138| return "MODE-ExternalTrustSpender";
+139| }
+140| if ("Unfulfilled".equals(fVal) && "Indifferent".equals(yVal)) {
+141| return "MODE-InternalDestroyer";
+142| }
+143| if (zVal.doubleValue() > 2.0) {
+144| return "MODE-Fluctuating";
+145| }
+146| return "MODE-StableDisciplined";
+147| }
+148|
+149| /**
+150| * Generates bilingual behavior labels from a signature.
+151| *
+152| * @param sig the behavior signature map
+153| * @param pattern the classified behavior pattern
+154| * @return list of bilingual label strings
+155| */
+156| @Nonnull
+157| List makeLabels(@Nonnull Map sig, @Nonnull String pattern) {
+158| List labels = new ArrayList<>();
+159| for (String factor : Arrays.asList("P", "F", "E", "A", "X", "Y")) {
+160| String val = (String) sig.get(factor);
+161| if (val != null) {
+162| Map factorLabels = LABEL_MAP.get(factor);
+163| if (factorLabels != null && factorLabels.containsKey(val)) {
+164| labels.add(factorLabels.get(val));
+165| }
+166| }
+167| }
+168| labels.add(pattern);
+169| return labels;
+170| }
+171|
+172| /**
+173| * Determines the three-color audit tag.
+174| *
+175| * @param pattern the behavior pattern
+176| * @param repeat repeat count (R)
+177| * @return color emoji string: 🟢, 🟡, or 🔴
+178| */
+179| @Nonnull
+180| String determineColor(@Nonnull String pattern, int repeat) {
+181| if ("MODE-InternalDestroyer".equals(pattern)) {
+182| return "\uD83D\uDD34"; // 🔴
+183| }
+184| if ("MODE-Fluctuating".equals(pattern) && repeat > 3) {
+185| return "\uD83D\uDFE1"; // 🟡
+186| }
+187| if ("MODE-DefensiveDefaulter".equals(pattern) && repeat > 2) {
+188| return "\uD83D\uDFE1"; // 🟡
+189| }
+190| return "\uD83D\uDFE2"; // 🟢
+191| }
+192|
+193| @Nonnull
+194| String getUid() {
+195| return uid;
+196| }
+197|
+198| @Nonnull
+199| static Set getPValues() {
+200| return P_VALUES;
+201| }
+202|
+203| @Nonnull
+204| static Set getFValues() {
+205| return F_VALUES;
+206| }
+207|
+208| @Nonnull
+209| static Set getEValues() {
+210| return E_VALUES;
+211| }
+212|
+213| @Nonnull
+214| static Set getAValues() {
+215| return A_VALUES;
+216| }
+217|
+218| @Nonnull
+219| static Set getXValues() {
+220| return X_VALUES;
+221| }
+222|
+223| @Nonnull
+224| static Set getYValues() {
+225| return Y_VALUES;
+226| }
+227|
+228| @Nonnull
+229| static Map getPatterns() {
+230| return PATTERNS;
+231| }
+232|
+233| @Nonnull
+234| static Map> getLabelMap() {
+235| return LABEL_MAP;
+236| }
+237|
+238| // --- Private helpers ---
+239|
+240| private static Set setOf(String... values) {
+241| Set set = new LinkedHashSet<>();
+242| Collections.addAll(set, values);
+243| return Collections.unmodifiableSet(set);
+244| }
+245|
+246| private static Map mapOf(String... entries) {
+247| Map map = new LinkedHashMap<>();
+248| for (int i = 0; i < entries.length; i += 2) {
+249| map.put(entries[i], entries[i + 1]);
+250| }
+251| return map;
+252| }
+253|
+254| @Nonnull
+255| private static String sha256Hex(@Nonnull String input) {
+256| try {
+257| MessageDigest md = MessageDigest.getInstance("SHA-256");
+258| byte[] digest = md.digest(input.getBytes(StandardCharsets.UTF_8));
+259| StringBuilder sb = new StringBuilder(64);
+260| for (byte b : digest) {
+261| sb.append(String.format("%02x", b & 0xff));
+262| }
+263| return sb.toString();
+264| } catch (NoSuchAlgorithmException e) {
+265| throw new RuntimeException("SHA-256 not available", e);
+266| }
+267| }
+268|}
\ No newline at end of file
diff --git a/adapters/java/src/main/java/cn/uid9622/longhun/DNAGenerator.java b/adapters/java/src/main/java/cn/uid9622/longhun/DNAGenerator.java
new file mode 100644
index 0000000..f097547
--- /dev/null
+++ b/adapters/java/src/main/java/cn/uid9622/longhun/DNAGenerator.java
@@ -0,0 +1,259 @@
+1|package cn.uid9622.longhun;
+2|
+3|import javax.annotation.Nonnull;
+4|import javax.annotation.Nullable;
+5|import java.nio.charset.StandardCharsets;
+6|import java.security.MessageDigest;
+7|import java.security.NoSuchAlgorithmException;
+8|import java.time.LocalDateTime;
+9|import java.time.ZoneId;
+10|import java.time.ZonedDateTime;
+11|import java.util.*;
+12|
+13|/**
+14| * Generates v∞ format DNA traceability codes for the LongHun standard.
+15| *
+16| *