下面列出了javax.annotation.Nonnegative#javax.annotation.CheckReturnValue 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Prepares for a check that the subject is deadline within the given tolerance of an
* expected value that will be provided in the next call in the fluent chain.
*/
@CheckReturnValue
public TolerantDeadlineComparison isWithin(final long delta, final TimeUnit timeUnit) {
return new TolerantDeadlineComparison() {
@Override
public void of(Deadline expected) {
Deadline actual = actual();
checkNotNull(actual, "actual value cannot be null. expected=%s", expected);
// This is probably overkill, but easier than thinking about overflow.
BigInteger actualTimeRemaining = BigInteger.valueOf(actual.timeRemaining(NANOSECONDS));
BigInteger expectedTimeRemaining = BigInteger.valueOf(expected.timeRemaining(NANOSECONDS));
BigInteger deltaNanos = BigInteger.valueOf(timeUnit.toNanos(delta));
if (actualTimeRemaining.subtract(expectedTimeRemaining).abs().compareTo(deltaNanos) > 0) {
failWithoutActual(
simpleFact(
lenientFormat(
"%s and <%s> should have been within <%sns> of each other",
actualAsString(), expected, deltaNanos)));
}
}
};
}
/** Returns {@code false} when client is misbehaving and should be disconnected. */
@CheckReturnValue
public boolean pingAcceptable() {
long now = ticker.nanoTime();
boolean valid;
if (!hasOutstandingCalls && !permitWithoutCalls) {
valid = compareNanos(lastValidPingTime + IMPLICIT_PERMIT_TIME_NANOS, now) <= 0;
} else {
valid = compareNanos(lastValidPingTime + minTimeNanos, now) <= 0;
}
if (!valid) {
pingStrikes++;
return !(pingStrikes > MAX_PING_STRIKES);
} else {
lastValidPingTime = now;
return true;
}
}
@Override
@CheckReturnValue
protected NettyServer buildTransportServer(
List<ServerStreamTracer.Factory> streamTracerFactories) {
ProtocolNegotiator negotiator = protocolNegotiator;
if (negotiator == null) {
negotiator = sslContext != null ? ProtocolNegotiators.serverTls(sslContext) :
ProtocolNegotiators.serverPlaintext();
}
return new NettyServer(
address, channelType, channelOptions, bossEventLoopGroup, workerEventLoopGroup,
negotiator, streamTracerFactories, transportTracerFactory,
maxConcurrentCallsPerConnection, flowControlWindow,
maxMessageSize, maxHeaderListSize, keepAliveTimeInNanos, keepAliveTimeoutInNanos,
maxConnectionIdleInNanos,
maxConnectionAgeInNanos, maxConnectionAgeGraceInNanos,
permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos, channelz);
}
/**
* @param patterns a collection of patterns to match
* @return a pattern that will match when any contained pattern matches
*/
@CheckReturnValue
public static Pattern or(Collection<? extends Pattern> patterns) {
// Simplify representation when there is only one alternative
if (patterns.size() == 1) {
return patterns.iterator().next();
}
return or(new LinkedHashSet<>(patterns));
}
@CheckReturnValue
@SuppressWarnings("unchecked")
default T where(U arg, U... args) {
ArrayList<U> argList = new ArrayList<>(args.length + 1);
argList.add(arg);
argList.addAll(Arrays.asList(args));
return where(argList);
}
@CheckReturnValue
public Graql.Token.Compute.Algorithm using() {
if (algorithm == null) {
return Graql.Token.Compute.Algorithm.DEGREE;
} else {
return algorithm;
}
}
@CheckReturnValue
default T of(String type, String... types) {
ArrayList<String> typeList = new ArrayList<>(types.length + 1);
typeList.add(type);
typeList.addAll(Arrays.asList(types));
return of(typeList);
}
/**
* @param type a concept type that this variable must be a kind of
* @return this
*/
@CheckReturnValue
default StatementType sub(Statement type) {
return sub(new SubProperty(type));
}
@CheckReturnValue
Optional<GraqlException> getException();
@CheckReturnValue
public static GraqlCompute.Builder compute() {
return new GraqlCompute.Builder();
}
@CheckReturnValue // TODO: will be made "private" once we upgrade to Java 9 or higher
StatementAttribute attribute(VarProperty property);
@CheckReturnValue
public static StatementAttribute neq(long value) {
return hiddenVar().neq(value);
}
@CheckReturnValue
public static StatementAttribute eq(Statement variable) {
return hiddenVar().eq(variable);
}
@CheckReturnValue
V where();
@CheckReturnValue
Set<String> in();
/**
* @param statements a collection of variable patterns to insert into the graph
* @return an insert query that will insert the given variable patterns into the graph
*/
@CheckReturnValue
public static GraqlInsert insert(Collection<? extends Statement> statements) {
return new GraqlInsert(null, Collections.unmodifiableList(new ArrayList<>(statements)));
}
/**
* @param patterns a collection of patterns to match in the graph
* @return a match clause that will find matches of the given patterns
*/
@CheckReturnValue
public static MatchClause match(Collection<? extends Pattern> patterns) {
return new MatchClause(and(Collections.unmodifiableSet(new LinkedHashSet<>(patterns))));
}
@CheckReturnValue
default StatementAttribute gt(double value) {
return gt(Comparison.Number::new, value);
}
@CheckReturnValue
public static <T extends Pattern> Disjunction<T> or(Set<T> patterns) {
return new Disjunction<>(patterns);
}
/**
* @param patterns an array of patterns to match in the graph
* @return a match clause that will find matches of the given patterns
*/
@CheckReturnValue
public static MatchClause match(Pattern... patterns) {
return match(Arrays.asList(patterns));
}
@CheckReturnValue
default StatementAttribute eq(long value) {
return eq(Comparison.Number::new, value);
}
/**
* @param type a concept type id that this variable must be a kind of
* @return this
*/
@CheckReturnValue
default StatementType sub(String type) {
return sub(Graql.type(type));
}
/**
* @param name the name of the variable
* @return a new statement with a variable of a given name
*/
@CheckReturnValue
public static Statement var(String name) {
return var(new Variable(name));
}
@CheckReturnValue
public static Pattern parsePattern(String pattern) {
return parser.parsePatternEOF(pattern);
}
@CheckReturnValue
default StatementType sub(SubProperty property) {
return type(property);
}
@CheckReturnValue
default StatementAttribute lt(Statement variable) {
return lt(Comparison.Variable::new, variable);
}
@CheckReturnValue
T attributes(boolean include);
@CheckReturnValue
public static StatementAttribute gt(long value) {
return hiddenVar().gt(value);
}
@CheckReturnValue
default StatementAttribute neq(String value) {
return neq(Comparison.String::new, value);
}
@CheckReturnValue
default StatementAttribute neq(LocalDateTime value) {
return neq(Comparison.DateTime::new, value);
}