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 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
Functions to return immutable collections succinctly:
List<String> anImmutableList = immutableList{"one","two","three"}; Set<Integer> anImmutableSet = immutableSet{1,2,3}; Map<String,Integer> anImmutableMap = immutableMap{"one"->1,"two"->2,"three"->3};
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 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]
Support left and right bit rotation on Integer
s.
rotateLeft($1010_0101, 4);
> $1010_0101_0000
rotateRight($1010_0101, 4);
> $0101_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1010
Convenience function: helpString() to help output class string attributes.
helpString("Thing", "Name"->"FirstThing", "Number"->1, "Optional"->null);
> “Thing:{Name=FirstThing,Number=1,Optional=null}“
Packages | |
herd.chayote.bytes | Contains functions to translate Integers into Sequences of Bytes integerToBytes(941226) > [0, 0, 0, 0, 0,… |
herd.chayote.collections | Contains functions to return immutable collections succinctly: List<String> anImmutableList =… |
herd.chayote.format | Contains functions to format Integers as either hex or bits Strings with padding and underscores to make them more… |
herd.chayote.integer | Support left and right bit rotation on |
herd.chayote.object_helpers | Contains helper functions for equals() and hash: hashes(myObject.myInteger,myObject.myString); > 1312847… |
Dependencies | ||
ceylon.collection | 1.1.0 |