Just clone the repository...?
Printable View
Changes
- BaseRandom now abstracts the pickItem function with a generic type. example: BaseRandom<Int>().pickItem() -> Int
- Changes to the subclasses of BaseRandom to reflect those changes.
- Removed vestigial data from MemoWeightedTable, made the equivalent data from WeightedTable internal rather than private so that MemoWeightedTable can access it.
Update 3/17/2019
- Splitting utils up in to their own separate repos starting with BoolUtil and StringUtil (was TextUtil, but StringUtil is less ambiguous).
- Providing jar as well as source code for each util.
- Improving the inside code composition wise as well as documentation wise. Have to find a better way to generate docs bc dokka doesnt work too well at least for markdown (boolutil has a dokka generated wiki page).
NbUtil project (where you can find the link to all sub projects): HERE
BoolUtil: HERE
StringUtil: HERE
Update 4/3/2019
- RandomUtil
- Code is now documented much better
- Expanded to have much more features such as
StringRandom
andNumberRandom
- Added a
UniversalRandom
. You can choose which type to get back, but you have to provide the source for itWeightedTable
has been updated to be able to use custom weights without being aMemoizedWeightedTable
, butMemoizedWeightedTable
is still faster for multiple accesses of custom weights- Lots of functions for
Array
and the primitive array types (IntArray
,CharArray
, etc.)- And much more!
- Up next is
NumberUtil
andTagUtil
. Keep watch!
NbUtil project (where you can find the link to all the updated sub projects): HERE
RandomUtil source: HERE
RandomUtil jar: HERE
Updated the main post to be less cluttered
Update 4/24/2019
- BoolUtil changes
BoolArray
renamed toDenseBoolList
(it implementsList<Boolean>
) and made more memory efficient (now usesByteArray
rather thanLongArray
)- Added
MutableDenseBoolList
. Uses same memory perBoolean
asDenseBoolList
but now you can make it bigger or smaller as well as use all theList
extension functions provided by kotlins standard library.- Added destructuring of primitive number types in to booleans up to their respective bit amounts. e.g.
Byte
can destructure up to 8Boolean
like such:val (bool1, bool2, bool3, bool4, bool5, bool6, bool7, bool8) = byteValue
- Added ways to randomly generate some common [inline]Boolean[inline] collections
- NumberUtil changes
- You can now access sequential sub-numbers in primitive numbers. e.g. you can access byte 1 (bits 0 to 7), byte 2 (bits 8 to 15) ... byte X in a
Long
. You can access an integral primitive as long as there is a bigger integral primitive. Usingnumber.getByte(byteIndex)
,number.getInt(intIndex)
, etc.- You can now access individual bits using
number.getBit(bitIndex)
- You can now set sequential sub-numbers using
number.setShort(shortIndex, shortValue)
,number.setByte(byteIndex, byteValue)
, etc.- You can now set individual bits using
number.setBit(bitIndex, booleanValue)
ByteArray
conversion (to and from) still present- Removed conversions to and from hex strings
- Parity (isEven, isOdd) still present
- Added
DenseNumberPair
forByte
,Short
andInt
. These store 2 of the given number in a smaller space than a standard libraryPair
would- Added
Vector
andNumberVector
(implementsVector
) as well asNumberVector
implementations for the primitive number types. GlorifiedList
- Added
MutableVector
andMutableNumberVector
(implementsMutableVector
) as well asMutableNumberVector
implementations for the primitive number types. GlorifiedMutableList
TagUtil is coming next for sure this time. BoolUtil was too juicy not to update.
NbUtil project (where you can find all the updated sub projects): HERE
BoolUtil: SOURCE/JAR
NumberUtil: SOURCE/JAR
Update 2019/04/30 (using new TagUtil)
TagUtil
- Completely rewritten
- Very similar to previous iteration when using
- More customizability allowing for more accurate "emulation" of other tag languages
- Less keystrokes to achieve the same thing compared to previous iteration
- Easier for your brain to interpret while creating your tags
And with that, the separation, rewriting and jarring of NbUtils is complete! Suggestions for additions and improvements are welcome!
TagUtil: SOURCE\JAR
Spoiler for CODE TO RECREATE THIS POST:
Update 2019/05/31
DelegateUtil
- Create delegates for
var
. Custom variable pass set condition, custom behaviour before set, after set, and on failing condition. Custom behaviour on get.- Create delegates for
val
. Custom behaviour on get.- Create delegates for
List
. Custom behaviour on get. Custom behaviour on getting list item.- Create asynchronous delegates. Same as
val
delegate except it's a suspending function (and lazy), so its nice for working with coroutines.
Ok, what is a delegate? Basically allows you to define custom get and set behaviour without having to re-type them every time. Imagine you have 3 values that you want to have the same get and set custom function for, which in this case as an example would be getting the value would return the value + 1, and setting the value would make the new value the set value + 1
That's not too bad to type out, but it IS repetitive. What if there was a solution? Lo and behold, delegates!Code:val value1: Int = 5
get() = field + 1
set(newValue) { field = newValue + 1 }
val value2: Int = 6
get() = field + 1
set(newValue) { field = newValue + 1 }
val value3: Int = 7
get() = field + 1
set(newValue) { field = newValue + 1 }
Delegated variables are a way to preserve simplicity and ease of extensibility without risk of typos creating inconsistencies, while also preserving regular syntax usage.
So, let's make this in to a delegated example
Here's the delegate
Here's the variables that use the delegate and changing the delegateCode:class PlusOneDelegate(private var value: Int = -1): ReadWriteProperty<Any?, Int> {
// Called every time you see "variableName" used anywhere.
override fun getValue(thisRef: Any?, property: KProperty<*>): Int = value + 1
// Called every time you see "variableName = newValue"
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Int) { this.value = value + 1 }
}
Bada bing, bada boom.Code:var value1: Int by PlusOneDelegate(5) // When called on, will receive 6 but the underlying value is still 5
var value2: Int by PlusOneDelegate(6)
var value3: Int by PlusOneDelegate(7)
value1 = 8 // sets to (8+1), now calling value1 will return 10
DelegateUtil: SOURCE/JAR
Have a look at this re: bool utils; https://github.com/brettwooldridge/S...rseBitSet.java
Update 2019/06/07
Update NumberUtils to v1.1-0
DenseBytePair
,DenseShortPair
andDenseIntPair
now implement a newDenseNumberPair
interface.component
operator functions were moved from the previously mentioned classes to theDenseNumberPair
interface.- The previously mentioned classes are now
inline class
, which means they will be optimized as (Short
forDenseBytePair
,Int
forDenseShortPair
andLong
forDenseIntPair
) when used as that class type, not when used asDenseNumberPair
. Expl. below- Added
DenseFloatPair
(optimizes asLong
Spoiler for Explanation of optimization:
NumberUtil: SOURCE/JAR
Update 2019/06/08
Update NumberUtils to v1.2-0
DenseNumberPair
now implements a newNumberPair
interface.DenseNumberPair
andNumberPair
now implementDenseNumberTuple
andNumberTuple
respectively.- Added
NumberTriple
andNumberQuad
as well as their dense cousins. They of course implement their respective tuple interfaces- Made
isEqualTo
a lot more consistent across implementations
NumberUtil: SOURCE/JAR