Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// ============================================================================
// Copyright (c) 2017-2019 Nawapunth Manusitthipol (NawaMan - http://nawaman.net).
// ----------------------------------------------------------------------------
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ============================================================================
package functionalj.function;
public abstract class Annotated implements Named, Traced {
private final String toString;
protected Annotated(String type, String name) {
this(type, name, null);
}
protected Annotated(String type, String name, String location) {
this.toString = type + prefixWhenNotBlank("::", name) + prefixWhenNotBlank("@", location);
}
private String prefixWhenNotBlank(String prefix, String location) {
return ((location != null) && !location.isEmpty()) ? prefix + location : "";
}
public final String getName() {
return this.toString.replaceFirst("^.*::", "").replaceFirst("^(.*)(@.*)$", "$1");
}
public final String getLocation() {
return this.toString.replaceFirst("^.*::", "").replaceFirst("^.*@", "");
}
public final String toString() {
return toString;
}
/** Named predicate. **/
static class Predicate extends Annotated implements java.util.function.Predicate {
private final java.util.function.Predicate check;
/** Constructors. */
public Predicate(String name, String location, java.util.function.Predicate check) {
super("Predicate", name, location);
this.check = check;
}
/** Constructors. */
public Predicate(String name, java.util.function.Predicate check) {
super("Predicate", name);
this.check = check;
}
@Override
public boolean test(T t) {
return check.test(t);
}
}
/** Named predicate. **/
static class BiPredicate extends Annotated implements java.util.function.BiPredicate {
private final java.util.function.BiPredicate check;
/** Constructors. */
public BiPredicate(String name, String location, java.util.function.BiPredicate check) {
super("BiPredicate", name, location);
this.check = check;
}
/** Constructors. */
public BiPredicate(String name, java.util.function.BiPredicate check) {
super("BiPredicate", name);
this.check = check;
}
@Override
public boolean test(T t, U u) {
return check.test(t, u);
}
}
/** Named runnable. **/
static class Runnable extends Annotated implements java.lang.Runnable {
private final java.lang.Runnable runnable;
/** Constructors. */
public Runnable(String name, String location, java.lang.Runnable runnable) {
super("Runnable", name, location);
this.runnable = runnable;
}
/** Constructors. */
public Runnable(String name, java.lang.Runnable runnable) {
super("Runnable", name);
this.runnable = runnable;
}
@Override
public void run() {
runnable.run();
}
}
/** Named supplier */
static class Supplier extends Annotated implements java.util.function.Supplier {
private final java.util.function.Supplier supplier;
/** Constructors. */
public Supplier(String name, String location, java.util.function.Supplier supplier) {
super("Supplier", name, location);
this.supplier = supplier;
}
/** Constructors. */
public Supplier(String name, java.util.function.Supplier supplier) {
super("Supplier", name);
this.supplier = supplier;
}
@Override
public T get() {
return supplier.get();
}
}
/** Named consumer. **/
static class Consumer extends Annotated implements java.util.function.Consumer {
private final java.util.function.Consumer consumer;
/** Constructors. */
public Consumer(String name, String location, java.util.function.Consumer consumer) {
super("Consumer", name, location);
this.consumer = consumer;
}
/** Constructors. */
public Consumer(String name, java.util.function.Consumer consumer) {
super("Consumer", name);
this.consumer = consumer;
}
@Override
public void accept(T value) {
consumer.accept(value);
}
}
static class Func0