Various utility classes and methods for Ceylon. These are intended to all be written in native Ceylon, with no dependency on JDK-specific modules.

Format Integers or Integer64s as either hex or bits Strings with padding and underscores to make them more readable.

   print(formatAndPadAsBits(30));

> 0001_1110

   print(formatAndPadAsHex(500000);

> 0007_a120

Determine whether an [[Integer] has too many (or too few in the case of negative) bits on a Ceylon platform (JVM or JS)

   print(isOverflowOnPlatform($0010_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000));

> false (JVM)

> true (JS)

Helper functions for equals() and hash:

   hashes(myObject.myInteger,myObject.myString);

> 1312847

   equalsWith(myObject.myInteger,otherObject.myInteger);

> true or false

   equalsWithMultiple([myObject.myInteger,otherObject.myInteger],
                      [myObject.myString,otherObject.myString]);

> true or false

Functions to translate Integers or Integer64s into Sequences of Bytes

   integerToBytes(941226);

> [0, 0, 0, 0, 0, $1110.byte, $0101_1100.byte, $1010_1010.byte]

   integerToBytesNoZeros(941226);

> [$1110.byte, $0101_1100.byte, $1010_1010.byte]

Convenience function: helpString() to help output class string attributes.

   helpString("Thing",  "Name"->"FirstThing", "Number"->1, "Optional"->null);

> “Thing:{Name=FirstThing,Number=1,Optional=null}“

Wrapper types for commonly used types to add unique typing. Example, in contexts where several Integer variables are used for different concepts such as AccountNumber, ReferenceNumber, etc

Examples:

  class AccountNumber(Integer baseValue) extends WrappedInteger(baseValue) {}
  class ReferenceNumber(Integer baseValue) extends WrappedInteger(baseValue) {}

  value accountNum1 = AccountNumber("1");
  value accountNum2 = AccountNumber("2");

  value refNum1 = ReferenceNumber("1");
  value refNum2 = ReferenceNumber("2");

  assertFalse(accountNum1.equals(accountNum2);
  assertFalse(accountNum1.equals(referenceNum1);
  assertFalse(referenceNum2.equals(accountNum2);
By: Luke deGruchy
License: Apache Software License
Packages
herd.chayote.bytes

Contains functions to translate Integers into Sequences of Bytes

herd.chayote.format

Contains functions to format Integers as either hex or bits Strings with padding and underscores to make them moreā€¦

herd.chayote.numeric

General numeric functions.

herd.chayote.object_helpers

Contains helper functions for equals() and hash:

herd.chayote.wrapper_type

Wrapper types for commonly used types to add unique typing.

Dependencies
ceylon.buffer1.2.2
ceylon.collection1.2.2
com.vasileff.ceylon.integer641.0.2