From 078486fa23f7c62a7966c17aca84496eb8d2f419 Mon Sep 17 00:00:00 2001 From: Tianhao25 Date: Wed, 12 Sep 2018 10:53:36 -0700 Subject: [PATCH 1/2] Update README.md Add general Java program instruction. --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 5f812ab..798a41e 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,32 @@ input widget ready for use, but only the UI parts are tied to Android. Non-UI code and tests can be run in Java SE, and the rest of the library could easily be adapted to run in any Java environment. +### Address validation in general JAVA project. + +If you are developing a pure JAVA project, this lib can still be very useful when you want to validate addresses. In this case, the only part we need is the common module. Please following steps below to get started. + +* 1. Follow the readme.md inside common module to build the common project. After build succeed, you would find a common.jar within folder: common/build/libs +* 2. Import this common.jar into your project. Now, you should be able to start to code. +* 3. For valiating address, the key class we need is **StandardAddressVerifier.java** +``` +// Build address data need to be verified. +final AddressData addressData = + AddressData.builder(). + setCountry("US"). + setAdminArea("CA"). + setPostalCode("94088"). + setLocality(Sunnyvale). + setAddress("Dream Ave"). + build(); +// address problems, which will be filled by standardAddressVerifier if some data is invalid. +AddressProblems addressProblems = new AddressProblems(); + +// Verify the address. +standardAddressVerifier.verify(addressData, addressProblems); + +// Now, you can see the address problems reside inside addressProblems. +addressProblems.getProblems(); +``` ## Mailing List Using and developing libaddressinput is discussed on this mailing list: From aeeb8343fb81df933ec69c33617a643a2a4b67ef Mon Sep 17 00:00:00 2001 From: Tianhao25 Date: Wed, 12 Sep 2018 11:04:10 -0700 Subject: [PATCH 2/2] Update README.md --- README.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 798a41e..7d9da31 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,10 @@ easily be adapted to run in any Java environment. If you are developing a pure JAVA project, this lib can still be very useful when you want to validate addresses. In this case, the only part we need is the common module. Please following steps below to get started. -* 1. Follow the readme.md inside common module to build the common project. After build succeed, you would find a common.jar within folder: common/build/libs +* 1. Follow the **readme.md** inside common module to build the common project. After build succeed, you would find common.jar within folder: common/build/libs * 2. Import this common.jar into your project. Now, you should be able to start to code. * 3. For valiating address, the key class we need is **StandardAddressVerifier.java** -``` +```java // Build address data need to be verified. final AddressData addressData = AddressData.builder(). @@ -58,6 +58,23 @@ standardAddressVerifier.verify(addressData, addressProblems); // Now, you can see the address problems reside inside addressProblems. addressProblems.getProblems(); ``` +Of course, StandardAddressVerifier needs some effort to be configured. +```java +StandardAddressVerifier standardAddressVerifier = new StandardAddressVerifier( + new FieldVerifier( + new ClientData( + new CacheData( + // By default, this lib uses SimpleClientCacheManager + // You can implement your customized cache manager to cache the metadata. + new RedisClientCacheManager(redissonClient, cacheSize), + // You need to implement AsyncRequestApi to provide internet access capability for this lib. + // If the address meta is not cached in your cache manager, it would go fetch the metadata from the internet: "https://chromium-i18n.appspot.com/ssl-address" + new XXXAsyncRequestApi() + ) + ) + )); +``` + ## Mailing List Using and developing libaddressinput is discussed on this mailing list: