Example usage for java.util Collections swap

List of usage examples for java.util Collections swap

Introduction

In this page you can find the example usage for java.util Collections swap.

Prototype

private static void swap(Object[] arr, int i, int j) 

Source Link

Document

Swaps the two specified elements in the specified array.

Usage

From source file:com.metinkale.prayerapp.vakit.fragments.SortFragment.java

public void onItemMove(int fromPosition, int toPosition) {
    if (fromPosition < toPosition) {
        for (int i = fromPosition; i < toPosition; i++) {
            Collections.swap(mAdapter.ids, i, i + 1);
        }/*w  w  w  .  j  a  va 2 s.  c o  m*/
    } else {
        for (int i = fromPosition; i > toPosition; i--) {
            Collections.swap(mAdapter.ids, i, i - 1);
        }
    }
    mAdapter.notifyItemMoved(fromPosition, toPosition);

    Times.drop(fromPosition, toPosition);
}

From source file:org.betaconceptframework.astroboa.console.jsf.edit.MultipleSimpleCmsPropertyWrapper.java

private void swapPropertyValuePositions(Integer fromIndex, Integer toIndex) {

    if (CollectionUtils.isEmpty(simpleCmsPropertyValueWrappers)) {
        logger.error("List of values is empty. This method should never be invoked when value list is empty");
        JSFUtilities.addMessage(null, "object.edit.swapPropertyValuePositions.failed", null,
                FacesMessage.SEVERITY_WARN);
        return;//from   ww w.  j  a  v  a2s  .  c  o m
    }

    if (cmsProperty.swapValues(fromIndex, toIndex)) {

        SimpleCmsPropertyValueWrapper fromSimpleCmsPropertyValueWrapper = simpleCmsPropertyValueWrappers
                .get(fromIndex);
        SimpleCmsPropertyValueWrapper toSimpleCmsPropertyValueWrapper = simpleCmsPropertyValueWrappers
                .get(toIndex);

        fromSimpleCmsPropertyValueWrapper.changeIndex(toIndex);
        toSimpleCmsPropertyValueWrapper.changeIndex(fromIndex);

        Collections.swap(simpleCmsPropertyValueWrappers, fromIndex, toIndex);
    } else {
        JSFUtilities.addMessage(null, "object.edit.swapPropertyValuePositions.failed", null,
                FacesMessage.SEVERITY_WARN);
    }
}

From source file:com.ymsfd.practices.ui.adapter.fancy.RecyclerListAdapter.java

@Override
public void onItemMove(int fromPosition, int toPosition) {
    Collections.swap(mItems, fromPosition, toPosition);
    notifyItemMoved(fromPosition, toPosition);
}

From source file:eu.power_switch.gui.adapter.RoomNameRecyclerViewAdapter.java

@Override
public void onItemMove(int fromPosition, int toPosition) {
    if (fromPosition < toPosition) {
        for (int i = fromPosition; i < toPosition; i++) {
            Collections.swap(rooms, i, i + 1);
        }// ww w  . j ava  2  s .com
    } else {
        for (int i = fromPosition; i > toPosition; i--) {
            Collections.swap(rooms, i, i - 1);
        }
    }

    notifyItemMoved(fromPosition, toPosition);
}

From source file:de.kuschku.quasseldroid_ng.ui.coresettings.network.server.NetworkServerAdapter.java

@Override
public boolean onItemMove(int fromPosition, int toPosition) {
    Collections.swap(servers, fromPosition, toPosition);
    notifyItemMoved(fromPosition, toPosition);
    return true;/*from  w ww .jav a2s .c o m*/
}

From source file:eu.power_switch.gui.adapter.ReceiverNameRecyclerViewAdapter.java

@Override
public void onItemMove(int fromPosition, int toPosition) {
    if (fromPosition < toPosition) {
        for (int i = fromPosition; i < toPosition; i++) {
            Collections.swap(receivers, i, i + 1);
        }//w  ww . j  a  v  a  2  s . c om
    } else {
        for (int i = fromPosition; i > toPosition; i--) {
            Collections.swap(receivers, i, i - 1);
        }
    }

    notifyItemMoved(fromPosition, toPosition);
}

From source file:com.example.sascha.mealdecisionhelper.adapter.RecyclerListAdapter.java

@Override
public boolean onItemMove(int fromPosition, int toPosition) {
    Collections.swap(categoriesList, fromPosition, toPosition);
    notifyItemMoved(fromPosition, toPosition);

    return true;// w w  w  .  j a v a  2 s  .  c o m
}

From source file:com.myframe.www.widget.dragandswipewithrecyclerview.RecyclerListAdapter.java

@Override
public boolean onItemMove(int fromPosition, int toPosition) {
    Collections.swap(mDatas, fromPosition, toPosition);
    notifyItemMoved(fromPosition, toPosition);
    return true;//from w  ww .j a  v a  2  s .  co  m
}

From source file:liam.franco.selene.fragments.SuperNotesFragment.java

public void updateNote(int oldPosition) {
    if (getAdapter() != null && getAdapter().getAdapterItemCount() > 0) {
        Collections.swap(getAdapter().getAdapterItems(), oldPosition, 0);
        getAdapter().notifyAdapterItemMoved(oldPosition, 0);
    }/* w  ww . j  a v  a  2  s .c o m*/
}

From source file:org.openmrs.module.facilitydata.web.controller.FacilityDataFormSchemaController.java

@RequestMapping("/module/facilitydata/moveSection.form")
public String moveSection(ModelMap map, @RequestParam(required = true) FacilityDataFormSchema schema,
        @RequestParam(required = true) Integer existingIndex, @RequestParam(required = true) Integer newIndex)
        throws Exception {

    Collections.swap(schema.getSections(), existingIndex, newIndex);
    Context.getService(FacilityDataService.class).saveFacilityDataFormSchema(schema);
    return String.format("redirect:schema.form?id=%s", schema.getId());
}