Example usage for org.apache.commons.lang ArrayUtils reverse

List of usage examples for org.apache.commons.lang ArrayUtils reverse

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils reverse.

Prototype

public static void reverse(boolean[] array) 

Source Link

Document

Reverses the order of the given array.

Usage

From source file:hudson.plugins.release.ReleaseWrapper.java

private VariableResolver<String> createVariableResolver(ParametersAction parametersAction,
        AbstractBuild<?, ?> build) {
    VariableResolver[] resolvers = new VariableResolver[parametersAction.getParameters().size() + 1];
    int i = 0;/*from   ww w.  j  a v a 2 s.  c  om*/
    for (ParameterValue p : parametersAction.getParameters())
        resolvers[i++] = p.createVariableResolver(build);

    resolvers[i] = build.getBuildVariableResolver();

    ArrayUtils.reverse(resolvers);

    return new VariableResolver.Union<String>(resolvers);
}

From source file:com.palantir.atlasdb.ptobject.EncodingUtils.java

public static byte[] encodeLittleEndian(long val) {
    byte[] bytes = PtBytes.toBytes(val);
    ArrayUtils.reverse(bytes);
    return bytes;
}

From source file:com.l2jfrozen.gameserver.geo.pathfinding.PathFinding.java

public final Node[] constructPath(Node node) {
    final ArrayList<Node> tmp = L2Collections.newArrayList();

    while (node.getParent() != null) {
        tmp.add(node);//from   w  w  w . j a va 2s.c o m

        node = node.getParent();
    }

    final Node[] path = tmp.toArray(new Node[tmp.size()]);

    L2Collections.recycle(tmp);

    ArrayUtils.reverse(path);

    for (int lastValid = 0; lastValid < path.length - 1;) {
        final Node lastValidNode = path[lastValid];

        int low = lastValid;
        int high = path.length - 1;

        while (low < high) {
            final int mid = ((low + high) >> 1) + 1;
            final Node midNode = path[mid];
            final int delta = mid - lastValid;
            final int deltaNodeX = Math.abs(midNode.getNodeX() - lastValidNode.getNodeX());
            final int deltaNodeY = Math.abs(midNode.getNodeY() - lastValidNode.getNodeY());

            if (delta <= 1) {
                low = mid;
            } else if (delta % 2 == 0 && deltaNodeX == delta / 2 && deltaNodeY == delta / 2) {
                low = mid;
            } else if (deltaNodeX == delta || deltaNodeY == delta) {
                low = mid;
            } else if (GeoData.getInstance().canMoveFromToTarget(lastValidNode.getX(), lastValidNode.getY(),
                    lastValidNode.getZ(), midNode.getX(), midNode.getY(), midNode.getZ())) {
                low = mid;
            } else {
                high = mid - 1;
            }
        }

        final int nextValid = low;

        for (int i = lastValid + 1; i < nextValid; i++)
            path[i] = null;

        lastValid = nextValid;
    }

    return L2Arrays.compact(path);
}

From source file:com.cubusmail.mail.util.MessageUtils.java

/**
 * Sort the messages./*from  ww w  .  j  a v  a  2  s  . c om*/
 * 
 * @param fieldName
 * @param ascending
 */
public static void sortMessages(Message[] msgs, String fieldName, boolean ascending) {

    if (msgs != null && msgs.length > 0) {
        if (!StringUtils.isEmpty(fieldName)) {
            Arrays.sort(msgs, new MessageComparator(fieldName, ascending));
        } else {
            // reverse order
            ArrayUtils.reverse(msgs);
        }
    }
}

From source file:com.kbot2.scriptable.methods.data.Walking.java

/**
 * Reverses a Tile array./*from   ww  w.  java 2  s . c  om*/
 *
 * @param in The Tile Array you want to reverse.
 * @return Returns a Tile array.
 * @author Alowaniak
 */
public static Tile[] reversePath(Tile[] in) {
    Tile[] out = (Tile[]) ArrayUtils.clone(in);
    ArrayUtils.reverse(out);
    return out;
}

From source file:de.dfki.iui.mmds.sdk.editors.grammar_rules.ContentListComposite.java

protected void moveDownSelectedElements(TableViewer tableViewer, EObject container,
        EStructuralFeature feature) {//  w  w  w .ja va  2s.c  o  m
    CompoundCommand subcommands = new CompoundCommand();
    int[] selectedIndices = tableViewer.getTable().getSelectionIndices();
    Arrays.sort(selectedIndices);
    ArrayUtils.reverse(selectedIndices);
    if (selectedIndices[0] == tableViewer.getTable().getItemCount() - 1)
        return;
    for (int i = 0; i < selectedIndices.length; ++i) {
        int sourceIndex, targetIndex;
        if (feature instanceof EAttribute) {
            sourceIndex = selectedIndices[i];
            targetIndex = selectedIndices[i] + 1;
        } else {
            sourceIndex = ((List) container.eGet(feature))
                    .indexOf(tableViewer.getElementAt(selectedIndices[i]));
            targetIndex = ((List) container.eGet(feature))
                    .indexOf(tableViewer.getElementAt(selectedIndices[i] + 1));
        }
        subcommands.append(
                new MoveCommand(editor.getEditingDomain(), container, feature, sourceIndex, targetIndex));
    }
    editor.getEditingDomain().getCommandStack().execute(subcommands.unwrap());
}

From source file:com.l2jfrozen.gameserver.geo.pathfinding.PathFinding.java

public final Node[] constructPath2(Node node) {
    final ArrayList<Node> tmp = L2Collections.newArrayList();
    int previousdirectionx = -1000;
    int previousdirectiony = -1000;
    int directionx;
    int directiony;
    while (node.getParent() != null) {
        // only add a new route point if moving direction changes
        directionx = node.getNodeX() - node.getParent().getNodeX();
        directiony = node.getNodeY() - node.getParent().getNodeY();
        if (directionx != previousdirectionx || directiony != previousdirectiony) {
            previousdirectionx = directionx;
            previousdirectiony = directiony;
            tmp.add(node);/* w w w .  j a  v a 2 s .  c  om*/
        }
        node = node.getParent();
    }

    final Node[] path = tmp.toArray(new Node[tmp.size()]);

    L2Collections.recycle(tmp);

    ArrayUtils.reverse(path);

    return path;
}

From source file:msi.gama.common.geometry.GamaCoordinateSequence.java

/**
 * Turns this sequence of coordinates into a clockwise orientation. Only done for rings (as it may change the
 * definition of line strings)//from   w  w  w  .j  a v a2 s .c o m
 * 
 * @param points
 * @return
 */
@Override
public void ensureClockwiseness() {
    if (!isRing(points)) {
        return;
    }
    if (signedArea(points) <= 0) {
        ArrayUtils.reverse(points);
    }
}

From source file:com.haulmont.cuba.core.sys.AbstractMessages.java

@Nullable
protected String searchIncludes(Properties properties, String key, Locale locale, Locale truncatedLocale,
        Set<String> passedPacks) {
    String includesProperty = properties.getProperty("@include");
    if (includesProperty != null) {
        // multiple includes separated by comma
        String[] includes = StringUtils.split(includesProperty, " ,");
        if (includes != null && includes.length > 0) {
            ArrayUtils.reverse(includes);
            for (String includePath : includes) {
                includePath = StringUtils.trimToNull(includePath);
                if (includePath != null) {
                    String message = searchMessage(includePath, key, locale, truncatedLocale, passedPacks);
                    if (message != null) {
                        return message;
                    }/*from   w w w.j a v  a  2s  .c  o  m*/
                }
            }
        }
    }
    return null;
}

From source file:com.core.controller.AlgoritmoController.java

public static Solucion aEstrellaConNodos(Grafo g, String inicio, String fin) {
    Solucion result = new Solucion("Algoritmo de busqueda A*");
    List<String> abiertos = new ArrayList<>();
    List<String> padresAbiertos = new ArrayList<>();
    List<Integer> valorFuncionAbiertos = new ArrayList<>();
    List<String> cerrados = new ArrayList<>();
    List<String> padresCerrados = new ArrayList<>();
    List<String> sucesores;
    String mejorNodo;//ww  w .j  a  v a 2 s . c o m
    int index;

    //Algoritmo A*
    abiertos.add(inicio);
    padresAbiertos.add("#");
    valorFuncionAbiertos.add(g.buscarNodo(inicio).getValor() + 0);
    while (true) {
        result.agregarPaso("PadresCerrados: " + padresCerrados);
        result.agregarPaso("Cerrados: " + cerrados);
        result.agregarPaso("Abiertos: " + abiertos);
        result.agregarPaso("ValorFun: " + valorFuncionAbiertos);
        int costoHastaNodoActual, heuristicaNodo, valorFun;
        String padre;

        //Si esta vacia devuelve error
        if (abiertos.isEmpty()) {
            result.agregarPaso("Error");
            break;
        }
        //Obtengo el mejor nodo de abiertos
        if (abiertos.size() == 1) {
            mejorNodo = abiertos.get(0);
        } else {
            mejorNodo = getMejorNodo(abiertos, valorFuncionAbiertos);
            result.agregarPaso("Mejor nodo: " + mejorNodo);
        }
        //Pregunto si es el nodo final
        if (mejorNodo.equals(fin)) {
            result.agregarPaso("Nodo fin alcanzado"); //Mostrar camino
            cerrados.add(mejorNodo);
            padresCerrados.add(padresAbiertos.get(abiertos.indexOf(mejorNodo)));
            String nodo = mejorNodo;
            ArrayList<String> secuenciaResultado = new ArrayList<>();
            //Mostrar el camino hasta la solucion
            while (true) {
                secuenciaResultado.add(nodo);
                nodo = padresCerrados.get(cerrados.indexOf(nodo));
                if (nodo.equals("#")) {
                    String[] r = new String[secuenciaResultado.size()];
                    for (int i = 0; i < r.length; i++) {
                        r[i] = secuenciaResultado.get(i);
                    }
                    ArrayUtils.reverse(r);
                    result.agregarPaso(Arrays.toString(r));
                    break;
                }
            }
            break;
        }
        index = abiertos.indexOf(mejorNodo);
        padre = padresAbiertos.get(index);
        //obtengo el costo hasta mejorNodo
        heuristicaNodo = g.buscarNodo(mejorNodo).getValor();
        costoHastaNodoActual = (valorFuncionAbiertos.get(index) - heuristicaNodo);
        //remuevo el nodo a ser explotado
        abiertos.remove(index);
        padresAbiertos.remove(index);
        valorFuncionAbiertos.remove(index);
        //lo agrego en cerrados
        cerrados.add(mejorNodo);
        padresCerrados.add(padre);
        //obtenemos los sucesores de mejor nodo
        sucesores = g.nodosVecinos(mejorNodo);

        for (int i = 0; i < sucesores.size(); i++) {
            heuristicaNodo = g.buscarNodo(sucesores.get(i)).getValor();
            valorFun = costoHastaNodoActual + (g.buscarArista(mejorNodo + "-" + sucesores.get(i))).getValor()
                    + heuristicaNodo;
            //pregunto si ya existe el noso en abiertos
            if (abiertos.contains(sucesores.get(i))) {
                index = abiertos.indexOf(sucesores.get(i));
                //Si ya existe pregunto si el nuevo nodo es mejor
                if (valorFuncionAbiertos.get(index) < valorFun) {
                    valorFuncionAbiertos.set(index, valorFun);
                    padresAbiertos.set(index, mejorNodo);
                }
            } else {
                //pregunto si esta en cerrados
                if (cerrados.contains(sucesores.get(i))) {
                    //no hacer nada
                } else {
                    abiertos.add(sucesores.get(i));
                    padresAbiertos.add(mejorNodo);
                    valorFuncionAbiertos.add(valorFun);
                }
            }
        } //fin for
    } //fin while
      //Verifico la solucion y la guardo en Solucion
    if (result.getPasos().contains("Nodo fin alcanzado")) {
        String solucion = result.getPasos().split("Nodo fin alcanzado\n")[1];
        String[] array = solucion.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(" ", "").split(",");
        //            ArrayUtils.reverse(array);
        for (String nombreNodo : array) {
            System.out.println("--------------------------------------");
            for (Map.Entry<String, Nodo> n : g.getNodos().entrySet()) {
                if (n.getKey().equals(nombreNodo)) {
                    System.out.println("Son iguales! Agregando " + nombreNodo + " a la lista");
                    result.getNodos().add(n.getValue());
                }
            }
        }

        System.out.println(
                "Nodos del resultado final en la lista: " + Arrays.toString(result.getNodos().toArray()));
    }
    return result;
}