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

The following examples show how to use com.google.common.base.Preconditions#checkNotNull() . 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: MasterInstance.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
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
Source File: ContainerStateMap.java    From hadoop-ozone with 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 3
Source File: BaseServiceImpl.java    From dynamic-data-source-demo with Apache License 2.0 5 votes vote down vote up
@Override
public PageInfo<T> selectPageAndCountByExample(Example example, int pageNum, int pageSize) {
    Preconditions.checkNotNull(example);
    return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(
            () -> mapper.selectByExample(example)
    );
}
 
Example 4
Source File: ZookeeperRegistry.java    From Distributed-KV with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: XmlNode.java    From java-n-IDE-for-Android with 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 6
Source File: EntrantUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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 File: CollectionUtil.java    From cymbal with 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 8
Source File: MemoryFullPrunedBlockStore.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@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 9
Source File: CreativeInventoryActionCodec.java    From Cleanstone with MIT License 5 votes vote down vote up
@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 10
Source File: MappedThriftLogFileReader.java    From singer with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: ConversionHandler.java    From kafka-connect-transform-common with Apache License 2.0 4 votes vote down vote up
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 12
Source File: PairNode.java    From gyro with 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 13
Source File: BaseServiceImpl.java    From maven-archetype-springboot with Apache License 2.0 4 votes vote down vote up
@Override
public T selectByPk(PK pk) {
    Preconditions.checkNotNull(pk);
    return mapper.selectByPrimaryKey(pk);
}
 
Example 14
Source File: MaterializationCache.java    From dremio-oss with 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 15
Source File: CustomerLabelName.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private CustomerLabelName(Builder builder) {
  customer = Preconditions.checkNotNull(builder.getCustomer());
  customerLabel = Preconditions.checkNotNull(builder.getCustomerLabel());
}
 
Example 16
Source File: RobotBatteryPublisherNode.java    From tangobot with Apache License 2.0 4 votes vote down vote up
public RobotBatteryPublisherNode(BaseDevice baseDevice) {
    Preconditions.checkNotNull(baseDevice);
    this.mBaseDevice = baseDevice;
}
 
Example 17
Source File: InMemCuboidMapper.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
protected InputConverterUnit<String[]> getInputConverterUnit(Context context) {
    Preconditions.checkNotNull(cubeDesc);
    Preconditions.checkNotNull(dictionaryMap);
    return new InputConverterUnitForRawData(cubeDesc, flatDesc, dictionaryMap);
}
 
Example 18
Source File: KeywordViewName.java    From google-ads-java with 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 19
Source File: VectorResolver.java    From dremio-oss with 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();
}
 
Example 20
Source File: LocaleMatcher.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public LocaleMatcher(Locale defaultLocale, Set<Locale> supportedLocales) {
    this.defaultLocale = Preconditions.checkNotNull(defaultLocale, "no default locale available");
    this.supportedLocales = Preconditions.checkNotNull(supportedLocales, "no supported locales");
}