use of net.imglib2.util.Pair in project mica2 by obiba.
the class AbstractFileSystemResource method doGetAttachment.
protected Attachment doGetAttachment(String path, @Nullable String version, @Nullable String shareKey) {
String basePath = normalizePath(path);
if (isPublishedFileSystem())
subjectAclService.checkAccess("/file", basePath);
else
subjectAclService.checkPermission("/draft/file", "VIEW", basePath, shareKey);
if (path.endsWith("/"))
throw new IllegalArgumentException("Folder download is not supported");
Pair<String, String> pathName = FileSystemService.extractPathName(basePath);
AttachmentState state = fileSystemService.getAttachmentState(pathName.getKey(), pathName.getValue(), isPublishedFileSystem());
if (isPublishedFileSystem())
return state.getPublishedAttachment();
if (Strings.isNullOrEmpty(version))
return state.getAttachment();
List<Attachment> attachments = fileSystemService.getAttachmentRevisions(state).stream().filter(a -> a.getId().equals(version)).collect(Collectors.toList());
if (attachments.isEmpty())
throw new NoSuchElementException("No file version " + version + " found at path: " + basePath);
return attachments.get(0);
}
use of net.imglib2.util.Pair in project android_packages_apps_crDroidSettings by crdroidandroid.
the class PagerSlidingTabStrip method getIndicatorCoordinates.
public Pair<Float, Float> getIndicatorCoordinates() {
// default: line below current tab
View currentTab = mTabsContainer.getChildAt(mCurrentPosition);
float lineLeft = currentTab.getLeft();
float lineRight = currentTab.getRight();
// if there is an offset, start interpolating left and right coordinates between current and next tab
if (mCurrentPositionOffset > 0f && mCurrentPosition < mTabCount - 1) {
View nextTab = mTabsContainer.getChildAt(mCurrentPosition + 1);
final float nextTabLeft = nextTab.getLeft();
final float nextTabRight = nextTab.getRight();
lineLeft = (mCurrentPositionOffset * nextTabLeft + (1f - mCurrentPositionOffset) * lineLeft);
lineRight = (mCurrentPositionOffset * nextTabRight + (1f - mCurrentPositionOffset) * lineRight);
}
return new Pair<>(lineLeft, lineRight);
}
use of net.imglib2.util.Pair in project incubator-gobblin by apache.
the class CouchbaseWriter method write.
@Override
public Future<WriteResponse> write(final D record, final WriteCallback callback) {
assertRecordWritable(record);
if (record instanceof TupleDocument) {
((TupleDocument) record).content().value1().retain();
}
Observable<D> observable = _bucket.async().upsert(record);
if (callback == null) {
return new WriteResponseFuture<>(observable.timeout(_operationTimeout, _operationTimeunit).toBlocking().toFuture(), _defaultWriteResponseMapper);
} else {
final AtomicBoolean callbackFired = new AtomicBoolean(false);
final BlockingQueue<Pair<WriteResponse, Throwable>> writeResponseQueue = new ArrayBlockingQueue<>(1);
final Future<WriteResponse> writeResponseFuture = new Future<WriteResponse>() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return callbackFired.get();
}
@Override
public WriteResponse get() throws InterruptedException, ExecutionException {
Pair<WriteResponse, Throwable> writeResponseThrowablePair = writeResponseQueue.take();
return getWriteResponseorThrow(writeResponseThrowablePair);
}
@Override
public WriteResponse get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
Pair<WriteResponse, Throwable> writeResponseThrowablePair = writeResponseQueue.poll(timeout, unit);
if (writeResponseThrowablePair == null) {
throw new TimeoutException("Timeout exceeded while waiting for future to be done");
} else {
return getWriteResponseorThrow(writeResponseThrowablePair);
}
}
};
observable.timeout(_operationTimeout, _operationTimeunit).subscribe(new Subscriber<D>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
callbackFired.set(true);
writeResponseQueue.add(new Pair<WriteResponse, Throwable>(null, e));
callback.onFailure(e);
}
@Override
public void onNext(D doc) {
try {
callbackFired.set(true);
WriteResponse writeResponse = new GenericWriteResponse<D>(doc);
writeResponseQueue.add(new Pair<WriteResponse, Throwable>(writeResponse, null));
callback.onSuccess(writeResponse);
} finally {
if (doc instanceof TupleDocument) {
((TupleDocument) doc).content().value1().release();
}
}
}
});
return writeResponseFuture;
}
}
use of net.imglib2.util.Pair in project Signal-Android by signalapp.
the class PagingMediaLoader method loadInBackground.
@Nullable
@Override
public Pair<Cursor, Integer> loadInBackground() {
long threadId = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(recipient);
Cursor cursor = DatabaseFactory.getMediaDatabase(getContext()).getGalleryMediaForThread(threadId);
while (cursor != null && cursor.moveToNext()) {
AttachmentId attachmentId = new AttachmentId(cursor.getLong(cursor.getColumnIndexOrThrow(AttachmentDatabase.ATTACHMENT_ID_ALIAS)), cursor.getLong(cursor.getColumnIndexOrThrow(AttachmentDatabase.UNIQUE_ID)));
Uri attachmentUri = PartAuthority.getAttachmentDataUri(attachmentId);
if (attachmentUri.equals(uri)) {
return new Pair<>(cursor, leftIsRecent ? cursor.getPosition() : cursor.getCount() - 1 - cursor.getPosition());
}
}
return null;
}
use of net.imglib2.util.Pair in project iobserve-analysis by research-iobserve.
the class BehaviorModelTable method toInstances.
/**
* create an Instances object for clustering.
*
* @return instance
*/
public Instances toInstances() {
final FastVector fastVector = new FastVector();
// 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) {
final Attribute attribute = new Attribute(AbstractBehaviorModelTable.EDGE_INDICATOR + this.inverseSignatures[i] + AbstractBehaviorModelTable.EDGE_DIVIDER + this.inverseSignatures[j]);
fastVector.addElement(attribute);
} else {
continue;
}
}
}
// add informations
this.signatures.values().stream().forEach(pair -> Arrays.stream(pair.getSecond()).forEach(callInformation -> fastVector.addElement(new Attribute(AbstractBehaviorModelTable.INFORMATION_INDICATOR + this.inverseSignatures[pair.getFirst()] + AbstractBehaviorModelTable.INFORMATION_DIVIDER + callInformation.getSignature()))));
// TODO name
final Instances instances = new Instances("Test", fastVector, 0);
final Instance instance = this.toInstance();
instances.add(instance);
return instances;
}
Aggregations