Example usage for org.apache.commons.lang3.tuple MutablePair MutablePair

List of usage examples for org.apache.commons.lang3.tuple MutablePair MutablePair

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple MutablePair MutablePair.

Prototype

public MutablePair(final L left, final R right) 

Source Link

Document

Create a new pair instance.

Usage

From source file:org.opendaylight.lispflowmapping.implementation.LispMappingService.java

@Override
public void handleMapNotify(MapNotify notify, List<TransportAddress> rlocs) {
    tlsMapNotify.set(new MutablePair<MapNotify, List<TransportAddress>>(notify, rlocs));
}

From source file:org.opendaylight.lispflowmapping.implementation.LispMappingService.java

@Override
public void handleNonProxyMapRequest(MapRequest mapRequest, TransportAddress transportAddress) {
    tlsMapRequest.set(new MutablePair<MapRequest, TransportAddress>(mapRequest, transportAddress));
}

From source file:org.opendaylight.sxp.route.core.RouteReactorZipImpl.java

@Override
public ListenableFuture<Void> updateRouting(@Nullable final SxpClusterRoute oldRoute,
        @Nullable final SxpClusterRoute newRoute) {
    // with state compression
    ListenableFuture<Void> futureResult;
    try {//from w  ww.j  a  va2s.  co  m
        queueGuard.acquire();

        if (compressionQueue.isEmpty()) {
            compressionQueue.add(new MutablePair<>(oldRoute, newRoute));
            // schedule task
            futureResult = servicePool.submit(updateRouteTask);
        } else {
            // compress, expect that task is already scheduled
            compressionQueue.peek().setRight(newRoute);
            futureResult = COMPRESSED_FUTURE_RESULT;
            LOG.trace("route update request got state compressed - firing immediate future");
        }

        queueGuard.release();
    } catch (Exception e) {
        LOG.warn("failed to get lock upon compression queue: {}", e.getMessage());
        futureResult = Futures.immediateFailedFuture(e);
    }
    return futureResult;
}

From source file:org.opendaylight.sxp.route.core.RouteReactorZipImpl.java

@Override
public ListenableFuture<Void> wipeRouting() {
    ListenableFuture<Void> futureResult;
    try {//  w ww. j a  v  a2 s.  co m
        queueGuard.acquire();

        if (compressionQueue.isEmpty()) {
            compressionQueue.add(new MutablePair<>(null, WIPE_ROUTING_MARK));
            // schedule task
            futureResult = servicePool.submit(updateRouteTask);
        } else {
            // compress, expect that task is already scheduled
            compressionQueue.peek().setRight(WIPE_ROUTING_MARK);
            futureResult = COMPRESSED_FUTURE_RESULT;
            LOG.trace("route update request got state compressed - firing immediate future");
        }

        queueGuard.release();
    } catch (Exception e) {
        LOG.warn("failed to get lock upon compression queue: {}", e.getMessage());
        futureResult = Futures.immediateFailedFuture(e);
    }
    return futureResult;
}

From source file:org.opentestsystem.shared.test.cooperation.StageImpl.java

@Override
public synchronized List<Cue> listenForCues(final CuePattern pattern) throws InterruptedException {
    List<Cue> ans = getCurrentCues(pattern);

    if (ans.size() == 0) {
        // Didn't find a retained cue that matches the pattern, so we wait for
        // one./* ww w.jav  a  2 s.  c  om*/
        final MutablePair<CuePattern, Cue> pr = new MutablePair<CuePattern, Cue>(pattern, null);
        _waitingPatterns.add(pr);
        while (pr.getRight() == null) {
            wait();
        }
        ans.add(pr.getRight());
    }
    return ans;
}

From source file:org.shaman.terrain.sketch.Graph.java

public void addEdge(int u, int v, float weight) {
    ArrayList<MutablePair<Integer, Float>> n1 = graph.get(u);
    ArrayList<MutablePair<Integer, Float>> n2 = graph.get(v);
    n1.add(new MutablePair<>(v, weight));
    n2.add(new MutablePair<>(u, weight));
}

From source file:org.uma.jmetal.util.experiment.component.GenerateFriedmanTestTables.java

private double[] computeAverageRanking(Vector<Vector<Double>> data) {
    /*Compute the average performance per algorithm for each data set*/
    double[][] mean = new double[numberOfProblems][numberOfAlgorithms];

    for (int j = 0; j < numberOfAlgorithms; j++) {
        for (int i = 0; i < numberOfProblems; i++) {
            mean[i][j] = data.elementAt(j).elementAt(i);
        }/*  ww  w .j a v a  2  s .  com*/
    }

    /*We use the Pair class to compute and order rankings*/
    List<List<Pair<Integer, Double>>> order = new ArrayList<List<Pair<Integer, Double>>>(numberOfProblems);

    for (int i = 0; i < numberOfProblems; i++) {
        order.add(new ArrayList<Pair<Integer, Double>>(numberOfAlgorithms));
        for (int j = 0; j < numberOfAlgorithms; j++) {
            order.get(i).add(new ImmutablePair<Integer, Double>(j, mean[i][j]));
        }
        Collections.sort(order.get(i), new Comparator<Pair<Integer, Double>>() {
            @Override
            public int compare(Pair<Integer, Double> pair1, Pair<Integer, Double> pair2) {
                if (Math.abs(pair1.getValue()) > Math.abs(pair2.getValue())) {
                    return 1;
                } else if (Math.abs(pair1.getValue()) < Math.abs(pair2.getValue())) {
                    return -1;
                } else {
                    return 0;
                }
            }
        });
    }

    /*building of the rankings table per algorithms and data sets*/
    // Pair[][] rank = new Pair[numberOfProblems][numberOfAlgorithms];
    List<List<MutablePair<Double, Double>>> rank = new ArrayList<List<MutablePair<Double, Double>>>(
            numberOfProblems);

    int position = 0;
    for (int i = 0; i < numberOfProblems; i++) {
        rank.add(new ArrayList<MutablePair<Double, Double>>(numberOfAlgorithms));
        for (int j = 0; j < numberOfAlgorithms; j++) {
            boolean found = false;
            for (int k = 0; k < numberOfAlgorithms && !found; k++) {
                if (order.get(i).get(k).getKey() == j) {
                    found = true;
                    position = k + 1;
                }
            }
            //rank[i][j] = new Pair(position,order[i][position-1].value);
            rank.get(i).add(new MutablePair<Double, Double>((double) position,
                    order.get(i).get(position - 1).getValue()));
        }
    }

    /*In the case of having the same performance, the rankings are equal*/
    for (int i = 0; i < numberOfProblems; i++) {
        boolean[] hasBeenVisited = new boolean[numberOfAlgorithms];
        Vector<Integer> pendingToVisit = new Vector<Integer>();

        Arrays.fill(hasBeenVisited, false);
        for (int j = 0; j < numberOfAlgorithms; j++) {
            pendingToVisit.removeAllElements();
            double sum = rank.get(i).get(j).getKey();
            hasBeenVisited[j] = true;
            int ig = 1;
            for (int k = j + 1; k < numberOfAlgorithms; k++) {
                if (rank.get(i).get(j).getValue() == rank.get(i).get(k).getValue() && !hasBeenVisited[k]) {
                    sum += rank.get(i).get(k).getKey();
                    ig++;
                    pendingToVisit.add(k);
                    hasBeenVisited[k] = true;
                }
            }
            sum /= (double) ig;
            rank.get(i).get(j).setLeft(sum);
            for (int k = 0; k < pendingToVisit.size(); k++) {
                rank.get(i).get(pendingToVisit.elementAt(k)).setLeft(sum);
            }
        }
    }

    /*compute the average ranking for each algorithm*/
    double[] averageRanking = new double[numberOfAlgorithms];
    for (int i = 0; i < numberOfAlgorithms; i++) {
        averageRanking[i] = 0;
        for (int j = 0; j < numberOfProblems; j++) {
            averageRanking[i] += rank.get(j).get(i).getKey() / ((double) numberOfProblems);
        }
    }

    return averageRanking;
}

From source file:ste.web.http.HttpUtils.java

public static Pair<String, String> parseBasicAuth(final Header authorization) {
    String authString = getAuthString(authorization);

    Pair<String, String> pair = null;

    if (authString != null) {
        int p = authString.indexOf(':');
        if (p > 0) {
            String login = authString.substring(0, p);
            pair = new MutablePair<>(login, authString.substring(p + 1));
        } else if (p < 0) {
            pair = new MutablePair<>(authString, null);
        }//from w ww  .j a  v a 2  s.c  o m
    }

    return pair;
}

From source file:storm.lrb.bolt.DailyExpenditureBolt.java

@Override
public void execute(Tuple tuple) {

    Fields fields = tuple.getFields();/*from w  w w.j  a v  a 2 s.  co  m*/

    if (fields.contains(TopologyControl.DAILY_EXPEDITURE_REQUEST_FIELD_NAME)) {

        DaiExpRequest exp = (DaiExpRequest) tuple
                .getValueByField(TopologyControl.DAILY_EXPEDITURE_REQUEST_FIELD_NAME);
        String out;
        int vehicleIdentifier = exp.getVehicleIdentifier();
        Values values;
        if (this.tollAccounts.containsKey(vehicleIdentifier)) {
            LOG.debug("ExpenditureRequest: found vehicle identifier %d", vehicleIdentifier);
            Pair<Integer, Integer> key = new MutablePair<Integer, Integer>(exp.getSegmentIdentifier().getxWay(),
                    exp.getDay());

            int toll = this.tollAccounts.get(exp.getVehicleIdentifier()).get(key);

            LOG.debug("3, %d, %d, %d, %d", exp.getTime(), exp.getEmitTime(), exp.getQueryIdentifier(), toll);

            values = new Values(LRBtuple.TYPE_DAILY_EXPEDITURE, exp.getTime(), exp.getEmitTime(),
                    exp.getQueryIdentifier(), toll);
        } else {
            values = new Values(LRBtuple.TYPE_DAILY_EXPEDITURE, exp.getTime(), exp.getEmitTime(),
                    exp.getQueryIdentifier(), Constants.INITIAL_TOLL);

        }
        this.collector.emit(values);
    }
    this.collector.ack(tuple);
}

From source file:tk.playerforcehd.networklib.bungee.socket.server.NS_NetServerSocket.java

/**
 * Start the Server/*from w w w.j av a2 s. c o  m*/
 */
@Override
public void open() throws IOException {
    if (this.log) {
        this.main.getLogger().info("The plugin " + this.ownerPlugin.getDescription().getName()
                + " is opening a Messaging Server at port: " + this.port + "...");
    }
    this.listen = true;
    this.serverSocket = new ServerSocket(this.port);
    this.socketDisconnectListenerTask = ProxyServer.getInstance().getScheduler().runAsync(this.ownerPlugin,
            () -> {
                while (this.listen) {
                    Collection<Pair<NetSocketConnection, ScheduledTask>> tmp_disconnectSockets = new ArrayList<>();
                    for (Pair<NetSocketConnection, ScheduledTask> netSocketConnection : this.netSocketConnections) {
                        NS_NetSocketConnection nsc = (NS_NetSocketConnection) netSocketConnection.getLeft();
                        if (!nsc.getSocket().isConnected()) {
                            try {
                                nsc.stopLoop();
                                nsc.getSocket().close();
                                netSocketConnection.getRight().cancel();
                                tmp_disconnectSockets.add(netSocketConnection);
                                close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    for (Pair<NetSocketConnection, ScheduledTask> tmp_disconnectSocket : tmp_disconnectSockets) {
                        netSocketConnections.remove(tmp_disconnectSocket);
                    }
                    try {
                        Thread.sleep(4000L);
                    } catch (InterruptedException e) {
                    }
                }
            });
    this.acceptLoopTask = ProxyServer.getInstance().getScheduler().runAsync(this.ownerPlugin, () -> {
        while (listen) {
            Socket socket;
            try {
                socket = serverSocket.accept();
                NS_NetSocketConnection NSNetSocketConnection = new NS_NetSocketConnection(socket,
                        NSNetServerSocket);
                ScheduledTask asyncFuture = ProxyServer.getInstance().getScheduler().runAsync(ownerPlugin,
                        NSNetSocketConnection::readLoop);
                netSocketConnections.add(new MutablePair<>(NSNetSocketConnection, asyncFuture));
            } catch (IOException e) {
                if (!e.getMessage().equalsIgnoreCase("socket closed")) {
                    e.printStackTrace();
                }
            }
        }
    });
    if (this.log) {
        this.main.getLogger().info("Messaging Server on port " + this.port + " has been opened!");
    }
}