{"id":16374987,"url":"https://github.com/moderocky/constantine","last_synced_at":"2026-03-31T16:30:16.654Z","repository":{"id":226933332,"uuid":"769929019","full_name":"Moderocky/Constantine","owner":"Moderocky","description":"A paradigm for constant conditions in Java.","archived":false,"fork":false,"pushed_at":"2025-02-05T21:31:39.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-05T22:37:14.136Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Moderocky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-10T13:12:35.000Z","updated_at":"2025-02-05T21:31:42.000Z","dependencies_parsed_at":"2024-04-02T12:45:25.538Z","dependency_job_id":"71a89c1d-18e6-4236-a23d-4b9c29cece2e","html_url":"https://github.com/Moderocky/Constantine","commit_stats":null,"previous_names":["moderocky/constantine"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FConstantine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FConstantine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FConstantine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moderocky%2FConstantine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Moderocky","download_url":"https://codeload.github.com/Moderocky/Constantine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239954693,"owners_count":19724286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T03:19:02.260Z","updated_at":"2026-03-31T16:30:16.599Z","avatar_url":"https://github.com/Moderocky.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Constantine\n=====\n\n### Opus #28\n\nA paradigm for constant conditions in Java.\n\n## Preamble\n\nJava lacks a true (or enforceable) idea of a constant.\nThe `final` keyword makes a variable immutable, but only in the sense that it cannot change its reference.\nThis having been said, a `final` variable is not necessarily a constant variable: it is unlikely to have constant\nconditions.\n\nFor example, we can assign a mutable list to a final variable and,\nwhile the list itself can't be swapped out with another, there are no restrictions on modifying its contents.\n\nEnter the constant: a thing made entirely of constants. The constant is not just immutable,\nit's constant right down to the primitive level, constant to the bone.\nIt is a thing constructed entirely from (constructions of) raw data and, as such, it can be represented as\n-- and reconstructed from -- that raw data.\n\nThis means that a constant is able to be stored (in its deconstructed form) in the class file constant pool,\ntherefore it is something that _has the potential to be_ a language-level literal.\n\n## Provided Resources\n\nConstantine provides two kinds of resource: the `Constant` and the `Constantive`.\nBoth are interfaces that can be implemented by regular classes in order to give them the value of constant conditions,\nand to ensure that they are, in fact, constant.\n\n### Constant Types\n\nA constant (implementing `org.valross.constantine.Constant`) is a type,\ninstances of which are completely unmodifiable and constructed only from other constants.\nFor simplicity, primitives, strings, primitive wrappers and other Java-provided 'constables' are assumed to be constant,\nsince they don't implement the Constant interface.\n\nA constant can be **described**. The description of a constant is the means to make it from its constituent parts.\nThis is the part that is used when a constant is stored within a class file or the like.\nCreating the description itself is handled automatically by the API, but two things must be provided by the implementor:\nFirstly, the parameters for the canonical constructor (the accessible one that should be used to re-create the object)\nand secondly, the 'serial' or the set of (constant) values that need to be fed to the constructor to re-create this\nexact object.\n\nA variation of this is provided specifically for records, which handles the canonical parameters and the serial (albeit\nreflectively).\n\n### Constantive Types\n\nA constantive (implementing `org.valross.constantine.Constantive`) is a type,\ninstances of which are capable of being **resolved**.\nThe resolution (or finalisation, although that word has various negative associations) of an instance\nis when it is \"finished\" and can no longer be edited.\nIn other words, the resolution of an object is when it's ready to become a constant.\n\nA simple example of this might be a constantive 'builder' class, which allows a data structure to be easily mutated.\nWhen the building is finished and the dataset is ready, we might want to return the finished product, which will be a\nconstant.\nAnother good example might be a mutable list that, once submitted, is resolved to a constant, immutable form.\n\nTherefore, a constantive is something that can effectively be turned into a constant and, by extension,\nthat we can sort of treat as a constant in the meantime.\n\nAll constants are also constantive, since they are already resolved to themselves.\n\n## Usage\n\n### Classes\n\nWhen implementing the `Constant` interface, a class must conform to the specifications listed above.\nAn example is shown below.\n\n```java\nimport org.valross.constantine.Constant;\n\nimport java.lang.constant.Constable;\n\npublic final class Person // our class is final, something else shouldn't extend it and add non-constant things\n    implements Constant { // it's okay to extend it with another constant type or seal it, though\n\n    public final String name; // all of our data is final and immutable\n    public final int age; // even though these aren't Constant, they're effectively constant\n\n    public Person(String name, int age) { // we have a canonical constructor\n        this.name = name;\n        this.age = age;\n    }\n\n    @Override\n    public Constable[] serial() {\n        return new Constable[] {name, age}; // these are the things needed to make a new Person(name, age)\n    }\n\n    @Override\n    public Class\u003c?\u003e[] canonicalParameters() {\n        return new Class[] {String.class, int.class}; // this is what the canonical constructor looks like\n    }\n\n}\n```\n\n### Records\n\nA record is the ideal way to express a constant object: it has a definite, visible canonical constructor,\ndefinite, visible, necessarily-final and accessible members, and all these things are enforced at the source level.\nNearly all constant types _ought to be_ records.\n\nMaking a record constant is a very difficult task, as seen below:\n\n```java\nimport org.valross.constantine.RecordConstant;\n\npublic record Day(String name)\n    implements RecordConstant {\n\n}\n```\n\n### Constantives\n\nA constantive class implements `org.valross.constantine.Constantive`.\nIt must implement the method `Constant constant()`, providing a constant version of its data.\n\n## Constant Arrays\n\nAn observant reader may have noticed that Java arrays do not satisfy the definition of a constant,\nsince their contents is mutable.\nTo cover this, the `org.valross.constantine.Array` class is provided, which can hold a fixed collection of constants.\n\nInternally, the backing array used by the Array class is made effectively final by being unreachable;\nnothing is able to access it in order to change its data, and all copies provided by accessors are cloned from the\noriginal.\n\nThe Array class also functions as a constant Collection, which can be iterated over.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoderocky%2Fconstantine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoderocky%2Fconstantine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoderocky%2Fconstantine/lists"}