Tabnine Logo
Collections.rotate
Code IndexAdd Tabnine to your IDE (free)

How to use
rotate
method
in
java.util.Collections

Best Java code snippets using java.util.Collections.rotate (Showing top 20 results out of 558)

origin: igniterealtime/Openfire

private Component getNextComponent() {
  Component component;
  synchronized (components) {
    component = components.get(0);
    Collections.rotate(components, 1);
  }
  return component;
}
origin: stackoverflow.com

Integer[] test = {1,2,3,4,5};
 Collections.rotate(Arrays.asList(test), -1);
 System.out.println(Arrays.toString(test));
 // prints "[2, 3, 4, 5, 1]"
origin: netty/netty

  @Override
  public void operationComplete(Future<List<InetAddress>> future) throws Exception {
    if (future.isSuccess()) {
      List<InetAddress> inetAddresses = future.getNow();
      if (!inetAddresses.isEmpty()) {
        // create a copy to make sure that it's modifiable random access collection
        List<InetAddress> result = new ArrayList<InetAddress>(inetAddresses);
        // rotate by different distance each time to force round robin distribution
        Collections.rotate(result, randomIndex(inetAddresses.size()));
        promise.setSuccess(result);
      } else {
        promise.setSuccess(inetAddresses);
      }
    } else {
      promise.setFailure(future.cause());
    }
  }
});
origin: redisson/redisson

  @Override
  public void operationComplete(Future<List<InetAddress>> future) throws Exception {
    if (future.isSuccess()) {
      List<InetAddress> inetAddresses = future.getNow();
      if (!inetAddresses.isEmpty()) {
        // create a copy to make sure that it's modifiable random access collection
        List<InetAddress> result = new ArrayList<InetAddress>(inetAddresses);
        // rotate by different distance each time to force round robin distribution
        Collections.rotate(result, randomIndex(inetAddresses.size()));
        promise.setSuccess(result);
      } else {
        promise.setSuccess(inetAddresses);
      }
    } else {
      promise.setFailure(future.cause());
    }
  }
});
origin: google/google-java-format

if (pos < lastPos) {
 List<List<AnnotationTree>> list = new ArrayList<>(dims);
 Collections.rotate(list, -(lastAnnotation + 1));
 return list;
origin: stackoverflow.com

 import java.util.*;
public class BinarySearch {
  static int findMinimum(Integer[] arr) {
    int low = 0;
    int high = arr.length - 1;
    while (arr[low] > arr[high]) {
      int mid = (low + high) >>> 1;
      if (arr[mid] > arr[high]) {
        low = mid + 1;
      } else {
        high = mid;
      }
    }
    return low;
  }
  public static void main(String[] args) {
    Integer[] arr = { 1, 2, 3, 4, 5, 6, 7 };
    // must be in sorted order, allowing rotation, and contain no duplicates

    for (int i = 0; i < arr.length; i++) {
      System.out.print(Arrays.toString(arr));
      int minIndex = findMinimum(arr);
      System.out.println(" Min is " + arr[minIndex] + " at " + minIndex);
      Collections.rotate(Arrays.asList(arr), 1);
    }
  }
}
origin: wildfly/wildfly

  @Override
  public void operationComplete(Future<List<InetAddress>> future) throws Exception {
    if (future.isSuccess()) {
      List<InetAddress> inetAddresses = future.getNow();
      if (!inetAddresses.isEmpty()) {
        // create a copy to make sure that it's modifiable random access collection
        List<InetAddress> result = new ArrayList<InetAddress>(inetAddresses);
        // rotate by different distance each time to force round robin distribution
        Collections.rotate(result, randomIndex(inetAddresses.size()));
        promise.setSuccess(result);
      } else {
        promise.setSuccess(inetAddresses);
      }
    } else {
      promise.setFailure(future.cause());
    }
  }
});
origin: primefaces/primefaces

@Override
public void decode(FacesContext context, DataTable table) {
  MethodExpression me = table.getDraggableRowsFunction();
  if (me != null) {
    me.invoke(context.getELContext(), new Object[]{table});
  }
  else {
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    String clientId = table.getClientId(context);
    int fromIndex = Integer.parseInt(params.get(clientId + "_fromIndex"));
    int toIndex = Integer.parseInt(params.get(clientId + "_toIndex"));
    table.setRowIndex(fromIndex);
    Object value = table.getValue();
    if (value instanceof List) {
      List list = (List) value;
      if (toIndex >= fromIndex) {
        Collections.rotate(list.subList(fromIndex, toIndex + 1), -1);
      }
      else {
        Collections.rotate(list.subList(toIndex, fromIndex + 1), 1);
      }
    }
    else {
      LOGGER.info("Row reordering is only available for list backed datatables, "
          + "use rowReorder ajax behavior with listener for manual handling of model update.");
    }
  }
}
origin: org.apache.commons/commons-math3

Collections.rotate(child1, lb);
Collections.rotate(child2, lb);
origin: apache/incubator-druid

@Test
public void smokeTest()
{
 ThreadLocalRandom r = ThreadLocalRandom.current();
 for (int i = 0; i < 1000; i++) {
  int numIterators = r.nextInt(1, 11);
  List<IntList> lists = new ArrayList<>(numIterators);
  for (int j = 0; j < numIterators; j++) {
   lists.add(new IntArrayList());
  }
  for (int j = 0; j < 50; j++) {
   lists.get(r.nextInt(numIterators)).add(j);
  }
  for (int j = 0; j < lists.size() + 1; j++) {
   assertAscending(mergeAscending(iteratorsFromLists(lists)));
   Collections.rotate(lists, 1);
  }
  for (int j = 0; j < 10; j++) {
   Collections.shuffle(lists);
   assertAscending(mergeAscending(iteratorsFromLists(lists)));
  }
 }
}
origin: soabase/exhibitor

private boolean advanceOrStartRollingConfig(ConfigCollection config, int rollingHostNamesIndex) throws Exception
{
  waitingForQuorumAttempts.set(0);
  List<String>        rollingHostNames = config.getRollingConfigState().getRollingHostNames();
  boolean             updateConfigResult;
  ConfigCollection    newCollection = checkNextInstanceState(config, rollingHostNames, rollingHostNamesIndex);
  if ( newCollection != null )
  {
    clearAttempts();
    updateConfigResult = internalUpdateConfig(newCollection);
  }
  else
  {
    if ( rollingHostNamesIndex < 0 )
    {
      // this is the start phase - park the bad instance in the back for now
      List<String>        newRollingHostNames = Lists.newArrayList(rollingHostNames);
      Collections.rotate(newRollingHostNames, -1);
      ConfigCollection        collection = new ConfigCollectionImpl(config.getRootConfig(), config.getRollingConfig(), newRollingHostNames, rollingHostNamesIndex + 1);
      clearAttempts();
      updateConfigResult = internalUpdateConfig(collection);
    }
    else
    {
      updateConfigResult = true;
    }
  }
  return updateConfigResult;
}
origin: apache/incubator-druid

/**
 * Check for some possible corner cases, because {@link IntIteratorUtils.MergeIntIterator} is
 * implemented using packing ints within longs, that is prone to some overflow or sign bit extension bugs
 */
@Test
public void testOverflow()
{
 List<IntList> lists = Lists.newArrayList(
   IntLists.singleton(Integer.MIN_VALUE),
   IntLists.singleton(Integer.MIN_VALUE),
   IntLists.singleton(-1),
   IntLists.singleton(0),
   IntLists.singleton(MAX_VALUE)
 );
 for (int i = 0; i < lists.size() + 1; i++) {
  assertAscending(mergeAscending(iteratorsFromLists(lists)));
  Collections.rotate(lists, 1);
 }
 Collections.shuffle(lists);
 assertAscending(mergeAscending(iteratorsFromLists(lists)));
}
origin: diffplug/spotless

  @Test
  public void cycleOrder() {
    BiConsumer<String, String> testCase = (unorderedStr, canonical) -> {
      List<String> unordered = Arrays.asList(unorderedStr.split(","));
      for (int i = 0; i < unordered.size(); ++i) {
        // try every rotation of the list
        Collections.rotate(unordered, 1);
        PaddedCell result = CYCLE.create(folder.getRoot(), unordered);
        // make sure the canonical result is always the appropriate one
        Assert.assertEquals(canonical, result.canonical());
      }
    };
    // alphabetic
    testCase.accept("a,b,c", "a");
    // length
    testCase.accept("a,aa,aaa", "a");
    // length > alphabetic
    testCase.accept("b,aa,aaa", "b");
  }
}
origin: aterai/java-swing-tips

public void next() {
 if (running) {
  // list.add(list.remove(0));
  Collections.rotate(list, 1);
 }
}
origin: stackoverflow.com

 public static <T> List<T> rotate(List<T> aL, int shift) {
  List<T> newValues = new ArrayList<>(aL);
  Collections.rotate(newValues, shift);
  return newValues;
}
origin: jvelo/mayocat-shop

  public static void move(List<?> collection, int indexToMoveFrom, int indexToMoveAt)
  {
    if (indexToMoveAt >= indexToMoveFrom) {
      Collections.rotate(collection.subList(indexToMoveFrom, indexToMoveAt + 1), -1);
    } else {
      Collections.rotate(collection.subList(indexToMoveAt, indexToMoveFrom + 1), 1);
    }
  }
}
origin: stackoverflow.com

List<Character> list = Arrays.asList(
   'a','b','c','d','e','f','g','h','i','j','k','l'
 );
 System.out.println(list);
 // [a, b, c, d, e, f, g, h, i, j, k, l]
 //     *  *  *  *  *
 System.out.println(list.subList(1, 6));
 // [b, c, d, e, f]
 Collections.rotate(list.subList(1, 6), -2);
 System.out.println(list);
 // [a, d, e, f, b, c, g, h, i, j, k, l]
 //     *  *  *  *  *
origin: nroduit/Weasis

public void toFront(Graphic graphic) {
  List<Graphic> list = graphicManager.getModels();
  synchronized (list) {
    for (int i = 0; i < list.size(); i++) {
      if (list.get(i).equals(graphic)) {
        Collections.rotate(list.subList(i, list.size()), -1);
        break;
      }
    }
  }
  repaint();
}
origin: tinyMediaManager/tinyMediaManager

 @Override
 public void actionPerformed(ActionEvent e) {
  int row = listGenres.getSelectedIndex();
  if (row < genres.size() - 1) {
   Collections.rotate(genres.subList(row, row + 2), -1);
   listGenres.getSelectionModel().setSelectionInterval(row + 1, row + 1);
  }
 }
}
origin: tinyMediaManager/tinyMediaManager

 @Override
 public void actionPerformed(ActionEvent e) {
  int row = listTags.getSelectedIndex();
  if (row < tags.size() - 1) {
   Collections.rotate(tags.subList(row, row + 2), -1);
   listTags.getSelectionModel().setSelectionInterval(row + 1, row + 1);
  }
 }
}
java.utilCollectionsrotate

Javadoc

Rotates the elements in list by the distance dist

e.g. for a given list with elements [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], calling rotate(list, 3) or rotate(list, -7) would modify the list to look like this: [8, 9, 0, 1, 2, 3, 4, 5, 6, 7]

Popular methods of Collections

  • emptyList
    Returns the empty list (immutable). This list is serializable.This example illustrates the type-safe
  • sort
  • singletonList
    Returns an immutable list containing only the specified object. The returned list is serializable.
  • unmodifiableList
    Returns an unmodifiable view of the specified list. This method allows modules to provide users with
  • emptyMap
    Returns the empty map (immutable). This map is serializable.This example illustrates the type-safe w
  • emptySet
    Returns the empty set (immutable). This set is serializable. Unlike the like-named field, this metho
  • unmodifiableMap
    Returns an unmodifiable view of the specified map. This method allows modules to provide users with
  • singleton
    Returns an immutable set containing only the specified object. The returned set is serializable.
  • unmodifiableSet
    Returns an unmodifiable view of the specified set. This method allows modules to provide users with
  • singletonMap
    Returns an immutable map, mapping only the specified key to the specified value. The returned map is
  • addAll
    Adds all of the specified elements to the specified collection. Elements to be added may be specifie
  • reverse
    Reverses the order of the elements in the specified list. This method runs in linear time.
  • addAll,
  • reverse,
  • unmodifiableCollection,
  • shuffle,
  • enumeration,
  • list,
  • synchronizedMap,
  • synchronizedList,
  • reverseOrder,
  • emptyIterator

Popular in Java

  • Reading from database using SQL prepared statement
  • getSupportFragmentManager (FragmentActivity)
  • setRequestProperty (URLConnection)
  • setContentView (Activity)
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • JComboBox (javax.swing)
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now