{"id":16517077,"url":"https://github.com/tomtzook/javabeans","last_synced_at":"2025-08-10T20:02:28.089Z","repository":{"id":57719291,"uuid":"145975734","full_name":"tomtzook/JavaBeans","owner":"tomtzook","description":"Java beans and observables","archived":false,"fork":false,"pushed_at":"2024-02-16T23:36:30.000Z","size":185,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T16:38:04.492Z","etag":null,"topics":["beans","java","observables"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomtzook.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-24T10:04:25.000Z","updated_at":"2023-12-30T05:59:57.000Z","dependencies_parsed_at":"2023-01-30T01:45:43.191Z","dependency_job_id":null,"html_url":"https://github.com/tomtzook/JavaBeans","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/tomtzook/JavaBeans","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomtzook%2FJavaBeans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomtzook%2FJavaBeans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomtzook%2FJavaBeans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomtzook%2FJavaBeans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomtzook","download_url":"https://codeload.github.com/tomtzook/JavaBeans/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomtzook%2FJavaBeans/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269780615,"owners_count":24474682,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["beans","java","observables"],"created_at":"2024-10-11T16:28:30.269Z","updated_at":"2025-08-10T20:02:27.986Z","avatar_url":"https://github.com/tomtzook.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaBeans\n![Maven Central](https://img.shields.io/maven-central/v/com.github.tomtzook/javabeans)\n![Travis (.org) branch](https://img.shields.io/travis/tomtzook/JavaBeans/master.svg)\n![GitHub](https://img.shields.io/github/license/tomtzook/JavaBeans.svg)\n\n\nLibrary providing java beans utilities and observables.\nProvides interfaces and several implementations for properties, observable data and such.\n\n## Building\n\nSimply run `./gradlew build` from the main directory.\nThis will build the library and export it along with a sources jar and javadoc archive into `build/libs`.\n\n## Properties\n\nJavaBeans introduces the `Property` interface, which is a mutable value, extending upon\n_Java_'s `java.uti.function.Supplier` interface.\n\nBasic properties, which implement `Property` expose `set` and `get` to modify the internal\ntheir value:\n```Java\nProperty\u003cString\u003e prop = ...\n\nprop.set(\"Hello World\");\nSystem.out.println(prop.get()); // returns \"Hello World\"\n```\n\nThere is no restrictions on how implementations store and access values, so make\nsure to check which implementation you use and whether or not it fits your needs.\n\n### Specialized Properties\n\nIn addition to the basic interface, there are also specializations for primitive \ntypes: `long`, `int`, `boolean`, `double`. Each specialization still exports `set` and `get`\nas it extends the base `Property` interface, however those methods return a wrapper class.\nTo get a primitive type, use `getAsType` and `setAsType` where `Type` is replaced by the \nprimitive type, e.g. `getAsBoolean`, `getAsInt` etc. It is recommended to use those methods.\n\n```Java\nIntProperty prop = ...\n\nprop.setAsInt(12);\nSystem.out.println(prop.getAsInt()); // returns 12 \n```\n\nThe `set` methods do not accept `null` values in specialization implementations.\n\n### Implementations\n\nJavaBeans provides the following implementations for `Property`, each implementation exists for \nthe specializations as well:\n- Simple: an in-memory implementation which is not thread-safe. Under `com.beans.properties`\n- Atomic: an in-memory thread-safe implementation. Under `com.beans.properties.atomic`\n\n### Observables\n\nAn `ObservableValue` is a value which can be observed for changes using listeners. Based\non the `java.util.function.Supplier` interface.\n\nAn `ObservableProperty` is a property which can be observed for changes using listeners.\nBased on the `Property` and `ObservableValue` interfaces.\n\nBoth have primitive specializations for types: `long`, `int`, `boolean`, `double`.\n\nCreation of such properties should be done using `ObservableFactory`.\n\n#### Listeners\n\nUsers may register `ChangeListener`s to an _observable_.\nAny changes to that _observable_'s value will\ncause an invocation of the listener with `ChangeEvent`.\n\n```Java\nObservableIntProperty prop = ....\nprop.addChangeListener((e)-\u003e {\n    System.out.println(\"New value: \" + e.getNewValue())\n});\n```\n\n#### Binding\n\nBinding `Observable`s will connect them. It is only possible between 2 `Observable`s with \nsimilar types. There are 2 types of bindings:\n\n- Single-Directional binding, `o1.bind(o2)` will connect the value of observable\n`o1` to `o2`, such that any changes to `o2` will change the value of `o1`. However,\nchanging the value of `o1` directly, with `setValue` will not be allowed, causing\na `RuntimeException`.\n```Java\nObservableIntProperty prop1 = ...;\nprop1.set(2);\nObservableIntProperty prop2 = ...;\nprop2.set(10);\n\nSystem.out.println(prop1.get()); // returns 2\n\nprop1.bind(prop2);\nSystem.out.println(prop1.get()); // returns 10\n\nprop2.set(100);\nSystem.out.println(prop1.get()); // returns 100\nSystem.out.println(prop2.get()); // returns 100\n\nprop1.set(5); // throws IllegalStateException\n```\n\n- Bi-Directional binding, `o1.bindBidirectional(o2)` will connect the value of observable\n`o1` to `o2`, such that any changes to `o2` will change the value of `o1`, and changes to `o1`\nwill change `o2`. \n```Java\nObservableIntProperty prop1 = ...;\nprop1.set(2);\nObservableIntProperty prop2 = ...;\nprop2.set(10);\n\nSystem.out.println(prop1.get()); // returns 2\n\nprop1.bindBidirectional(prop2);\nSystem.out.println(prop1.get()); // returns 10\n\nprop2.set(100);\nSystem.out.println(prop1.get()); // returns 100\nSystem.out.println(prop2.get()); // returns 100\n\nprop1.set(5);\nSystem.out.println(prop1.get()); // returns 5\nSystem.out.println(prop2.get()); // returns 5\n```\n\nWhile bound, properties will still invoke listeners on changes.\n\n#### Observable From Supplier\n\nUsing `PollingObserableFactory`, it is possible to create `ObservableValue`s out of `Supplier`s \n(including specializations).\n\nCreate the factory first:\n```Java\nObserableFactory observableFactory = ...;\nScheduledExecutorService executorService = ...;\nint pollingTimeMs = 25;\n\nPollingObserableFactory factory = new PollingObserableFactory(observableFactory, executorService, pollingTimeMs); \n```\n\nAnd simply use `factory.from` to create the `ObservableValue`. Now, it will be possible to listen\nto changes of the `Supplier` and bind it to other observables.\n\n```Java\nSupplier\u003cString\u003e supplier = ...;\nObservableValue\u003cString\u003e observable = factory.from(supplier);\n```\n\nThe `ScheduledExecutorService` will be used to poll updates from the supplier and test for changes in the value,\nmaking it observable. The `pollingTimeMs` is the period for polling the supplier.\n\n#### Global\n\nFor easier work with the observable factories, use the `Observables` class. This class will\nautomatically create the factories and provide access to them:\n\n```Java\nObservableIntProperty prop = Observables.factory().newIntProperty();\n\nSupplier\u003cObject\u003e supplier = ...;\nObserableValue\u003cObject\u003e observable = Observables.pollingFactory().from(supplier);\n```\n\nThe created factories will use a `ScheduledExecutorService` created specifically for dispatching events\nand for polling suppliers. This executor service will be terminated automatically using a shutdown hook.\n\nIt is also possible to configure the factories manually instead of using the automatically created ones. This should \nbe done before any usage or access to the factories:\n```Java\nObservableFactory factory = ...;\nObserables.setFactory(factory);\n\nObservablePollingFactory pollingFactory = ...;\nObserables.setPollingFactory(pollingFactory);\n```\n\nIt is also possible to configure the `ScheduledExecutorService` that will be used by the factories,\nusing `setExecutorService`. Doing so will make the factories use that executor service, but should be done\nbefore any usage/access to the factories. The executor service will not be terminated automatically, and\nthis must be the responsibility of the user providing the instance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomtzook%2Fjavabeans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomtzook%2Fjavabeans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomtzook%2Fjavabeans/lists"}