Giter Club home page Giter Club logo

intera's Introduction

intera

GitHub Workflow Status (branch) JitPack MIT License

A user-interface library for converting rome numerals to arabic and back written in java.

Example usage

For basic usage you can just use the default implementation with all common roman counting rules applied. To obtain the default instance you can simply use:

final Intera intera = Intera.defaults();

The default instance is shared, and you don't have to use a local variable to save the instance. All intera instances are thread save.

An instance of intera only has to methods: parse and write. parse simply converts a roman number as a string to an arabic number using the known associations defined in the instance (We will come to that later). write converts the arabic letter back to a roman number string. For example:

final int arabic = Intera.defaults().parse("MDCCLXXX"); // 1780
final String roman = Intera.defaults().write(1780); // MDCCLXXX

The default number mapping is:

Rome I V X L C D M
Arabic 1 5 10 50 100 500 1000

You can change this mapping by using the intera-builder:

final Intera intera = Intera.builder()
  .registerAssociation('X', 100)
  .registerAssociation('I', 1000)
  .registerAssociation('M', 10000)
  .build();

You can also change the mathematical behaviour of the instance. By default, a maximum of three same chars can follow each other: XXX is ok (30), XXXX (40) has to be XL (50 - 10)

This behaviour can be modified in the builder. In this example we set the maximum same chars in a row to 5. If this value is smaller or equal to 1 the check is disabled:

final Intera intera = Intera.builder()
  .defaultAssociations()
  .maxSameCharsInRow(5)
  .build();

There is still one other rule in the roman math system. Subtractions are only allowed in some cases. You can only subtract by 1 from a 5 or 10, by 10 from a 50 and 100 and by 100 from a 500 and 1000. These rules can get disabled by using the builder as well as modified. To disable you can simply use:

final Intera intera = Intera.builder()
  .defaultAssociations()
  .subtractionValidator(SubtractionValidator.disabled())
  .build();

To modify the behaviour you can simply use:

final Intera intera = Intera.builder()
  .defaultAssociations()
  .subtractionValidator((number, subtraction) -> number > subtraction)
  .build();

The result is a boolean which when true indicates that the operation can't be done, false otherwise.

This was a quick go-trough all features of the library, for more information check the documentation.

Get intera

The compiled jar file is always included in the latest release.

For gradle you may use:

maven {
  name 'jitpack'
  url 'https://jitpack.io'
}

dependencies {
  implementation 'com.github.derklaro:intera:1.0.1'
}

For maven:

<repository>
  <id>jitpack.io</id>
  <url>https://jitpack.io</url>
</repository>

<dependency>
  <groupId>com.github.derklaro</groupId>
  <artifactId>intera</artifactId>
  <version>1.0.1</version>
</dependency>

Contributing

I appreciate contributions of any type. For any new features or fixes/style changes, please open an issue

The project is built with Gradle, require at least JDK 8, and use the google checkstyle configuration. Please make sure all tests pass, license headers are updated, and checkstyle passes to help us review your contribution.

License

intera is released under the terms of the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.