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

The following examples show how to use com.google.common.base.Preconditions#checkNotNull() . 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
public MasterInstance build() {
    Preconditions.checkNotNull(instanceId, "Instance id not set");
    Preconditions.checkNotNull(instanceGroupId, "Instance group id not set");
    Preconditions.checkNotNull(ipAddress, "ip address not set");
    Preconditions.checkNotNull(status, "status not set");

    this.statusHistory = Evaluators.getOrDefault(statusHistory, Collections.emptyList());
    this.serverPorts = Evaluators.getOrDefault(serverPorts, Collections.emptyList());
    this.labels = Evaluators.getOrDefault(labels, Collections.emptyMap());
    return new MasterInstance(instanceId, instanceGroupId, ipAddress, status, statusHistory, serverPorts, labels);
}
 
Example 2
@SuppressWarnings({ "rawtypes", "unchecked" })
public MappedThriftLogFileReader(LogFile logFile,
                                 String path,
                                 long byteOffset,
                                 int readBufferSize,
                                 int maxMessageSize) throws Exception {
  Preconditions.checkArgument(!Strings.isNullOrEmpty(path));
  Preconditions.checkArgument(byteOffset >= 0);

  this.logFile = Preconditions.checkNotNull(logFile);
  this.path = path;
  this.maxMessageSize = maxMessageSize;
  this.maxMessageSizeInternal = maxMessageSize * 10;

  this.thriftReader = new MappedThriftReader(path, new LogMessageFactory(),
      maxMessageSizeInternal);
  this.thriftReader.setByteOffset((int) byteOffset);

  // Make sure the path is still associated with the LogFile.
  // This can happen when the path is reused for another LogFile during log
  // rotation.
  if (logFile.getInode() != SingerUtils.getFileInode(FileSystems.getDefault().getPath(path))) {
    LOG.info("Log file {} does not match path: {}. The path has been reused for another file.",
        logFile.getInode(), path);

    // Close the reader and throw.
    thriftReader.close();
    throw new LogFileReaderException(
        "Path: " + path + " is not associated with log file:" + logFile.toString());
  }
  closed = false;
}
 
Example 3
@Nullable
private ItemStack readItemStack(ByteBuf byteBuf) {
    short itemID = byteBuf.readShort();

    if (itemID != -1) {
        byte itemCount = byteBuf.readByte();
        short itemMetadata = byteBuf.readShort();
        ItemType itemType = itemTypeMapping.getItemType(itemID, itemMetadata);
        Preconditions.checkNotNull(itemType, "Cannot find itemType with ID " + itemID);
        byte nbtStartByte = byteBuf.readByte(); // TODO Item NBT
        return new SimpleItemStack(itemType, itemCount, null);
    }
    return null;
}
 
Example 4
@Override
public synchronized final void put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) throws BlockStoreException {
    Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed");
    Sha256Hash hash = storedBlock.getHeader().getHash();
    fullBlockMap.put(hash, storedBlock.getHeight(), undoableBlock);
    blockMap.put(hash, new StoredBlockAndWasUndoableFlag(storedBlock, true));
}
 
Example 5
Source Project: cymbal   File: CollectionUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static <T> Map<T, T> toMap(List<T> list) {
    Preconditions.checkNotNull(list);
    Preconditions.checkArgument(list.size() % 2 == 0, "Size of list must be even.");
    Map<T, T> result = new HashMap<>();
    for (int i = 0; i < list.size(); i += 2) {
        result.put(list.get(i), list.get(i + 1));
    }
    return result;
}
 
Example 6
public int getMapPlayCount(Entrant entrant, PGMMap map) {
    Preconditions.checkNotNull(map, "Map");
    int count = 0;
    for (MatchDoc match : Preconditions.checkNotNull(entrant, "Entrant").matches()) {
        if (Config.mapMatchFamilies().contains(match.family_id())) {
            if(map.getDocument().equals(match.map())) {
                count++;
            }
        }
    }

    return count;
}
 
Example 7
Source Project: java-n-IDE-for-Android   File: XmlNode.java    License: Apache License 2.0 5 votes vote down vote up
private NamespaceAwareName(@NonNull String namespaceURI,
        @NonNull String prefix,
        @NonNull String localName) {
    mNamespaceURI = Preconditions.checkNotNull(namespaceURI);
    mPrefix = Preconditions.checkNotNull(prefix);
    mLocalName = Preconditions.checkNotNull(localName);
}
 
Example 8
@Override
public void register(URL url) throws Exception {
	Preconditions.checkNotNull(url);
	Preconditions.checkNotNull(url.getPath());
	// 获取url对应的zk路径
	String providerPath = getProviderPath(url);
	// 在zk服务器上建立相应路径
	zk.create(providerPath, "".getBytes(), null, CreateMode.EPHEMERAL);
}
 
Example 9
@Override
public PageInfo<T> selectPageAndCountByExample(Example example, int pageNum, int pageSize) {
    Preconditions.checkNotNull(example);
    return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(
            () -> mapper.selectByExample(example)
    );
}
 
Example 10
Source Project: hadoop-ozone   File: ContainerStateMap.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns Containers in the System by the Type.
 *
 * @param type - Replication type -- StandAlone, Ratis etc.
 * @return NavigableSet
 */
NavigableSet<ContainerID> getContainerIDsByType(final ReplicationType type) {
  Preconditions.checkNotNull(type);
  lock.readLock().lock();
  try {
    return typeMap.getCollection(type);
  } finally {
    lock.readLock().unlock();
  }
}
 
Example 11
public LocaleMatcher(Locale defaultLocale, Set<Locale> supportedLocales) {
    this.defaultLocale = Preconditions.checkNotNull(defaultLocale, "no default locale available");
    this.supportedLocales = Preconditions.checkNotNull(supportedLocales, "no supported locales");
}
 
Example 12
Source Project: google-ads-java   File: KeywordViewName.java    License: Apache License 2.0 4 votes vote down vote up
private KeywordViewName(Builder builder) {
  customer = Preconditions.checkNotNull(builder.getCustomer());
  keywordView = Preconditions.checkNotNull(builder.getKeywordView());
}
 
Example 13
public DecimalConversionHandler(Schema headerSchema, String header, String field) {
  super(headerSchema, header, field);
  String scaleText = null != headerSchema.parameters() ? headerSchema.parameters().get(Decimal.SCALE_FIELD) : null;
  Preconditions.checkNotNull(scaleText, "schema parameters must contain a '%s' parameter.", Decimal.SCALE_FIELD);
  scale = Integer.parseInt(scaleText);
}
 
Example 14
Source Project: gyro   File: PairNode.java    License: Apache License 2.0 4 votes vote down vote up
public PairNode(Node key, Node value) {
    super(null);

    this.key = Preconditions.checkNotNull(key);
    this.value = Preconditions.checkNotNull(value);
}
 
Example 15
@Override
public T selectByPk(PK pk) {
    Preconditions.checkNotNull(pk);
    return mapper.selectByPrimaryKey(pk);
}
 
Example 16
Source Project: dremio-oss   File: MaterializationCache.java    License: Apache License 2.0 4 votes vote down vote up
MaterializationCache(CacheHelper provider, NamespaceService namespaceService, ReflectionStatusService reflectionStatusService) {
  this.provider = Preconditions.checkNotNull(provider, "materialization provider required");
  this.namespaceService = Preconditions.checkNotNull(namespaceService, "namespace service required");
  this.reflectionStatusService = Preconditions.checkNotNull(reflectionStatusService, "reflection status service required");
}
 
Example 17
private CustomerLabelName(Builder builder) {
  customer = Preconditions.checkNotNull(builder.getCustomer());
  customerLabel = Preconditions.checkNotNull(builder.getCustomerLabel());
}
 
Example 18
public RobotBatteryPublisherNode(BaseDevice baseDevice) {
    Preconditions.checkNotNull(baseDevice);
    this.mBaseDevice = baseDevice;
}
 
Example 19
@Override
protected InputConverterUnit<String[]> getInputConverterUnit(Context context) {
    Preconditions.checkNotNull(cubeDesc);
    Preconditions.checkNotNull(dictionaryMap);
    return new InputConverterUnitForRawData(cubeDesc, flatDesc, dictionaryMap);
}
 
Example 20
Source Project: dremio-oss   File: VectorResolver.java    License: Apache License 2.0 4 votes vote down vote up
public static <T extends ValueVector> T simple(VectorAccessible incoming, Class<T> vectorClass, int... ids) {
  VectorWrapper<T> wrapper = incoming.getValueAccessorById(vectorClass, ids);
  Preconditions.checkNotNull(wrapper, "Failure while loading vector with id: %s. Vector not found.", Arrays.toString(ids));
  Preconditions.checkArgument(!wrapper.isHyper(), "Failure while loading vector with id: %s. Vector was expected to be simple but turned out to be hyper.", Arrays.toString(ids));
  return wrapper.getValueVector();
}