当前位置: 首页>>代码示例>>Java>>正文


Java Preconditions.checkArgument方法代码示例

本文整理汇总了Java中com.google.common.base.Preconditions.checkArgument方法的典型用法代码示例。如果您正苦于以下问题:Java Preconditions.checkArgument方法的具体用法?Java Preconditions.checkArgument怎么用?Java Preconditions.checkArgument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.base.Preconditions的用法示例。


在下文中一共展示了Preconditions.checkArgument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getClass

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> Class<? extends T> getClass(String path, Class<T> iface, Class<? extends T> defaultImpl) {
  if (this.hasPath(path)) {
    String className = this.getString(path);
    ;
    try {
      Class<?> clazz = Class.forName(className);
      Preconditions.checkArgument(iface.isAssignableFrom(clazz));
      return (Class<? extends T>) clazz;
    } catch (ClassNotFoundException e) {
      throw UserException.unsupportedError(e)
      .message("Failure while attempting to find implementation class %s for interface  %s. The sabot config key is %s ",
          defaultImpl.getName(), iface.getName(), path).build(logger);
    }
  }

  return defaultImpl;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:19,代码来源:SabotConfig.java

示例2: getCurrentConversationByChannelId

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
public Conversation getCurrentConversationByChannelId(Client client, String channelId, Supplier<Conversation> supplier) {
    Preconditions.checkNotNull(client);
    Preconditions.checkArgument(StringUtils.isNoneBlank(channelId));
    final ObjectId conversationId = storeService.mapChannelToCurrentConversationId(channelId);
    if (conversationId != null) {
        Conversation conversation = storeService.get(conversationId);
        if(Objects.equal(conversation.getOwner(), client.getId())){
            return getConversation(client, conversationId);
        } else {
            //this should never happen unless we have two clients with the same channelId
            throw new IllegalStateException("Conversation for channel '" + channelId + "' has a different owner "
                    + "as the current client (owner: " + conversation.getOwner() + ", client: " + client + ")!");
        }
    } else {
        final Conversation c = supplier.get();
        if(c != null){
            c.setId(null);
            c.setOwner(client.getId());
            c.setChannelId(channelId);
            return storeService.store(c);
        } else {
            return null;
        }
    }
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:26,代码来源:ConversationService.java

示例3: mergeChildrenWithMultipleDeclarations

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
 * Merges two children when this children's type allow multiple elements declaration with the
 * same key value. In that case, we only merge the lower priority child if there is not already
 * an element with the same key value that is equal to the lower priority child. Two children
 * are equals if they have the same attributes and children declared irrespective of the
 * declaration order.
 *
 * @param lowerPriorityChild the lower priority element's child.
 * @param mergingReport the merging report to log errors and actions.
 */
private void mergeChildrenWithMultipleDeclarations(
        XmlElement lowerPriorityChild,
        MergingReport.Builder mergingReport) {

    Preconditions.checkArgument(lowerPriorityChild.getType().areMultipleDeclarationAllowed());
    if (lowerPriorityChild.getType().areMultipleDeclarationAllowed()) {
        for (XmlElement sameTypeChild : getAllNodesByType(lowerPriorityChild.getType())) {
            if (sameTypeChild.getId().equals(lowerPriorityChild.getId()) &&
                    sameTypeChild.isEquals(lowerPriorityChild)) {
                return;
            }
        }
    }
    // if we end up here, we never found a child of this element with the same key and strictly
    // equals to the lowerPriorityChild so we should merge it in.
    addElement(lowerPriorityChild, mergingReport);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:28,代码来源:XmlElement.java

示例4: TopConf

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
public TopConf(Configuration conf) {
  isEnabled = conf.getBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY,
      DFSConfigKeys.NNTOP_ENABLED_DEFAULT);
  String[] periodsStr = conf.getTrimmedStrings(
      DFSConfigKeys.NNTOP_WINDOWS_MINUTES_KEY,
      DFSConfigKeys.NNTOP_WINDOWS_MINUTES_DEFAULT);
  nntopReportingPeriodsMs = new int[periodsStr.length];
  for (int i = 0; i < periodsStr.length; i++) {
    nntopReportingPeriodsMs[i] = Ints.checkedCast(
        TimeUnit.MINUTES.toMillis(Integer.parseInt(periodsStr[i])));
  }
  for (int aPeriodMs: nntopReportingPeriodsMs) {
    Preconditions.checkArgument(aPeriodMs >= TimeUnit.MINUTES.toMillis(1),
        "minimum reporting period is 1 min!");
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TopConf.java

示例5: validatePMMLVsSchema

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
 * Validates that the encoded PMML model received matches expected schema.
 *
 * @param pmml {@link PMML} encoding of KMeans Clustering
 * @param schema expected schema attributes of KMeans Clustering
 */
public static void validatePMMLVsSchema(PMML pmml, InputSchema schema) {
  List<Model> models = pmml.getModels();
  Preconditions.checkArgument(models.size() == 1,
      "Should have exactly one model, but had %s", models.size());

  Model model = models.get(0);
  Preconditions.checkArgument(model instanceof ClusteringModel);
  Preconditions.checkArgument(model.getMiningFunction() == MiningFunction.CLUSTERING);

  DataDictionary dictionary = pmml.getDataDictionary();
  Preconditions.checkArgument(
      schema.getFeatureNames().equals(AppPMMLUtils.getFeatureNames(dictionary)),
      "Feature names in schema don't match names in PMML");

  MiningSchema miningSchema = model.getMiningSchema();
  Preconditions.checkArgument(schema.getFeatureNames().equals(
      AppPMMLUtils.getFeatureNames(miningSchema)));

}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:26,代码来源:KMeansPMMLUtils.java

示例6: mapAttribute

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public Optional<MappedDependency> mapAttribute(final Object value) {
    if (value == null) {
        return Optional.absent();
    }

    String expectedClass = getOpenType().getClassName();
    String realClass = value.getClass().getName();
    Preconditions.checkArgument(realClass.equals(expectedClass),
            "Type mismatch, expected " + expectedClass + " but was " + realClass);
    Util.checkType(value, ObjectName.class);

    ObjectName on = (ObjectName) value;

    String refName = ObjectNameUtil.getReferenceName(on);

    // we want to use the exact service name that was configured in xml so services
    // that are referencing it can be resolved
    return Optional.of(new MappedDependency(namespace,
            QName.create(ObjectNameUtil.getServiceQName(on)).getLocalName(), refName));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:ObjectNameAttributeMappingStrategy.java

示例7: getReturnCodes

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
 * Algorithm 7.28: GetReturnCodes
 *
 * @param bold_s the list of selections
 * @param bold_P the point matrix containing the responses for each of the authorities
 * @return the verification codes corresponding to the point matrix
 */
public List<String> getReturnCodes(List<Integer> bold_s, List<List<Point>> bold_P) {
    int length = bold_P.get(0).size();
    Preconditions.checkArgument(bold_P.stream().allMatch(l -> l.size() == length));
    List<Character> A_r = publicParameters.getUpper_a_r();

    List<String> bold_rc_s = new ArrayList<>();
    for (int i = 0; i < length; i++) {
        byte[] rc_i = new byte[publicParameters.getUpper_l_r()];
        for (int j = 0; j < publicParameters.getS(); j++) {
            rc_i = ByteArrayUtils.xor(rc_i, ByteArrayUtils.truncate(
                    hash.recHash_L(bold_P.get(j).get(i)),
                    publicParameters.getUpper_l_r()));
        }
        byte[] upper_r = ByteArrayUtils.markByteArray(rc_i, bold_s.get(i) - 1, publicParameters.getN_max());
        bold_rc_s.add(conversion.toString(upper_r, A_r));
    }
    return bold_rc_s;
}
 
开发者ID:republique-et-canton-de-geneve,项目名称:chvote-protocol-poc,代码行数:26,代码来源:VoteCastingClientAlgorithms.java

示例8: mailboxPushTimeout

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public T mailboxPushTimeout(String timeout) {
    Duration pushTimeout = Duration.create(timeout);
    Preconditions.checkArgument(pushTimeout.isFinite(), "invalid value for mailbox push timeout");

    Map<String, Object> boundedMailbox = (Map<String, Object>) configHolder.get(TAG_MAILBOX);
    boundedMailbox.put(TAG_MAILBOX_PUSH_TIMEOUT, timeout);
    return (T)this;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:CommonConfig.java

示例9: checkFields

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
private void checkFields(List<Field> fields) {
    int c = 1;
    for (int i = 0; i < fields.size(); i++) {
        Preconditions.checkArgument(fields.get(i).getOrd() == c, "Gap in fields or not in order!");
        c++;
    }
}
 
开发者ID:atlascon,项目名称:travny,代码行数:8,代码来源:RecordSchema.java

示例10: StatAggregate

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
 * @param eventIds A list of eventIds that contributed to the {@link StatAggregate}
 * @param maxEventIds The maximum number of eventIds to hold in the {@link StatAggregate}, if eventIds is above
 *                    this limit, then only the first N will be included in the aggregate
 */
public StatAggregate(final List<MultiPartIdentifier> eventIds, final int maxEventIds) {
    Preconditions.checkNotNull(eventIds);
    Preconditions.checkArgument(maxEventIds >= 0);
    this.maxEventIds = maxEventIds;
    if (eventIds.size() > maxEventIds) {
        this.eventIds = new ArrayList<>(eventIds.subList(0, maxEventIds));
    } else {
        this.eventIds = new ArrayList<>(eventIds);
    }
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:16,代码来源:StatAggregate.java

示例11: addTail

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
 * Add a FlumeEventPointer to the tail of the queue.
 *
 * @param FlumeEventPointer to be added
 * @return true if space was available and pointer
 * was added to the queue
 */
synchronized boolean addTail(FlumeEventPointer e) {
  if (getSize() == backingStore.getCapacity()) {
    return false;
  }

  long value = e.toLong();
  Preconditions.checkArgument(value != EMPTY);
  backingStore.incrementFileID(e.getFileID());

  add(backingStore.getSize(), value);
  return true;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:FlumeEventQueue.java

示例12: spawnFirework

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
public static @Nonnull Firework spawnFirework(@Nonnull Location location, @Nonnull FireworkEffect effect, int power) {
    Preconditions.checkNotNull(location, "location");
    Preconditions.checkNotNull(effect, "firework effect");
    Preconditions.checkArgument(power >= 0, "power must be positive");

    FireworkMeta meta = (FireworkMeta) Bukkit.getItemFactory().getItemMeta(Material.FIREWORK);
    meta.setPower(power > 0 ? (power - 1) : power);
    meta.addEffect(effect);

    Firework firework = (Firework) location.getWorld().spawnEntity(location.add(0.5, 0.0, 0.5), EntityType.FIREWORK);
    firework.setFireworkMeta(meta);
    if (power == 0) Bukkit.getScheduler().runTaskLater(TGM.get(), firework::detonate, 1L);

    return firework;
}
 
开发者ID:WarzoneMC,项目名称:Warzone,代码行数:16,代码来源:FireworkUtil.java

示例13: removeEvent

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
 * Removes an Event from the manager.
 * @param value - Event Identity (as long)
 * @param ident - Yang Identity
 * @param displayName - Display Name
 */
static public void removeEvent(Long value, Class<? extends EventType> ident, String displayName) {
    Preconditions.checkArgument((value != null), "Long value cannot be empty");
    if (!eventIds.remove(value)) {
        return;
    }
    if (displayName != null) {
        eventMappingsByName.remove(displayName);
    }
    if (ident != null) {
        eventMappingsByIdentity.remove(ident);
    }
}
 
开发者ID:opendaylight,项目名称:fpc,代码行数:19,代码来源:Events.java

示例14: render

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public Map2D<TerminalPixel> render(final int width) {
    Preconditions.checkArgument(width >= 0);
    final int p = (int)Math.ceil(width * progress);
    return Map2D.of(width, 1, TerminalPixel.class, background)
        .modify((x, y, v) -> x <= p ? fill : v);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:8,代码来源:ProgressBar.java

示例15: createCall

import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
  Preconditions.checkArgument(operands.length == 3, "SqlAccelToggle.createCall() has to get 3 operands!");
  return new SqlAccelToggle(pos, (SqlIdentifier) operands[0], (SqlLiteral) operands[1], (SqlLiteral) operands[2]);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:6,代码来源:SqlAccelToggle.java


注:本文中的com.google.common.base.Preconditions.checkArgument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。