Search in sources :

Example 96 with Pair

use of mpicbg.trakem2.util.Pair in project Tusky by tuskyapp.

the class TimelineFragment method findStatusAndPosition.

@Nullable
private Pair<StatusViewData.Concrete, Integer> findStatusAndPosition(int position, Status status) {
    StatusViewData.Concrete statusToUpdate;
    int positionToUpdate;
    StatusViewData someOldViewData = statuses.getPairedItem(position);
    // Unlikely, but data could change between the request and response
    if ((someOldViewData instanceof StatusViewData.Placeholder) || !((StatusViewData.Concrete) someOldViewData).getId().equals(status.getId())) {
        // try to find the status we need to update
        int foundPos = statuses.indexOf(Either.<Placeholder, Status>right(status));
        // okay, it's hopeless, give up
        if (foundPos < 0)
            return null;
        statusToUpdate = ((StatusViewData.Concrete) statuses.getPairedItem(foundPos));
        positionToUpdate = position;
    } else {
        statusToUpdate = (StatusViewData.Concrete) someOldViewData;
        positionToUpdate = position;
    }
    return new Pair<>(statusToUpdate, positionToUpdate);
}
Also used : StatusViewData(com.keylesspalace.tusky.viewdata.StatusViewData) Pair(android.support.v4.util.Pair) Nullable(android.support.annotation.Nullable)

Example 97 with Pair

use of mpicbg.trakem2.util.Pair in project LibreraReader by foobnix.

the class CacheZipUtils method isSingleAndSupportEntry.

public static Pair<Boolean, String> isSingleAndSupportEntry(InputStream is) {
    if (is == null) {
        return new Pair<Boolean, String>(false, "");
    }
    String name = "";
    try {
        ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(is, "cp1251");
        boolean find = false;
        ZipArchiveEntry nextEntry = null;
        while ((nextEntry = zipInputStream.getNextZipEntry()) != null) {
            name = nextEntry.getName();
            if (find) {
                zipInputStream.close();
                is.close();
                return new Pair<Boolean, String>(false, "");
            }
            find = true;
        }
        zipInputStream.close();
        is.close();
    } catch (Exception e) {
        LOG.e(e);
    }
    return new Pair<Boolean, String>(BookType.isSupportedExtByPath(name), name);
}
Also used : ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Pair(android.support.v4.util.Pair)

Example 98 with Pair

use of mpicbg.trakem2.util.Pair in project incubator-gobblin by apache.

the class CouchbaseWriterTest method writeRecords.

private List<Pair<AbstractDocument, Future>> writeRecords(Iterator<AbstractDocument> recordIterator, CouchbaseWriter writer, int outstandingRequests, long kvTimeout, TimeUnit kvTimeoutUnit) throws DataConversionException, UnsupportedEncodingException {
    final BlockingQueue<Pair<AbstractDocument, Future>> outstandingCallQueue = new LinkedBlockingDeque<>(outstandingRequests);
    final List<Pair<AbstractDocument, Future>> failedFutures = new ArrayList<>(outstandingRequests);
    int index = 0;
    long runTime = 0;
    final AtomicInteger callbackSuccesses = new AtomicInteger(0);
    final AtomicInteger callbackFailures = new AtomicInteger(0);
    final ConcurrentLinkedDeque<Throwable> callbackExceptions = new ConcurrentLinkedDeque<>();
    Verifier verifier = new Verifier();
    while (recordIterator.hasNext()) {
        AbstractDocument doc = recordIterator.next();
        index++;
        verifier.onWrite(doc);
        final long startTime = System.nanoTime();
        Future callFuture = writer.write(doc, new WriteCallback<TupleDocument>() {

            @Override
            public void onSuccess(WriteResponse<TupleDocument> writeResponse) {
                callbackSuccesses.incrementAndGet();
            }

            @Override
            public void onFailure(Throwable throwable) {
                callbackFailures.incrementAndGet();
                callbackExceptions.add(throwable);
            }
        });
        drainQueue(outstandingCallQueue, 1, kvTimeout, kvTimeoutUnit, failedFutures);
        outstandingCallQueue.add(new Pair<>(doc, callFuture));
        runTime += System.nanoTime() - startTime;
    }
    int failedWrites = 0;
    long responseStartTime = System.nanoTime();
    drainQueue(outstandingCallQueue, outstandingRequests, kvTimeout, kvTimeoutUnit, failedFutures);
    runTime += System.nanoTime() - responseStartTime;
    for (Throwable failure : callbackExceptions) {
        System.out.println(failure.getClass() + " : " + failure.getMessage());
    }
    failedWrites += failedFutures.size();
    System.out.println("Total time to send " + index + " records = " + runTime / 1000000.0 + "ms, " + "Failed writes = " + failedWrites + " Callback Successes = " + callbackSuccesses.get() + "Callback Failures = " + callbackFailures.get());
    verifier.verify(writer.getBucket());
    return failedFutures;
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ArrayList(java.util.ArrayList) TupleDocument(org.apache.gobblin.couchbase.common.TupleDocument) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) AbstractDocument(com.couchbase.client.java.document.AbstractDocument) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Future(java.util.concurrent.Future) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Pair(org.apache.commons.math3.util.Pair)

Example 99 with Pair

use of mpicbg.trakem2.util.Pair in project iobserve-analysis by research-iobserve.

the class BehaviorModelTable method toInstance.

/**
 * returns an instance vector.
 *
 * @return instance
 */
public Instance toInstance() {
    final List<Double> attValues = new ArrayList<>();
    // add transitions
    for (int i = 0; i < this.signatures.size(); i++) {
        for (int j = 0; j < this.signatures.size(); j++) {
            if (this.transitions[i][j] > AbstractBehaviorModelTable.TRANSITION_THRESHOLD) {
                attValues.add(Double.valueOf(this.transitions[i][j]));
            } else {
                continue;
            }
        }
    }
    this.signatures.values().stream().forEach(pair -> Arrays.stream(pair.getSecond()).forEach(callInformation -> attValues.add(callInformation.getRepresentativeCode())));
    final double[] attArray = new double[attValues.size()];
    for (int i = 0; i < attValues.size(); i++) {
        attArray[i] = attValues.get(i) == null ? 0.0 : attValues.get(i);
    }
    final Instance instance = new Instance(1.0, attArray);
    return instance;
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) FastVector(weka.core.FastVector) Pair(org.apache.commons.math3.util.Pair) SingleOrNoneCollector(org.iobserve.analysis.clustering.SingleOrNoneCollector) Instances(weka.core.Instances) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) Instance(weka.core.Instance) List(java.util.List) Map(java.util.Map) Optional(java.util.Optional) Attribute(weka.core.Attribute) Instance(weka.core.Instance) ArrayList(java.util.ArrayList)

Example 100 with Pair

use of mpicbg.trakem2.util.Pair in project mvpanimation by androidMVP.

the class ExpandingAdapter method createSafeTransitionParticipants.

public Pair<View, String>[] createSafeTransitionParticipants(@NonNull Activity activity, boolean includeStatusBar, @Nullable Pair... otherParticipants) {
    // Avoid system UI glitches as described here:
    // https://plus.google.com/+AlexLockwood/posts/RPtwZ5nNebb
    View decor = activity.getWindow().getDecorView();
    View statusBar = null;
    if (includeStatusBar) {
        statusBar = decor.findViewById(android.R.id.statusBarBackground);
    }
    View navBar = decor.findViewById(android.R.id.navigationBarBackground);
    // Create pair of transition participants.
    List<Pair> participants = new ArrayList<>(3);
    addNonNullViewToTransitionParticipants(statusBar, participants);
    addNonNullViewToTransitionParticipants(navBar, participants);
    // only add transition participants if there's at least one none-null element
    if (otherParticipants != null && !(otherParticipants.length == 1 && otherParticipants[0] == null)) {
        participants.addAll(Arrays.asList(otherParticipants));
    }
    return participants.toArray(new Pair[participants.size()]);
}
Also used : ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Pair(android.support.v4.util.Pair)

Aggregations

Pair (android.support.v4.util.Pair)79 ArrayList (java.util.ArrayList)39 View (android.view.View)28 Pair (org.apache.commons.math3.util.Pair)20 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)16 TextView (android.widget.TextView)15 Intent (android.content.Intent)14 List (java.util.List)13 ImageView (android.widget.ImageView)10 ByteProcessor (ij.process.ByteProcessor)9 RecyclerView (android.support.v7.widget.RecyclerView)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AlertDialog (android.support.v7.app.AlertDialog)7 Pair (mpicbg.trakem2.util.Pair)7 NonNull (android.support.annotation.NonNull)6 Patch (ini.trakem2.display.Patch)6 OsmandSettings (net.osmand.plus.OsmandSettings)6 DialogInterface (android.content.DialogInterface)5 IOException (java.io.IOException)5