Thread: [KT] NBUtil: Make your kotlin easier

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27
  1. #11  
    Registered Member
    Dread's Avatar
    Join Date
    Nov 2013
    Posts
    49
    Thanks given
    17
    Thanks received
    116
    Rep Power
    503
    Quote Originally Posted by harley_rae_ann View Post
    either way im not reading code on a site webpage by webpage.
    Just clone the repository...?
    Reply With Quote  
     

  2. Thankful users:


  3. #12  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    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.
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  4. #13  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    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
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  5. #14  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Update 4/3/2019
    • RandomUtil
      • Code is now documented much better
      • Expanded to have much more features such as StringRandom and NumberRandom
      • Added a UniversalRandom. You can choose which type to get back, but you have to provide the source for it
      • WeightedTable has been updated to be able to use custom weights without being a MemoizedWeightedTable, but MemoizedWeightedTable 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 and TagUtil. Keep watch!


    NbUtil project (where you can find the link to all the updated sub projects): HERE
    RandomUtil source: HERE
    RandomUtil jar: HERE
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  6. #15  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Updated the main post to be less cluttered

    Update 4/24/2019
    • BoolUtil changes
      • BoolArray renamed to DenseBoolList (it implements List<Boolean>) and made more memory efficient (now uses ByteArray rather than LongArray)
      • Added MutableDenseBoolList. Uses same memory per Boolean as DenseBoolList but now you can make it bigger or smaller as well as use all the List 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 8 Boolean 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. Using number.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 for Byte, Short and Int. These store 2 of the given number in a smaller space than a standard library Pair would
      • Added Vector and NumberVector (implements Vector) as well as NumberVector implementations for the primitive number types. Glorified List
      • Added MutableVector and MutableNumberVector (implements MutableVector) as well as MutableNumberVector implementations for the primitive number types. Glorified MutableList


    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
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  7. #16  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    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:

    With a fresh new project and the jar as the only library:
    Code:
    import tagUtil.example.*
    
    val FINAL_TEXT = TEXTBOX {
        +fontColor("FFFFFF", "Update 2019/04/30 (using new TagUtil)")
        +"TagUtil"
        +list {
            +"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: "
        -textUrl("https://bitbucket.org/nbutil/tagutil/", "SOURCE")
        -"\\"
        -textUrl("https://bitbucket.org/nbutil/tagutil/downloads/", "JAR")
    
        +spoiler { value = "CODE TO RECREATE THIS POST"
            +"With a fresh new project and the jar as the only library:"
            +codeBlock {
                +"You get the point"
            }
        }
    }
    
    fun main() {
        println(FINAL_TEXT)
    }
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  8. #17  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    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
    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 }
    That's not too bad to type out, but it IS repetitive. What if there was a solution? Lo and behold, delegates!
    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
    Code:
    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 }
    }
    Here's the variables that use the delegate and changing the delegate
    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
    Bada bing, bada boom.

    DelegateUtil: SOURCE/JAR
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  9. #18  
    Registered Member
    hc747's Avatar
    Join Date
    Dec 2013
    Age
    26
    Posts
    1,474
    Thanks given
    3,312
    Thanks received
    691
    Rep Power
    1098
    Have a look at this re: bool utils; https://github.com/brettwooldridge/S...rseBitSet.java
    Reply With Quote  
     

  10. #19  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Update 2019/06/07

    Update NumberUtils to v1.1-0
    • DenseBytePair, DenseShortPair and DenseIntPair now implement a new DenseNumberPair interface.
    • component operator functions were moved from the previously mentioned classes to the DenseNumberPair interface.
    • The previously mentioned classes are now inline class, which means they will be optimized as (Short for DenseBytePair, Int for DenseShortPair and Long for DenseIntPair) when used as that class type, not when used as DenseNumberPair. Expl. below
    • Added DenseFloatPair (optimizes as Long


    Spoiler for Explanation of optimization:

    Here's an example inline class: inline class IntWrapper(val wrappedValue: Int): Interface<Int>
    When you create an inline class, the compiler essentially turns all uses of that class in to the underlying value's class at runtime, and all the functions that take that inline class actually take the underlying value's class.
    This allows the compiler to optimize the example class's as an Int even though it implements an interface.
    This optimization is ONLY applicable when you use it as an IntWrapper in an example function fun takeIntWrapper(wrapper: IntWrapper). This function essentially compiles to take an Int, but you can't use it as such! Compiler tricks are crazy.
    If you use it as an Interface<Int>, it will not be optimized.
    Same thing as if you use it as IntWrapper? or a generic.


    NumberUtil: SOURCE/JAR
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  11. #20  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Update 2019/06/08

    Update NumberUtils to v1.2-0
    • DenseNumberPair now implements a new NumberPair interface.
    • DenseNumberPair and NumberPair now implement DenseNumberTuple and NumberTuple respectively.
    • Added NumberTriple and NumberQuad 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
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

Page 2 of 3 FirstFirst 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 21
    Last Post: 12-07-2017, 09:08 AM
  2. Replies: 20
    Last Post: 10-30-2012, 10:35 PM
  3. Replies: 4
    Last Post: 05-16-2007, 07:50 AM
  4. Replies: 7
    Last Post: 05-14-2007, 08:19 PM
  5. Replies: 6
    Last Post: 05-09-2007, 12:35 AM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •