Class PositionUpdater

java.lang.Object
com.mewna.catnip.rest.guild.PositionUpdater

public class PositionUpdater extends Object
An updater for positions of things like roles and channels.

Consider a set of channels like the following:

 
 #channel (id 123, pos 0)
 #channel (id 125, pos 1)
 #channel (id 193, pos 2)
 
 
Suppose you wanted to change the order from (123, 125, 193) to (193, 123, 125). You could accomplish this with something like:
 
 updater
     .select("123").position(1)
     .select("125").position(2)
     .select("193").position(0);
 
 
which, in action, looks something like:
 
 0.    123 ----|
 1. |- 125     |
 2. |  193 -   |
    |      |   |
 0. |  193 <   |
 1. |  123 <---|
 2. |> 125
 
 

Or alternatively:

 
 // Add all channels
 updater
     .select("123").position(0)
     .select("125").position(0)
     .select("193").position(0);

 // Relative movements
 updater
     .select("123").increment()
     .select("125").increment()
     .select("125").increment();
 
 
When objects have the same position, Discord will sort them by their snowflake. So the second example looks something like:
 
 // Initial state
 0.  123
 1.  125
 2.  193

 // All channels added to updater
 // Remember that they're sorted by snowflake
 0.  123
 0.  125
 0.  193

 // .select("123").increment()
 0.  123 --|
 0.  125   |
 0.  193   |
           |
 0.  125   |
 0.  193   |
 1.  123 <-|

 // .select("125").increment()
 0.  125 --|
 0.  193   |
 1.  123   |
           |
 0.  193   |
 1.  123   |
 1.  125 <-|

 // .select("125").increment()
 0.  193
 1.  123
 1.  125 --|
           |
 0.  193   |
 1.  123   |
 2.  125 <-|
 
 
While in this example, and in many real-world examples, we could just leave the positions the same and let snowflake-sorting figure it out, it's most likely better overall to have proper positions specified, so that the snowflake-sorting doesn't surprise you.
  • Constructor Details

    • PositionUpdater

      public PositionUpdater(String guildId, boolean reverseOrder)
  • Method Details