Java Code Examples for javax.annotation.CheckReturnValue

The following examples show how to use javax.annotation.CheckReturnValue. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: grpc-nebula-java   Source File: DeadlineSubject.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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)));
      }
    }
  };
}
 
Example 2
Source Project: grpc-nebula-java   Source File: KeepAliveEnforcer.java    License: Apache License 2.0 6 votes vote down vote up
/** 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;
  }
}
 
Example 3
Source Project: grpc-nebula-java   Source File: NettyServerBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @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));
}
 
Example 5
Source Project: graql   Source File: Computable.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 6
Source Project: graql   Source File: GraqlCompute.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@CheckReturnValue
public Graql.Token.Compute.Algorithm using() {
    if (algorithm == null) {
        return Graql.Token.Compute.Algorithm.DEGREE;
    } else {
        return algorithm;
    }
}
 
Example 7
Source Project: graql   Source File: Computable.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 8
/**
 * @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));
}
 
Example 9
Source Project: graql   Source File: Computable.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@CheckReturnValue
Optional<GraqlException> getException();
 
Example 10
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@CheckReturnValue
public static GraqlCompute.Builder compute() {
    return new GraqlCompute.Builder();
}
 
Example 11
@CheckReturnValue   // TODO: will be made "private" once we upgrade to Java 9 or higher
StatementAttribute attribute(VarProperty property);
 
Example 12
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@CheckReturnValue
public static StatementAttribute neq(long value) {
    return hiddenVar().neq(value);
}
 
Example 13
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@CheckReturnValue
public static StatementAttribute eq(Statement variable) {
    return hiddenVar().eq(variable);
}
 
Example 14
Source Project: graql   Source File: Computable.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@CheckReturnValue
V where();
 
Example 15
Source Project: graql   Source File: Computable.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@CheckReturnValue
Set<String> in();
 
Example 16
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @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)));
}
 
Example 17
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @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))));
}
 
Example 18
@CheckReturnValue
default StatementAttribute gt(double value) {
    return gt(Comparison.Number::new, value);
}
 
Example 19
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@CheckReturnValue
public static <T extends Pattern> Disjunction<T> or(Set<T> patterns) {
    return new Disjunction<>(patterns);
}
 
Example 20
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @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));
}
 
Example 21
@CheckReturnValue
default StatementAttribute eq(long value) {
    return eq(Comparison.Number::new, value);
}
 
Example 22
/**
 * @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));
}
 
Example 23
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @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));
}
 
Example 24
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@CheckReturnValue
public static Pattern parsePattern(String pattern) {
    return parser.parsePatternEOF(pattern);
}
 
Example 25
@CheckReturnValue
default StatementType sub(SubProperty property) {
    return type(property);
}
 
Example 26
@CheckReturnValue
default StatementAttribute lt(Statement variable) {
    return lt(Comparison.Variable::new, variable);
}
 
Example 27
Source Project: graql   Source File: Computable.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@CheckReturnValue
T attributes(boolean include);
 
Example 28
Source Project: graql   Source File: Graql.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@CheckReturnValue
public static StatementAttribute gt(long value) {
    return hiddenVar().gt(value);
}
 
Example 29
@CheckReturnValue
default StatementAttribute neq(String value) {
    return neq(Comparison.String::new, value);
}
 
Example 30
@CheckReturnValue
default StatementAttribute neq(LocalDateTime value) {
    return neq(Comparison.DateTime::new, value);
}