Java Code Examples for com.google.common.base.Preconditions#checkArgument()

The following examples show how to use com.google.common.base.Preconditions#checkArgument() . 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 File: DefaultMessagePoller.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
public DefaultMessagePoller(ConsumerConfig config, NameServerConfig nameServerConfig, ClusterManager clusterManager,
                            ClusterClientManager clusterClientManager, ConsumerClientManager consumerClientManager) {
    Preconditions.checkArgument(config != null, "consumer can not be null");
    Preconditions.checkArgument(nameServerConfig != null, "nameServer can not be null");
    Preconditions.checkArgument(clusterManager != null, "clusterManager can not be null");
    Preconditions.checkArgument(clusterClientManager != null, "clusterClientManager can not be null");
    Preconditions.checkArgument(consumerClientManager != null, "consumerClientManager can not be null");
    Preconditions.checkArgument(StringUtils.isNotBlank(config.getApp()), "consumer.app not blank");
    Preconditions.checkArgument(config.getPollTimeout() > config.getLongPollTimeout(), "consumer.pollTimeout must be greater than consumer.longPullTimeout");

    this.config = config;
    this.nameServerConfig = nameServerConfig;
    this.clusterManager = clusterManager;
    this.clusterClientManager = clusterClientManager;
    this.consumerClientManager = consumerClientManager;
}
 
Example 2
Source File: HdKeyNode.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Generate a master HD key node from a seed.
 * 
 * @param seed
 *           the seed to generate the master HD wallet key from.
 * @return a master HD key node for the seed
 * @throws KeyGenerationException
 *            if the seed is not suitable for seeding an HD wallet key
 *            generation. This is extremely unlikely
 */
public static HdKeyNode fromSeed(byte[] seed) throws KeyGenerationException {
   Preconditions.checkArgument(seed.length * 8 >= 128, "seed must be larger than 128");
   Preconditions.checkArgument(seed.length * 8 <= 512, "seed must be smaller than 512");
   byte[] I = Hmac.hmacSha512(asciiStringToBytes(BITCOIN_SEED), seed);

   // Construct private key
   byte[] IL = BitUtils.copyOfRange(I, 0, 32);
   BigInteger k = new BigInteger(1, IL);
   if (k.compareTo(Parameters.n) >= 0) {
      throw new KeyGenerationException(
            "An unlikely thing happened: The derived key is larger than the N modulus of the curve");
   }
   if (k.equals(BigInteger.ZERO)) {
      throw new KeyGenerationException("An unlikely thing happened: The derived key is zero");
   }
   InMemoryPrivateKey privateKey = new InMemoryPrivateKey(IL, true);

   // Construct chain code
   byte[] IR = BitUtils.copyOfRange(I, 32, 32 + CHAIN_CODE_SIZE);
   return new HdKeyNode(privateKey, IR, 0, 0, 0);
}
 
Example 3
Source File: CacheDirectiveInfo.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private Expiration(long ms, boolean isRelative) {
  if (isRelative) {
    Preconditions.checkArgument(ms <= MAX_RELATIVE_EXPIRY_MS,
        "Expiration time is too far in the future!");
  }
  this.ms = ms;
  this.isRelative = isRelative;
}
 
Example 4
Source File: Methods.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public MethodDiscoveryBuilder annotatedWith(Class<? extends Annotation> annotation) {
   Preconditions.checkNotNull(annotation, "annotation may not be null");
   Preconditions.checkArgument(isRuntimeRetained(annotation), "non-runtime annotations, can't be used here");

   this.annotations.add(annotation);
   return this;
}
 
Example 5
Source File: AddressManager.java    From artemis with Apache License 2.0 5 votes vote down vote up
public static AddressManager getRegistryAddressManager(final String clientId, final ArtemisClientManagerConfig managerConfig) {
    Preconditions.checkArgument(!StringValues.isNullOrWhitespace(clientId), "clientId");
    Preconditions.checkArgument(managerConfig != null, "manager config");
    return new AddressManager(managerConfig,
            new AddressRepository(clientId, managerConfig, RestPaths.CLUSTER_UP_REGISTRY_NODES_FULL_PATH)){
        @Override
        protected AddressContext newAddressContext() {
            return new AddressContext(clientId, managerConfig, _addressRepository.get(), WebSocketPaths.HEARTBEAT_DESTINATION);
        }
    };
}
 
Example 6
Source File: BroadcastMessagePoller.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
public BroadcastMessagePoller(ConsumerConfig config, NameServerConfig nameServerConfig, ClusterManager clusterManager, ConsumerClientManager consumerClientManager) {
    Preconditions.checkArgument(StringUtils.isNotBlank(config.getBroadcastGroup()), "consumer.broadcastGroup must be greater than 0");
    Preconditions.checkArgument(StringUtils.isNotBlank(config.getBroadcastLocalPath()), "consumer.broadcastLocalPath must not be null");

    this.config = config;
    this.nameServerConfig = nameServerConfig;
    this.clusterManager = clusterManager;
    this.consumerClientManager = consumerClientManager;
}
 
Example 7
Source File: BinlogHelper.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
void logTrailer(
    long seq,
    Status status,
    Metadata metadata,
    GrpcLogEntry.Logger logger,
    long callId,
    // null on server, can be non null on client if this is a trailer-only response
    @Nullable SocketAddress peerAddress) {
  Preconditions.checkArgument(
      peerAddress == null || logger == GrpcLogEntry.Logger.LOGGER_CLIENT,
      "peerSocket can only be specified for client");
  MaybeTruncated<io.grpc.binarylog.v1.Metadata.Builder> pair
      = createMetadataProto(metadata, maxHeaderBytes);

  io.grpc.binarylog.v1.Trailer.Builder trailerBuilder
      = io.grpc.binarylog.v1.Trailer.newBuilder()
      .setStatusCode(status.getCode().value())
      .setMetadata(pair.proto);
  String statusDescription = status.getDescription();
  if (statusDescription != null) {
    trailerBuilder.setStatusMessage(statusDescription);
  }
  byte[] statusDetailBytes = metadata.get(STATUS_DETAILS_KEY);
  if (statusDetailBytes != null) {
    trailerBuilder.setStatusDetails(ByteString.copyFrom(statusDetailBytes));
  }

  GrpcLogEntry.Builder entryBuilder = newTimestampedBuilder()
      .setSequenceIdWithinCall(seq)
      .setType(EventType.EVENT_TYPE_SERVER_TRAILER)
      .setTrailer(trailerBuilder)
      .setPayloadTruncated(pair.truncated)
      .setLogger(logger)
      .setCallId(callId);
  if (peerAddress != null) {
    entryBuilder.setPeer(socketToProto(peerAddress));
  }
  sink.write(entryBuilder.build());
}
 
Example 8
Source File: TimeOfDay.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static TimeOfDay fromString(String tod) {
   Matcher m = TOD_PATTERN.matcher(tod);
   Preconditions.checkArgument(m.matches(), "Invalid time of day [" + tod + "]");
   int hours = Integer.parseInt(m.group(1));
   int min = Integer.parseInt(m.group(2));
   int sec = Integer.parseInt(m.group(3));
   return new TimeOfDay(hours, min, sec);
}
 
Example 9
Source File: OmKeyInfo.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("parameternumber")
OmKeyInfo(String volumeName, String bucketName, String keyName,
    List<OmKeyLocationInfoGroup> versions, long dataSize,
    long creationTime, long modificationTime,
    HddsProtos.ReplicationType type,
    HddsProtos.ReplicationFactor factor,
    Map<String, String> metadata,
    FileEncryptionInfo encInfo, List<OzoneAcl> acls,
    long objectID, long updateID) {
  this.volumeName = volumeName;
  this.bucketName = bucketName;
  this.keyName = keyName;
  this.dataSize = dataSize;
  // it is important that the versions are ordered from old to new.
  // Do this sanity check when versions got loaded on creating OmKeyInfo.
  // TODO : this is not necessary, here only because versioning is still a
  // work in-progress, remove this following check when versioning is
  // complete and prove correctly functioning
  long currentVersion = -1;
  for (OmKeyLocationInfoGroup version : versions) {
    Preconditions.checkArgument(
          currentVersion + 1 == version.getVersion());
    currentVersion = version.getVersion();
  }
  this.keyLocationVersions = versions;
  this.creationTime = creationTime;
  this.modificationTime = modificationTime;
  this.factor = factor;
  this.type = type;
  this.metadata = metadata;
  this.encInfo = encInfo;
  this.acls = acls;
  this.objectID = objectID;
  this.updateID = updateID;
}
 
Example 10
Source File: CMODataTransport.java    From devops-cm-client with Apache License 2.0 5 votes vote down vote up
public CMODataTransport(String transportID, String developmentSystemID, Boolean isModifiable, String description, String owner) {

        Preconditions.checkArgument(! isNullOrEmpty(transportID), "transportId was null or empty.");
        this.transportID = transportID;
        this.developmentSystemID = developmentSystemID;
        this.isModifiable = isModifiable;
        this.description = description;
        this.owner = owner;
    }
 
Example 11
Source File: BrokerService.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
private NameService getNameService(BrokerContext brokerContext, Configuration configuration) {
    Property property = configuration.getProperty(NAMESERVICE_NAME);
    NameService nameService = Plugins.NAMESERVICE.get(property == null ? DEFAULT_NAMESERVICE_NAME : property.getString().trim());
    Preconditions.checkArgument(nameService != null, "nameService not found!");

    CompensatedNameService compensatedNameService = new CompensatedNameService(nameService);
    enrichIfNecessary(nameService, brokerContext);
    enrichIfNecessary(compensatedNameService, brokerContext);
    return compensatedNameService;
}
 
Example 12
Source File: Vector.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void addRow(ReadableQMatrix A, int i) {
  Preconditions.checkArgument(i >= 0);
  A.addToVector(this, i);
}
 
Example 13
Source File: CreateServiceResponse.java    From fc-java-sdk with MIT License 4 votes vote down vote up
public Boolean getInternetAccess() {
    Preconditions.checkArgument(serviceMetadata != null);
    return serviceMetadata.getInternetAccess();
}
 
Example 14
Source File: ShardingValueWrapper.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
public ShardingValueWrapper(final Comparable<?> value) {
    Preconditions.checkArgument(value instanceof Number || value instanceof Date || value instanceof String, 
            String.format("Value must be type of Number, Data or String, your value type is '%s'", value.getClass().getName()));
    this.value = value;
}
 
Example 15
Source File: 1_NodeUtil.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @return Whether a TRY node has a finally block.
 */
static boolean hasFinally(Node n) {
  Preconditions.checkArgument(n.getType() == Token.TRY);
  return n.getChildCount() == 3;
}
 
Example 16
Source File: CountDownLatchInjectionImpl.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void countDown() {
  Preconditions.checkNotNull(latch, "Latch not initialized in %s at %s.", siteClass.getSimpleName(), desc);
  Preconditions.checkArgument(latch.getCount() > 0, "Counting down on latch more than intended.");
  latch.countDown();
}
 
Example 17
Source File: MicrosoftTransferExtension.java    From data-transfer-project with Apache License 2.0 4 votes vote down vote up
@Override
public Importer<?, ?> getImporter(String transferDataType) {
  Preconditions.checkState(initialized);
  Preconditions.checkArgument(SUPPORTED_IMPORT_SERVICES.contains(transferDataType));
  return importerMap.get(transferDataType);
}
 
Example 18
Source File: RetryStrategyLibrary.java    From data-transfer-project with Apache License 2.0 4 votes vote down vote up
public RetryStrategyLibrary(@JsonProperty("strategyMappings") List<RetryMapping> retryMappings,
    @JsonProperty("defaultRetryStrategy") RetryStrategy defaultRetryStrategy) {
  Preconditions.checkArgument(defaultRetryStrategy != null, "Default retry strategy cannot be null");
  this.retryMappings = retryMappings;
  this.defaultRetryStrategy = defaultRetryStrategy;
}
 
Example 19
Source File: UpdateServiceResponse.java    From fc-java-sdk with MIT License 4 votes vote down vote up
public VpcConfig getVpcConfig() {
    Preconditions.checkArgument(serviceMetadata != null);
    return serviceMetadata.getVpcConfig();
}
 
Example 20
Source File: SpiderInfoDAO.java    From Gather-Platform with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 更新爬虫模板
 *
 * @param spiderInfo 爬虫模板实体
 * @return 爬虫模板id
 * @throws ExecutionException
 * @throws InterruptedException
 */
public String update(SpiderInfo spiderInfo) throws ExecutionException, InterruptedException {
    Preconditions.checkArgument(StringUtils.isNotBlank(spiderInfo.getId()), "待更新爬虫模板id不可为空");
    UpdateRequest updateRequest = new UpdateRequest(INDEX_NAME, TYPE_NAME, spiderInfo.getId());
    updateRequest.doc(gson.toJson(spiderInfo));
    UpdateResponse updateResponse = client.update(updateRequest).get();
    return updateResponse.getId();
}