List of usage examples for org.apache.commons.lang3.tuple Triple of
public static <L, M, R> Triple<L, M, R> of(final L left, final M middle, final R right)
Obtains an immutable triple of from three objects inferring the generic types.
This factory allows the triple to be created using inference to obtain the generic types.
From source file:at.gridtec.lambda4j.predicate.tri.ThrowableTriIntPredicate.java
/** * Returns a memoized (caching) version of this {@link ThrowableTriIntPredicate}. Whenever it is called, the mapping * between the input parameters and the return value is preserved in a cache, making subsequent calls returning the * memoized value instead of computing the return value again. * <p>//from w ww . j a va 2 s . co m * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code ThrowableTriIntPredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default ThrowableTriIntPredicate<X> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<Integer, Integer, Integer>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ThrowableTriIntPredicate<X> & Memoized) (value1, value2, value3) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3), ThrowableFunction .of(key -> testThrows(key.getLeft(), key.getMiddle(), key.getRight()))); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.obj.ObjBiIntPredicate.java
/** * Returns a memoized (caching) version of this {@link ObjBiIntPredicate}. Whenever it is called, the mapping * between the input parameters and the return value is preserved in a cache, making subsequent calls returning the * memoized value instead of computing the return value again. * <p>//from w ww . ja v a 2 s.c om * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code ObjBiIntPredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default ObjBiIntPredicate<T> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, Integer, Integer>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ObjBiIntPredicate<T> & Memoized) (t, value1, value2) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), key -> test(key.getLeft(), key.getMiddle(), key.getRight())); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.ThrowableTriBytePredicate.java
/** * Returns a memoized (caching) version of this {@link ThrowableTriBytePredicate}. Whenever it is called, the * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls * returning the memoized value instead of computing the return value again. * <p>/* www . j a v a2 s . c om*/ * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code ThrowableTriBytePredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default ThrowableTriBytePredicate<X> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<Byte, Byte, Byte>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ThrowableTriBytePredicate<X> & Memoized) (value1, value2, value3) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3), ThrowableFunction .of(key -> testThrows(key.getLeft(), key.getMiddle(), key.getRight()))); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.ThrowableTriLongPredicate.java
/** * Returns a memoized (caching) version of this {@link ThrowableTriLongPredicate}. Whenever it is called, the * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls * returning the memoized value instead of computing the return value again. * <p>/*from ww w .j a v a 2 s. co m*/ * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code ThrowableTriLongPredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default ThrowableTriLongPredicate<X> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<Long, Long, Long>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ThrowableTriLongPredicate<X> & Memoized) (value1, value2, value3) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3), ThrowableFunction .of(key -> testThrows(key.getLeft(), key.getMiddle(), key.getRight()))); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.ThrowableTriCharPredicate.java
/** * Returns a memoized (caching) version of this {@link ThrowableTriCharPredicate}. Whenever it is called, the * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls * returning the memoized value instead of computing the return value again. * <p>/* w ww . j a va 2 s . co m*/ * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code ThrowableTriCharPredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default ThrowableTriCharPredicate<X> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<Character, Character, Character>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ThrowableTriCharPredicate<X> & Memoized) (value1, value2, value3) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3), ThrowableFunction .of(key -> testThrows(key.getLeft(), key.getMiddle(), key.getRight()))); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.obj.ObjBiBooleanPredicate.java
/** * Returns a memoized (caching) version of this {@link ObjBiBooleanPredicate}. Whenever it is called, the mapping * between the input parameters and the return value is preserved in a cache, making subsequent calls returning the * memoized value instead of computing the return value again. * <p>//from w w w . j a va 2 s .com * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code ObjBiBooleanPredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default ObjBiBooleanPredicate<T> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, Boolean, Boolean>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ObjBiBooleanPredicate<T> & Memoized) (t, value1, value2) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), key -> test(key.getLeft(), key.getMiddle(), key.getRight())); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.obj.ObjBiLongPredicate.java
/** * Returns a memoized (caching) version of this {@link ObjBiLongPredicate}. Whenever it is called, the mapping * between the input parameters and the return value is preserved in a cache, making subsequent calls returning the * memoized value instead of computing the return value again. * <p>// w ww . j av a2 s. c o m * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code ObjBiLongPredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default ObjBiLongPredicate<T> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, Long, Long>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ObjBiLongPredicate<T> & Memoized) (t, value1, value2) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), key -> test(key.getLeft(), key.getMiddle(), key.getRight())); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.obj.ObjBiBytePredicate.java
/** * Returns a memoized (caching) version of this {@link ObjBiBytePredicate}. Whenever it is called, the mapping * between the input parameters and the return value is preserved in a cache, making subsequent calls returning the * memoized value instead of computing the return value again. * <p>/*w w w. j a v a 2 s . co m*/ * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code ObjBiBytePredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default ObjBiBytePredicate<T> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, Byte, Byte>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ObjBiBytePredicate<T> & Memoized) (t, value1, value2) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), key -> test(key.getLeft(), key.getMiddle(), key.getRight())); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.obj.ObjBiCharPredicate.java
/** * Returns a memoized (caching) version of this {@link ObjBiCharPredicate}. Whenever it is called, the mapping * between the input parameters and the return value is preserved in a cache, making subsequent calls returning the * memoized value instead of computing the return value again. * <p>//from w w w .j a va 2s . c o m * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code ObjBiCharPredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default ObjBiCharPredicate<T> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, Character, Character>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ObjBiCharPredicate<T> & Memoized) (t, value1, value2) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), key -> test(key.getLeft(), key.getMiddle(), key.getRight())); } return returnValue; }; } }
From source file:nya.miku.wishmaster.ui.GalleryActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) requestWindowFeature(Window.FEATURE_PROGRESS); settings = MainApplication.getInstance().settings; settings.getTheme().setTo(this, R.style.Transparent); super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) CompatibilityImpl.setActionBarNoIcon(this); downloadingLocker = MainApplication.getInstance().downloadingLocker; inflater = getLayoutInflater();//from w w w . j a v a 2 s . c o m instantiatedViews = new SparseArray<View>(); tnDownloadingTask = new CancellableTask.BaseCancellableTask(); tnDownloadingExecutor = Executors.newFixedThreadPool(4, PriorityThreadFactory.LOW_PRIORITY_FACTORY); fileCache = MainApplication.getInstance().fileCache; bitmapCache = MainApplication.getInstance().bitmapCache; AttachmentModel attachment = (AttachmentModel) getIntent().getSerializableExtra(EXTRA_ATTACHMENT); boardModel = (BoardModel) getIntent().getSerializableExtra(EXTRA_BOARDMODEL); if (boardModel == null) return; String pagehash = getIntent().getStringExtra(EXTRA_PAGEHASH); String localFilename = getIntent().getStringExtra(EXTRA_LOCALFILENAME); if (localFilename != null) { try { localFile = ReadableContainer.obtain(new File(localFilename)); } catch (Exception e) { Logger.e(TAG, "cannot open local file", e); } } chan = MainApplication.getInstance().getChanModule(boardModel.chan); PresentationModel presentationModel = MainApplication.getInstance().pagesCache .getPresentationModel(pagehash); if (presentationModel != null) { boolean isThread = presentationModel.source.pageModel.type == UrlPageModel.TYPE_THREADPAGE; customSubdir = BoardFragment.getCustomSubdir(presentationModel.source.pageModel); List<Triple<AttachmentModel, String, String>> list = presentationModel.getAttachments(); presentationModel = null; if (list != null) { int index = -1; String attachmentHash = ChanModels.hashAttachmentModel(attachment); for (int i = 0; i < list.size(); ++i) { if (list.get(i).getMiddle().equals(attachmentHash)) { index = i; break; } } if (index != -1) { if (isThread) { attachments = list; currentPosition = index; } else { int leftOffset = 0, rightOffset = 0; String threadNumber = list.get(index).getRight(); int it = index; while (it > 0 && list.get(--it).getRight().equals(threadNumber)) ++leftOffset; it = index; while (it < (list.size() - 1) && list.get(++it).getRight().equals(threadNumber)) ++rightOffset; attachments = list.subList(index - leftOffset, index + rightOffset + 1); currentPosition = leftOffset; } } } } if (attachments == null) { attachments = Collections.singletonList( Triple.of(attachment, ChanModels.hashAttachmentModel(attachment), (String) null)); currentPosition = 0; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && settings.fullscreenGallery()) { setContentView(R.layout.gallery_layout_fullscreen); GalleryFullscreen.initFullscreen(this); } else { setContentView(R.layout.gallery_layout); } progressBar = (ProgressBar) findViewById(android.R.id.progress); progressBar.setMax(Window.PROGRESS_END); viewPager = (ViewPager) findViewById(R.id.gallery_viewpager); navigationInfo = (TextView) findViewById(R.id.gallery_navigation_info); for (int id : new int[] { R.id.gallery_navigation_previous, R.id.gallery_navigation_next }) findViewById(id).setOnClickListener(this); viewPager.setAdapter(new GalleryAdapter()); viewPager.setCurrentItem(currentPosition); viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { currentPosition = position; updateItem(); } }); }