Skip to content

bogdanovmn/java-human-readable-values

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

A small library that will help you to get convenient for analyzing values. For instance, a big amount of seconds or bytes.

How to use it

1. Get the latest dependency

Maven Central

<dependency> <groupId>com.github.bogdanovmn.humanreadablevalues</groupId> <artifactId>human-readable-values</artifactId> <version>...</version> </dependency>

2. Print out your values

Milliseconds

assertEquals( "1h 1s 50ms", new MillisecondsValue(3600_000 + 1050).fullString() ); assertEquals( "1.1s", new MillisecondsValue(1050).shortString() );

Seconds

assertEquals( "2h 46m 40s", new SecondsValue(10000).fullString() ); assertEquals( "2.8h", new SecondsValue(10000).shortString() );

Bytes

assertEquals( "9K 784b", new BytesValue(10000).fullString() ); assertEquals( "9.8K", new BytesValue(10000).shortString() );

3. Customization

Define a custom type

public class MyTypeValue extends FractionatedValue { public MyTypeValue(long value) { super( value, new FractionSpecification( FractionDefinition.builder()	.name("the minimal fraction unit")	.shortNotation("mu")	.minimalUnitsAmount(1)	.build(), FractionDefinition.builder()	.name("another fraction unit")	.shortNotation("afu")	.minimalUnitsAmount(60)	.build(), FractionDefinition.builder()	.name("the last fraction unit")	.shortNotation("lfu")	.minimalUnitsAmount(3600)	.build()	)	);	} }
assertEquals( "2lfu 46afu 40mu", new MyTypeValue(10000).fullString() );

Using of custom formatting

The base class FractionatedValue has methods that return components of the divided on fractions value so you can use them for your better formatting

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages