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);
}
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);
}
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;
}
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;
}
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()]);
}
Aggregations