From 1c7242d372d747239c76a3d5bd2e4a66a565a20d Mon Sep 17 00:00:00 2001 From: Colin Redmond Date: Fri, 22 Mar 2024 21:46:30 -0700 Subject: [PATCH] docs: updated documents to include details about the types of lists, sets and maps supported. --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bcb277392..f9898c1f9 100644 --- a/README.md +++ b/README.md @@ -228,8 +228,7 @@ If you want to use a different path style you can provide your own SentenceLexer long maxConnectionsPerRoute = gestalt.getConfig("http.Pool.maxPerRoute", 24, Long.class); // get a list of Host objects, or an PlaceHolder collection if there is no hosts found. - List hosts = gestalt.getConfig("db.hosts", Collections.emptyList(), - new TypeCapture>() {}); + LinkedList hosts = gestalt.getConfig("db.hosts", new LinkedList(), new TypeCapture>() {}); // Get a class at a specific list index. Host host = gestalt.getConfig("db.hosts[2]", Host.class); @@ -334,13 +333,17 @@ iHttpPool pool = gestalt.getConfig("http.pool", iHttpPool.class); ### Retrieving Generic objects To get an interface you need to pass in a TypeCapture with the Generic value of the class for gestalt to return. -Gestalt supports getting Generic objects such as Lists or Maps. However, due to type erasure we need to capture the type using the TypeCapture class. The Generic can be any type Gestalt supports decoding such as a primitive wrapper or an Object. +Gestalt supports getting Generic objects such as Lists, Maps or Sets. However, due to type erasure we need to capture the type using the TypeCapture class. The Generic can be any type Gestalt supports decoding such as a primitive wrapper or an Object. ```java List httpPoolList = gestalt.getConfig("http.pool", new TypeCapture<>() { }); var httpPoolMap = gestalt.getConfig("http.pool", new TypeCapture>() { }); ``` +Gestalt supports multiple varieties of List such as AbstractList, CopyOnWriteArrayList, ArrayList, LinkedList, Stack, Vector, and SequencedCollection. If asked for a List it will default to an ArrayList. +Gestalt supports multiple varieties of Maps such as HashMap, TreeMap, ArrayList, LinkedHashMap and SequencedMap. If asked for a Map it will default to an HashMap. +Gestalt supports multiple varieties of Sets such as HashSet, TreeSet, LinkedHashSet, LinkedHashMap and SequencedSet. If asked for a Set it will default to an HashSet. + #### Config Data Type For non-generic classes you can use the interface that accepts a class `HttpPool pool = gestalt.getConfig("http.pool", HttpPool.class);`, for Generic classes you need to use the interface that accepts a TypeCapture `List pools = gestalt.getConfig("http.pools", Collections.emptyList(), new TypeCapture>() {});` to capture the generic type. This allows you to decode Lists, Sets and Maps with a generic type. @@ -828,11 +831,11 @@ To register your own default ConfigLoaders add them to the builder, or add it to | Float | Float and float | | Instant | | | Integer | Integer and int | -| List | a Java list with any Generic class, Can decode simple types from a single comma separated value, or from an array node. You can escape the comma with a \\, so the values are not split. | +| List | a Java list with any Generic class, Can decode simple types from a single comma separated value, or from an array node. You can escape the comma with a \\, so the values are not split. Supports multiple varieties of List such as AbstractList, CopyOnWriteArrayList, ArrayList, LinkedList, Stack, Vector, and SequencedCollection. If asked for a List it will default to an ArrayList. | | LocalDate | Takes a DateTimeFormatter as a parameter, by default it uses DateTimeFormatter.ISO_LOCAL_DATE | | LocalDateTime | Takes a DateTimeFormatter as a parameter, by default it uses DateTimeFormatter.ISO_DATE_TIME | | Long | Long or long | -| Map | A map, Assumes that the key is a simple class that can be decoded from a single string. ie a Boolean, String, Int. The value can be any type we can decode. | +| Map | A map, Assumes that the key is a simple class that can be decoded from a single string. ie a Boolean, String, Int. The value can be any type we can decode. Supports parsing a map from a string with the format key1=value1, key2=value2. You can escape the comma with a \\, so the values are not split. Supports multiple varieties of Maps such as HashMap, TreeMap, ArrayList, LinkedHashMap and SequencedMap. If asked for a Map it will default to an HashMap. | | Object | Decodes a java Bean style class, although it will work with any java class. Will fail if the constructor is private. Will construct the class even if there are missing values, the values will be null or the default. Then it will return errors which you can disable using treatMissingValuesAsErrors = true. Decodes member classes and lists as well. | | Optional | Decodes an optional value, if no value is found it will return an Optional.empty() | | OptionalDouble | Decodes an optional Double, if no value is found it will return an OptionalDouble.empty() | @@ -842,10 +845,7 @@ To register your own default ConfigLoaders add them to the builder, or add it to | Pattern | | | Proxy (interface) | Will create a proxy for an interface that will return the config value based on the java bean method name. So a method "getCar()" would match a config named "car". If a config is missing it will call the default method if provided. Has 2 modes, Cached and pass-through, the default is Cached. Cached will receive a cache of all values on creation and return those from an internal cache. Pass-though will result the object on creation, but when calling to get the values it will call gestalt for each value. This allows you to always get the most recent values. To set the mode on the builder use `Gestalt gestalt = builder.setProxyDecoderMode(ProxyDecoderMode.PASSTHROUGH)` | | Record | Decodes a Java record. All members of the record must have a value or construction will fail.So unlike the Object decoder it will not have the option to default to null or provide defaults. Will construct the record even if there are extra values, it will ignore all extra values. | -| SequencedCollection | A SequencedCollection with any Generic class, Can decode simple types from a single comma separated value, or from an array node. Provides a ArrayList. | -| SequencedMap | A map, Assumes that the key is a simple class that can be decoded from a single string. ie a Boolean, String, Int. The value can be any type we can decode. Provides a LinkedHashMap. Json, Toml, and Properties dont support sorted maps. Only Hocon supports sorted maps. | -| SequencedSet | A SequencedSet with any Generic class, Can decode simple types from a single comma separated value, or from an array node. Provides an ordered LinkedHashSet. | -| Set | A Set with any Generic class, Can decode simple types from a single comma separated value, or from an array node. Provides an unordered HashSet. | +| Set | A Set with any Generic class, Can decode simple types from a single comma separated value, or from an array node. You can escape the comma with a \\, so the values are not split. Provides an unordered HashSet. Supports multiple varieties of Sets such as HashSet, TreeSet, LinkedHashSet, LinkedHashMap and SequencedSet. If asked for a Set it will default to an HashSet. | | Short | Short or short | | String | | | StringConstructor | Will decode a class that has a constructor that accepts a single string. This will only match for leaf nodes. It will send the value of the leaf node to the String constructor. |