{"id":2072,"date":"2025-11-24T10:00:19","date_gmt":"2025-11-24T15:00:19","guid":{"rendered":"http:\/\/www.mymiller.name\/wordpress\/?p=2072"},"modified":"2025-11-24T10:00:19","modified_gmt":"2025-11-24T15:00:19","slug":"unitofdistance","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/unitofdistance\/","title":{"rendered":"UnitOfDistance &#8211; Measure and Convert your distance"},"content":{"rendered":"<p>Well I was bored one night after creating the UnitOfMemory and decided what else could be useful in the future. \u00a0I came up with a UnitOfDistance to convert distances over land. \u00a0Miles v&#8217;s kilometers and everything in between. \u00a0The class was easy to come up with, finding the exact conversion rates however was a different story. \u00a0The class works by basing everything on meters. \u00a0A nice conversion method from converting from one measurement type to another.<\/p>\n<p>If the precision level is not high enough for what you need, simply modify their values in the Enum list to what you do need.<\/p>\n<p>\u00a0<\/p>\n\n\n<pre class=\"wp-block-code\"><code>package name.mymiller.lang;\r\n\r\nimport java.io.Serializable;\r\n\r\n\/**\r\n * @author jmiller Defined UnitOfMeasures\r\n *\/\r\n\r\npublic enum UnitOfDistance implements Serializable {\r\n    \/\/ @formatter:off\r\n    \/**\r\n     * Standard U.S. Miles\r\n     *\/\r\n    Miles(\"Miles\", 1609.34, 0.000621371),\r\n    \/**\r\n     * Feet\r\n     *\/\r\n    Feet(\"Feet\", 3.28084, 0.3048),\r\n    \/**\r\n     * Inches\r\n     *\/\r\n    Inches(\"Inches\", 39.3701, 0.0254),\r\n    \/**\r\n     * Nautical Miles as defined at the equator\r\n     *\/\r\n    Nautical_Miles(\"Nautical Miles\", 1852.0, 0.000539957),\r\n    \/**\r\n     * Metric Based\r\n     *\/\r\n    Kilometers(\"Kilometers\", 1000.0, 0.001),\r\n    \/**\r\n     * Metric Based\r\n     *\/\r\n    Meters(\"Meters\", 1.0, 1.0),\r\n    \/**\r\n     * Metric Based\r\n     *\/\r\n    Centimeters(\"Centimeters\", 100.0, 0.01),\r\n    \/**\r\n     * Metric Based\r\n     *\/\r\n    Millimeters(\"Millimeters\", 1000.0, 0.001);\r\n    \/\/ @formatter:on\r\n\r\n    \/**\r\n     * Field to hold the conversion rate of unit to meters\r\n     *\/\r\n    private double conversionRateToMeters = 0.0;\r\n    \/**\r\n     * Field to hold the conversion rate from meters to unit\r\n     *\/\r\n    private double conversionRateFromMeters = 0.0;\r\n    \/**\r\n     * Label to use with unit of measure\r\n     *\/\r\n    private String label = null;\r\n\r\n    \/**\r\n     * Constructor for this enum to set values.\r\n     *\r\n     * @param label                    Label to use with the unit of measure\r\n     * @param conversionRateFromMeters Field to hold the conversion rate from meters\r\n     *                                 to unit\r\n     * @param conversionRateToMeters   Field to hold the conversion rate of unit to\r\n     *                                 meters\r\n     *\/\r\n    UnitOfDistance(final String label, final Double conversionRateFromMeters, final double conversionRateToMeters) {\r\n        this.label = label;\r\n        this.conversionRateToMeters = conversionRateToMeters;\r\n        this.conversionRateFromMeters = conversionRateFromMeters;\r\n    }\r\n\r\n    \/**\r\n     * Convert a measurement from one type to another\r\n     *\r\n     * @param convertTo   UnitOfDistance to convert measurement to.\r\n     * @param convertFrom UnitOfDistance measurement is in.\r\n     * @param distance    Distance to convert\r\n     * @return Double indicating the distance in the new UnitOfDistance\r\n     *\/\r\n    public static double convert(UnitOfDistance convertTo, UnitOfDistance convertFrom, double distance) {\r\n        return convertTo.getConversionRateFromMeters() * (distance * convertFrom.getConversionRateToMeters());\r\n    }\r\n\r\n    \/**\r\n     * @return Conversion Rate To Meters\r\n     *\/\r\n    public double getConversionRateFromMeters() {\r\n        return this.conversionRateFromMeters;\r\n    }\r\n\r\n    \/**\r\n     * @return Conversion Rate from Meters\r\n     *\/\r\n    public double getConversionRateToMeters() {\r\n        return this.conversionRateToMeters;\r\n    }\r\n\r\n    \/**\r\n     * @return Name given for this unit of measure.\r\n     *\/\r\n    public String getLabel() {\r\n        return this.label;\r\n    }\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Well I was bored one night after creating the UnitOfMemory and decided what else could be useful in the future. \u00a0I came up with a UnitOfDistance to convert distances over land. \u00a0Miles v&#8217;s kilometers and everything in between. \u00a0The class was easy to come up with, finding the exact conversion rates however was a different [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2073,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[457],"tags":[69],"series":[248],"class_list":["post-2072","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java_extra","tag-java-2","series-advanced-classes"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2017\/02\/tape-measure-1860811_640.jpg?fit=640%2C426&ssl=1","jetpack-related-posts":[{"id":2067,"url":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/unitofmemory\/","url_meta":{"origin":2072,"position":0},"title":"UnitOfMemory &#8211; Measure and convert you bytes","author":"Jeffery Miller","date":"November 24, 2025","format":false,"excerpt":"Not very often do I need to take a number of bytes and convert them into the most appropriate measurement. \u00a0This came up recently on a project and I thought it would be nice to just create a class to handle this for me. \u00a0So I created UnitOfMemory as enum\u2026","rel":"","context":"In &quot;Java Extras&quot;","block_context":{"text":"Java Extras","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_extra\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2017\/02\/info-1641937_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2017\/02\/info-1641937_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2017\/02\/info-1641937_640.jpg?fit=640%2C426&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":2449,"url":"https:\/\/www.mymiller.name\/wordpress\/java\/jackson-configuration\/","url_meta":{"origin":2072,"position":1},"title":"Jackson Configuration","author":"Jeffery Miller","date":"December 23, 2025","format":false,"excerpt":"Jackson configuration for JSON to POJO conversion. Standard conversion for converting JSON to POJO objects for Rest APIs and other implementations.","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java\/"},"img":{"alt_text":"Jackson configuration","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/05\/analytics-3088958_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/05\/analytics-3088958_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/05\/analytics-3088958_640.jpg?fit=640%2C426&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":2111,"url":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/unitoftime\/","url_meta":{"origin":2072,"position":2},"title":"UnitOfTime &#8211; Measure and convert you milliseconds","author":"Jeffery Miller","date":"November 24, 2025","format":false,"excerpt":"Continuing my series on advanced classes that are handy to have around when needed. \u00a0I have created the UnitOfTime. \u00a0This class is used to convert a number of milliseconds over to a more understandable period of time. package name.mymiller.extensions.lang; import java.math.BigDecimal; import java.math.BigInteger; \/** * Measure UnitOfTime based on milliseconds\u2026","rel":"","context":"In &quot;Java Extras&quot;","block_context":{"text":"Java Extras","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_extra\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2017\/03\/time-3222267_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2017\/03\/time-3222267_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2017\/03\/time-3222267_640.jpg?fit=640%2C426&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3421,"url":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/convert-csv-to-json-and-json-to-csv-with-csvjsonconverter\/","url_meta":{"origin":2072,"position":3},"title":"Convert CSV to JSON and JSON to CSV with CSVJSONConverter","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"In today's data-driven world, it's common to work with different data formats like CSV (Comma-Separated Values) and JSON (JavaScript Object Notation). Converting data between these formats is a common task in data processing and integration workflows. In this article, we'll explore how to use the CSVJSONConverter class, a versatile utility\u2026","rel":"","context":"In &quot;Java Extras&quot;","block_context":{"text":"Java Extras","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_extra\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/07\/computer-g610baba23_640.jpg?fit=640%2C360&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/07\/computer-g610baba23_640.jpg?fit=640%2C360&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/07\/computer-g610baba23_640.jpg?fit=640%2C360&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3718,"url":"https:\/\/www.mymiller.name\/wordpress\/springboot\/deep-dive-into-springs-message-conversion-custom-message-converters-and-their-role-in-serialization-deserialization\/","url_meta":{"origin":2072,"position":4},"title":"Deep Dive into Spring&#8217;s Message Conversion: Custom Message Converters and Their Role in Serialization\/Deserialization","author":"Jeffery Miller","date":"November 24, 2025","format":false,"excerpt":"When working with Spring applications, particularly those that deal with messaging, REST APIs, or data interchange, understanding message conversion is crucial. Spring provides a powerful framework for handling serialization and deserialization through its message converters. In this article, we will explore the concept of custom message converters, how they fit\u2026","rel":"","context":"In &quot;Springboot&quot;","block_context":{"text":"Springboot","link":"https:\/\/www.mymiller.name\/wordpress\/category\/springboot\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/transformation-3753443_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/transformation-3753443_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/transformation-3753443_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/transformation-3753443_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/transformation-3753443_1280-jpg.avif 3x"},"classes":[]},{"id":3380,"url":"https:\/\/www.mymiller.name\/wordpress\/java\/synchronous-to-asynchronous\/","url_meta":{"origin":2072,"position":5},"title":"Synchronous to Asynchronous","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Converting a synchronous method to an asynchronous one in Java involves modifying the code to allow other tasks to execute while it is waiting for input\/output operations to complete. Here's an example of how to convert a synchronous method to an asynchronous one in Java: Let's say we have a\u2026","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/multitasking-ga6749a2b2_640.jpg?fit=640%2C394&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/multitasking-ga6749a2b2_640.jpg?fit=640%2C394&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/multitasking-ga6749a2b2_640.jpg?fit=640%2C394&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/2072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=2072"}],"version-history":[{"count":9,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/2072\/revisions"}],"predecessor-version":[{"id":2908,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/2072\/revisions\/2908"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/2073"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=2072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=2072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=2072"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=2072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}