Contenu connexe Similaire à Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017 (20) Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 20171. Copyright © 2016, Creative Arts & Technologies and others. All rights reserved.
Physikal – JSR 363 and
Kotlin for Clean Energy
Werner Keil
JSR 363 Maintenance Lead
@wernerkeil
October 18, 2017
2. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
Agenda
1. Introduction
2. Tenkiv Nexus
3. JSR 363
4. Physikal
3. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
Who am I?
Werner Keil
• Consultant – Coach
• Creative Cosmopolitan
• Open Source Evangelist
• Software Architect
• Spec Lead – JSR363
• Individual JCP Executive Committee Member
[www.linkedin.com/in/catmedia]
Twitter @wernerkeil
4. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
Save Water
5. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
Water Crisis
6. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
The Globe
2.5 billion people across the globe
lack access to clean water.
7. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
Developing Nations
In places like Afghanistan,
lack of access to water sanitation leads to a
1 in 5 child mortality rate.
8. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
California
98% of California is experiencing
severe drought, placing major stress
on our water infrastructure.
9. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
What is Tenkiv Nexus?
The Tenkiv Nexus is a fully modular renewable energy system. It uses heat
from the sun in order to power anything for 1/13th the cost of existing solar
panels and 1/5th the cost of fossil fuels without any subsidies. It’s the
breakthrough the world’s been waiting for that finally enables us to truly
utilize the most abundant source of power available on earth: the sun.
Tenkiv started deployment of the Tenkiv Nexus for water purification, but
over time will replace more and more of the world's dying energy
infrastructure with this new, more powerful, cost-effective, and completely
clean energy nexus.
10. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
Tenkiv Nexus
11. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
What is JSR-363?
5,999 miles
A Quantity
A Unit
Brussels
São Paulo
12. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
Why do we need JSR-363?
There are no specifications or standards for handling units in Java.
The current solution is to use primitives, that don’t provide any Type
Safety.
The errors are difficult to find using unit testing:
Interface and Internationalization (e.g. radian/degree, meters/feet);
Arithmetic operations (e.g. overflow);
Conversion between units (e.g. from same domain);
13. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
5,999 miles
A Quantity
A Unit
What is the problem, in code?
int distance = 5999; //in miles
float speed = airplane.getSpeed(); //in km/h
System.out.println(“ETA: “ + (distance/speed) + “ h”);
14. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
What is JSR-363, in code?
Quantity<Length> distance = Quantities.getQuantity(5999,
US.MILE);
Quantity<Speed> airplaneSpeed = getAirplaneSpeed();
Quantity<Time> eta =
(Quantity<Time>)distance.divide(airplaneSpeed);
System.out.println(“ETA: “ + eta.to(Units.HOUR));
ETA: 10.216345960256564 h
15. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
What is Physikal?
Library providing Kotlin extensions and ease of use functions for Java
Units of Measurement libraries based on JSR-363.
Contains
• Core - Basic Metric units.
• SI-Units - SI units.
• Complete-Units - All units including US or Imperial.
16. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
What is Physikal, in code?
Create Units
val added = 10.metre + 1.kilo.metre
>> 1010.0 m
val small = 10.metre
val large = 10.kilo.metre
17. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
What is Physikal, in more code?
Includes all operators
val added = 10.metre + 1.kilo.metre
>> 1010.0 m
val speed = added/10.minute
>> 101 m/min
var aFewSeconds = 5.second
aFewSeconds++
>> 6.0 s
10.peta.watt > 2.watt
>> true
18. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
What is Physikal, in more code?
Using different units (SI units & other units)
5.gram + 2.pound
>> 912.18474 g
(13.kilo.gram + 20.pound) convertTo STONE
>> 3.47572100600243466674378 st
19. © 2017 Creative Arts & Technologies and others. All rights reserved.#Physikal @UnitAPI
Links
Public JSR-363 mailing list(s) and/or forum(s)
Units-Dev on Google Groups
Units-Users on Google Groups
JSR-363 page: https://jcp.org/en/jsr/detail?id=363…
Project Website: http://unitsofmeasurement.github.io on GitHub
Tenkiv: https://tenkiv.com
Physikal: https://github.com/Tenkiv/Physikal