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:ec.edu.chyc.manejopersonal.managebean.GestorArticulo.java

public void moverAbajo(PersonaArticulo personaArticuloMover, Integer indexActual) {
    if (indexActual != listaPersonaArticulo.size() - 1) {
        Collections.swap(listaPersonaArticulo, indexActual, indexActual + 1);
    }// w ww.  j  a  va2 s .  c o m
}

From source file:com.predic8.membrane.core.transport.http.ConnectionManager.java

public Connection getConnection(InetAddress host, int port, String localHost, SSLProvider sslProvider,
        int connectTimeout) throws UnknownHostException, IOException {

    log.debug("connection requested for host: " + host + " and port: " + port);

    log.debug("Number of connections in pool: " + numberInPool.get());

    ConnectionKey key = new ConnectionKey(host, port);
    long now = System.currentTimeMillis();

    synchronized (this) {
        ArrayList<OldConnection> l = availableConnections.get(key);
        if (l != null) {
            int i = l.size() - 1;
            while (i >= 0) {
                OldConnection c = l.get(i);
                if (c.deathTime > now) {
                    l.remove(i);/*w ww.  j  a va2  s  .  co m*/
                    return c.connection;
                }
                Collections.swap(l, 0, i);
                i--;
            }
        }
    }

    Connection result = Connection.open(host, port, localHost, sslProvider, this, connectTimeout);
    numberInPool.incrementAndGet();
    return result;
}

From source file:org.videolan.vlc.gui.audio.PlaylistAdapter.java

@Override
public void onItemMove(int fromPosition, int toPosition) {
    Collections.swap(mDataSet, fromPosition, toPosition);
    Collections.swap(mOriginalDataSet, fromPosition, toPosition);
    notifyItemMoved(fromPosition, toPosition);
    mHandler.obtainMessage(PlaylistHandler.ACTION_MOVE, fromPosition, toPosition).sendToTarget();
}

From source file:com.example.admin.news.mvp.ui.adapter.NewsChannelAdapter.java

@Override
public boolean onItemMove(int fromPosition, int toPosition) {
    if (isChannelFixed(fromPosition, toPosition)) {
        return false;
    }//from  www .ja  va  2s  .  c  o  m
    Collections.swap(mList, fromPosition, toPosition);
    notifyItemMoved(fromPosition, toPosition);
    RxBus.getInstance().post(new ChannelItemMoveEvent(fromPosition, toPosition));
    return true;
}

From source file:com.heliosdecompiler.helios.gui.controller.PathEditorController.java

@FXML
private void down(MouseEvent event) {
    int selected = list.getSelectionModel().getSelectedIndex();
    if (selected != -1) {
        if (selected < list.getItems().size() - 1) {
            Collections.swap(list.getItems(), selected, selected + 1);
            this.list.getSelectionModel().select(selected + 1);
        } else {/* w w  w .j a v  a2  s.  co m*/
            this.list.getSelectionModel().select(this.list.getItems().size() - 1);
        }
        this.list.requestFocus();
    }
}

From source file:com.zmf.editablelist.EditListAdapter.java

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

From source file:org.squale.welcom.struts.action.WForwardAction.java

/**
 * @see org.squale.welcom.struts.action.WAction#wExecute(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *//*from w  w  w . ja  va 2  s .c om*/
public ActionForward wExecute(final ActionMapping mapping, final ActionForm form,
        final HttpServletRequest request, final HttpServletResponse response)
        throws IOException, ServletException, JspException {
    final String oldAction = request.getParameter("oldAction");

    // Permer de rester dansle contexte.
    final String forward = request.getParameter("wforward");
    if (forward != null) {
        return mapping.findForward(forward);
    }

    if (!GenericValidator.isBlankOrNull(oldAction)) {
        // Effectue le populate
        final ModuleConfig moduleConfig = mapping.getModuleConfig();
        final String path = ServletUtils.processPath(servlet, request, response, oldAction, moduleConfig);
        final ActionMapping mappingGenerique = ServletUtils.processMapping(request, response, moduleConfig,
                path);

        if (mappingGenerique != null) {
            // Process any ActionForm bean related to this request
            final ActionForm formGenerique = ServletUtils.processActionForm(request, response, moduleConfig,
                    mappingGenerique, servlet);

            // remis a zero
            // Dactive si optimization.checkbox.javascript a true
            if (Util.isFalse(WelcomConfigurator.getMessage(WelcomConfigurator.OPTIFLUX_AUTORESET_CHECKBOX))) {
                InternalTableUtil.razCheckBoxListe(request, formGenerique);
            }

            // Appele le reset du formulaire
            formGenerique.reset(mappingGenerique, request);

            // Effectue la populate
            ServletUtils.processPopulate(request, response, formGenerique, mappingGenerique, servlet);

            // on gere le cas ColOrder :
            final String action = request.getParameter("action");
            if ((action != null) && (action.equals("order"))) {
                final String property = request.getParameter("property");
                final String sens = request.getParameter("sens");
                final List list = (List) LayoutUtils.getProperty(formGenerique,
                        request.getParameter("collection"));
                final int index1 = Integer.parseInt(request.getParameter("position"));
                int index2;
                final Object obj1 = list.get(index1);
                Object obj2;
                if (sens.equals("up")) {
                    index2 = index1 - 1;
                    obj2 = list.get(index2);
                } else {
                    index2 = index1 + 1;
                    obj2 = list.get(index2);
                }
                // on echange la property d'ordre
                final Object oldProperty1 = LayoutUtils.getProperty(obj1, property);
                final Object oldProperty2 = LayoutUtils.getProperty(obj2, property);
                LayoutUtils.setProperty(obj1, property, oldProperty2);
                LayoutUtils.setProperty(obj2, property, oldProperty1);

                // on modifie l'ordre dans la liste
                Collections.swap(list, index1, index2);

                // on position a true l'attribut changed :
                ((WIChanged) obj1).setChanged(true);
                ((WIChanged) obj2).setChanged(true);
            }

        }
    }

    final String referer = request.getParameter("requestURI");

    if (!GenericValidator.isBlankOrNull(referer) && (referer.length() > 1) && (referer.charAt(0) == '/')) {
        final String contextPath = request.getContextPath();

        if (referer.indexOf(contextPath, 0) > -1) {
            return new ActionForward(referer.substring(contextPath.length(), referer.length()));
        } else {
            return new ActionForward(referer);
        }
    } else {
        return new ActionForward(referer);
    }
}

From source file:org.schreibubi.JCombinations.jfreechart.XYLineAndShapeRendererExtended.java

private void sort(ArrayList<Double> x, ArrayList<Double> yl, ArrayList<Double> yh) {
    for (int i = x.size(); --i >= 0;) {
        boolean swapped = false;
        for (int j = 0; j < i; j++)
            if (x.get(j) > x.get(j + 1)) {
                Collections.swap(x, j, j + 1);
                Collections.swap(yl, j, j + 1);
                Collections.swap(yh, j, j + 1);
                swapped = true;/*from  w  w  w. j  a  v  a  2  s . c  o m*/
            }
        if (!swapped)
            return;
    }
}

From source file:org.apache.cayenne.modeler.util.CayenneTableModel.java

protected void swapRows(int i, int j) {
    Collections.swap(objectList, i, j);
    fireTableDataChanged();
}

From source file:com.ejwa.dinja.demo.model.RubiksCube.java

public void roll(Vector3f axis) {
    if (axis.equals(Vector3f.POSITIVE_X_AXIS) || axis.equals(Vector3f.POSITIVE_Y_AXIS)
            || axis.equals(Vector3f.POSITIVE_Z_AXIS)) {
        for (int j = 0; j < sliceToRoll.length - 2; j++) {
            Collections.swap(boxSections, sliceToRoll[j], sliceToRoll[j + 2]);
        }//from w w  w  . ja  va2s. co  m
    } else if (axis.equals(Vector3f.NEGATIVE_X_AXIS) || axis.equals(Vector3f.NEGATIVE_Y_AXIS)
            || axis.equals(Vector3f.NEGATIVE_Z_AXIS)) {
        for (int j = sliceToRoll.length - 1; j >= 2; j--) {
            Collections.swap(boxSections, sliceToRoll[j], sliceToRoll[j - 2]);
        }
    }
}