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


Java MoreObjects.firstNonNull方法代码示例

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


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

示例1: newOwner

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
@Override
public String newOwner(String currentOwner, Collection<String> viableCandidates) {
    Preconditions.checkArgument(viableCandidates.size() > 0);
    String leastLoadedCandidate = null;
    long leastLoadedCount = Long.MAX_VALUE;

    if (!Strings.isNullOrEmpty(currentOwner)) {
        long localVal = MoreObjects.firstNonNull(localStatistics.get(currentOwner), 0L);
        localStatistics.put(currentOwner, localVal - 1);
    }

    for (String candidateName : viableCandidates) {
        long val = MoreObjects.firstNonNull(localStatistics.get(candidateName), 0L);
        if (val < leastLoadedCount) {
            leastLoadedCount = val;
            leastLoadedCandidate = candidateName;
        }
    }

    if (leastLoadedCandidate == null) {
        leastLoadedCandidate = viableCandidates.iterator().next();
    }

    localStatistics.put(leastLoadedCandidate, leastLoadedCount + 1);
    return leastLoadedCandidate;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:27,代码来源:LeastLoadedCandidateSelectionStrategy.java

示例2: InsertFromSubQueryAnalyzedStatement

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
public InsertFromSubQueryAnalyzedStatement(AnalyzedRelation subQueryRelation,
                                           DocTableInfo tableInfo,
                                           List<Reference> targetColumns,
                                           @Nullable Map<Reference, Symbol> onDuplicateKeyAssignments) {
    this.targetTable = tableInfo;
    this.subQueryRelation = subQueryRelation;
    this.onDuplicateKeyAssignments = onDuplicateKeyAssignments;
    this.targetColumns = targetColumns;
    Map<ColumnIdent, Integer> columnPositions = toPositionMap(targetColumns);

    clusteredByIdx = MoreObjects.firstNonNull(columnPositions.get(tableInfo.clusteredBy()), -1);
    ImmutableMap<ColumnIdent, GeneratedReferenceInfo> generatedColumns =
            Maps.uniqueIndex(tableInfo.generatedColumns(), ReferenceInfo.TO_COLUMN_IDENT);

    if (tableInfo.hasAutoGeneratedPrimaryKey()) {
        this.primaryKeySymbols = Collections.emptyList();
    } else {
        this.primaryKeySymbols = symbolsFromTargetColumnPositionOrGeneratedExpression(
                columnPositions, targetColumns, tableInfo.primaryKey(), generatedColumns);
    }
    this.partitionedBySymbols = symbolsFromTargetColumnPositionOrGeneratedExpression(
            columnPositions, targetColumns, tableInfo.partitionedBy(), generatedColumns);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:InsertFromSubQueryAnalyzedStatement.java

示例3: register

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
/**
 * Registers all subscriber methods on the given listener object.
 */
void register(Object listener) {
  Multimap<Class<?>, Subscriber> listenerMethods = findAllSubscribers(listener);

  for (Map.Entry<Class<?>, Collection<Subscriber>> entry : listenerMethods.asMap().entrySet()) {
    Class<?> eventType = entry.getKey();
    Collection<Subscriber> eventMethodsInListener = entry.getValue();

    CopyOnWriteArraySet<Subscriber> eventSubscribers = subscribers.get(eventType);

    if (eventSubscribers == null) {
      CopyOnWriteArraySet<Subscriber> newSet = new CopyOnWriteArraySet<Subscriber>();
      eventSubscribers =
          MoreObjects.firstNonNull(subscribers.putIfAbsent(eventType, newSet), newSet);
    }

    eventSubscribers.addAll(eventMethodsInListener);
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:22,代码来源:SubscriberRegistry.java

示例4: run

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
private static <T> CompletableFuture<T> run(ThriftCall<T> call) {
    ThriftCompletableFuture<T> future = new ThriftCompletableFuture<>();
    try {
        call.apply(future);
    } catch (Exception e) {
        final Throwable cause;
        if (e instanceof InvocationTargetException) {
            cause = MoreObjects.firstNonNull(e.getCause(), e);
        } else {
            cause = e;
        }
        CompletableFuture<T> failedFuture = new CompletableFuture<>();
        failedFuture.completeExceptionally(cause);
        return failedFuture;
    }
    return future;
}
 
开发者ID:line,项目名称:centraldogma,代码行数:18,代码来源:DefaultCentralDogma.java

示例5: lexicalSubstituteAdd

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
/**
 * Lexical Substitute task by Add Method
 * @param word target word
 * @param contexts list of given contexts
 * @param average average the context vectors of given contexts
 * @param top number of results return
 * @return a list of {@link Pair}
 */
public List<Pair<String, Double>> lexicalSubstituteAdd (String word, List<String> contexts, boolean average, Integer top) {
	top = MoreObjects.firstNonNull(top, 10);
	INDArray targetVec = getWordVector(word);
	INDArray ctxVec = zeros();
	int found = 0;
	for (String context : contexts) {
		if (!hasContext(context)) continue;
		found++;
		ctxVec.addi(getContextVector(context));
	}
	if (average && (found != 0)) ctxVec.divi(Nd4j.scalar(found));
	targetVec.addi(ctxVec);
	double norm = Math.sqrt(targetVec.mmul(targetVec.transpose()).getDouble(0));
	norm = norm == 0.0 ? 1.0 : norm;
	targetVec.divi(Nd4j.scalar(norm));
	INDArray scores = wordSimilarity(targetVec);
	List<Pair<String, Double>> list = new ArrayList<>(wordVocab.size());
	for (int i = 0; i < wordVocab.size(); i++) { list.add(new Pair<>(wordVocab.get(i), scores.getDouble(i))); }
	return list.stream().sorted((e1, e2) -> Double.valueOf(e2.getValue()).compareTo(Double.valueOf(e1.getValue()))).limit(top).collect(Collectors.toCollection(LinkedList::new));
}
 
开发者ID:IsaacChanghau,项目名称:Word2VecfJava,代码行数:29,代码来源:Word2Vecf.java

示例6: CopyToAnalyzedStatement

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
public CopyToAnalyzedStatement(QueriedDocTable subQueryRelation,
                               Settings settings,
                               Symbol uri,
                               boolean isDirectoryUri,
                               @Nullable WriterProjection.CompressionType compressionType,
                               @Nullable WriterProjection.OutputFormat outputFormat,
                               @Nullable List<String> outputNames,
                               boolean columnsDefined,
                               @Nullable Map<ColumnIdent, Symbol> overwrites) {
    super(settings, uri);
    this.subQueryRelation = subQueryRelation;
    this.columnsDefined = columnsDefined;
    this.compressionType = compressionType;
    this.outputNames = outputNames;
    this.outputFormat = outputFormat;
    this.isDirectoryUri = isDirectoryUri;
    this.overwrites = MoreObjects.firstNonNull(overwrites, ImmutableMap.<ColumnIdent, Symbol>of());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:CopyToAnalyzedStatement.java

示例7: getFlatProjectorChain

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
private FlatProjectorChain getFlatProjectorChain(ProjectorFactory projectorFactory,
                                                 ESGetNode node,
                                                 QueryResultRowDownstream queryResultRowDownstream) {
    if (node.limit() != null || node.offset() > 0 || !node.sortSymbols().isEmpty()) {
        List<Symbol> orderBySymbols = new ArrayList<>(node.sortSymbols().size());
        for (Symbol symbol : node.sortSymbols()) {
            int i = node.outputs().indexOf(symbol);
            if (i < 0) {
                orderBySymbols.add(new InputColumn(node.outputs().size() + orderBySymbols.size()));
            } else {
                orderBySymbols.add(new InputColumn(i));
            }
        }
        TopNProjection topNProjection = new TopNProjection(
                // TODO: use TopN.NO_LIMIT as default once this can be used as subrelation
                MoreObjects.firstNonNull(node.limit(), Constants.DEFAULT_SELECT_LIMIT),
                node.offset(),
                orderBySymbols,
                node.reverseFlags(),
                node.nullsFirst()
        );
        topNProjection.outputs(InputColumn.numInputs(node.outputs().size()));
        return FlatProjectorChain.withAttachedDownstream(
                projectorFactory,
                null,
                ImmutableList.<Projection>of(topNProjection),
                queryResultRowDownstream,
                jobId()
        );
    } else {
        return FlatProjectorChain.withReceivers(ImmutableList.of(queryResultRowDownstream));
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:34,代码来源:ESGetTask.java

示例8: column

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @throws NullPointerException if {@code columnKey} is {@code null}
 */
@Override
public ImmutableMap<R, V> column(C columnKey) {
  checkNotNull(columnKey);
  return MoreObjects.firstNonNull(
      (ImmutableMap<R, V>) columnMap().get(columnKey), ImmutableMap.<R, V>of());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:12,代码来源:ImmutableTable.java

示例9: IndexReferenceInfo

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
public IndexReferenceInfo(ReferenceIdent ident,
                          IndexType indexType,
                          List<ReferenceInfo> columns,
                          @Nullable String analyzer) {
    super(ident, RowGranularity.DOC, DataTypes.STRING, ColumnPolicy.DYNAMIC, indexType);
    this.columns = MoreObjects.firstNonNull(columns, Collections.<ReferenceInfo>emptyList());
    this.analyzer = analyzer;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:9,代码来源:IndexReferenceInfo.java

示例10: AddColumnDefinition

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
public AddColumnDefinition(Expression name,
                           @Nullable Expression generatedExpression,
                           @Nullable ColumnType type,
                           @Nullable List<ColumnConstraint> constraints) {
    this.name = name;
    this.generatedExpression = generatedExpression;
    this.type = type;
    this.constraints = MoreObjects.firstNonNull(constraints, ImmutableList.<ColumnConstraint>of());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:AddColumnDefinition.java

示例11: lexicalSubstituteAdaptive

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
/**
 * Lexical Substitute task by Adaptive Method
 * @param word target word
 * @param contexts list of given contexts
 * @param parameter parameter to adjust the weight between word and contexts
 * @param top number of results return
 * @return a list of {@link Pair}
 */
public List<Pair<String, Double>> lexicalSubstituteAdaptive (String word, List<String> contexts, double parameter, Integer top) {
	top = MoreObjects.firstNonNull(top, 10);
	if (parameter < 0 && parameter > 1.0)
		parameter = 0.5; // set default value
	INDArray targetVec = getWordVector(word);
	INDArray ctxVec = zeros();
	int found = 0;
	for (String context : contexts) {
		if (hasContext(context)) {
			found++;
			ctxVec.addi(getContextVector(context));
		}
	}
	if (found != 0) ctxVec.divi(Nd4j.scalar(found));
	INDArray wscores = wordSimilarity(targetVec);
	if (wscores.minNumber().doubleValue() < 0.0) wscores.addi(wscores.minNumber().doubleValue() * (-1.0f)).divi(wscores.maxNumber());
	else wscores.divi(wscores.maxNumber());
	INDArray cscores = wordVectors.subRowVector(targetVec).mmul(ctxVec.transpose());
	if (cscores.minNumber().doubleValue() < 0.0) cscores.addi(cscores.minNumber().doubleValue() * (-1.0)).divi(cscores.maxNumber());
	else cscores.divi(cscores.maxNumber());
	INDArray scores = wscores.mul(1.0 - parameter).add(cscores.mul(parameter));
	scores.divi(scores.maxNumber());
	List<Pair<String, Double>> list = new ArrayList<>(wordVocab.size());
	for (int i = 0; i < getWordVocab().size(); i++) { list.add(new Pair<>(wordVocab.get(i), scores.getDouble(i))); }
	return list.stream().sorted((e1, e2) -> Double.valueOf(e2.getValue()).compareTo(Double.valueOf(e1.getValue()))).limit(top).collect(Collectors.toCollection(LinkedList::new));
}
 
开发者ID:IsaacChanghau,项目名称:Word2VecfJava,代码行数:35,代码来源:Word2Vecf.java

示例12: ceiling

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
@Nullable
private AvlNode<E> ceiling(Comparator<? super E> comparator, E e) {
  int cmp = comparator.compare(e, elem);
  if (cmp < 0) {
    return (left == null) ? this : MoreObjects.firstNonNull(left.ceiling(comparator, e), this);
  } else if (cmp == 0) {
    return this;
  } else {
    return (right == null) ? null : right.ceiling(comparator, e);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:TreeMultiset.java

示例13: index

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
public String index() {
    return MoreObjects.firstNonNull(index, "not_analyzed");
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:4,代码来源:AnalyzedColumnDefinition.java

示例14: setMetadataPolicy

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
public void setMetadataPolicy(UIMetadataPolicy metadataPolicy){
  this.metadataPolicy = MoreObjects.firstNonNull(metadataPolicy, UIMetadataPolicy.DEFAULT_UIMETADATA_POLICY);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:4,代码来源:SourceUI.java

示例15: printEvent

import com.google.common.base.MoreObjects; //导入方法依赖的package包/类
private void printEvent(Event<?, ?> event) {
    if (event instanceof DeviceEvent) {
        DeviceEvent deviceEvent = (DeviceEvent) event;
        if (event.type().toString().startsWith("PORT")) {
            // Port event
            print("%s %s\t%s/%s [%s]",
                  new LocalDateTime(event.time()),
                  event.type(),
                  deviceEvent.subject().id(), deviceEvent.port().number(),
                  deviceEvent.port()
              );
        } else {
            // Device event
            print("%s %s\t%s [%s]",
                  new LocalDateTime(event.time()),
                  event.type(),
                  deviceEvent.subject().id(),
                  deviceEvent.subject()
              );
        }

    } else if (event instanceof MastershipEvent) {
        print("%s %s\t%s [%s]",
              new LocalDateTime(event.time()),
              event.type(),
              event.subject(),
              ((MastershipEvent) event).roleInfo());

    } else if (event instanceof LinkEvent) {
        LinkEvent linkEvent = (LinkEvent) event;
        Link link = linkEvent.subject();
        print("%s %s\t%s/%s-%s/%s [%s]",
              new LocalDateTime(event.time()),
              event.type(),
              link.src().deviceId(), link.src().port(), link.dst().deviceId(), link.dst().port(),
              link);

    } else if (event instanceof HostEvent) {
        HostEvent hostEvent = (HostEvent) event;
        print("%s %s\t%s [%s->%s]",
              new LocalDateTime(event.time()),
              event.type(),
              hostEvent.subject().id(),
              hostEvent.prevSubject(), hostEvent.subject());

    } else if (event instanceof TopologyEvent) {
        TopologyEvent topoEvent = (TopologyEvent) event;
        List<Event> reasons = MoreObjects.firstNonNull(topoEvent.reasons(),
                                                       ImmutableList.<Event>of());
        Topology topo = topoEvent.subject();
        String summary = String.format("(d=%d,l=%d,c=%d)",
                                       topo.deviceCount(),
                                       topo.linkCount(),
                                       topo.clusterCount());
        print("%s %s%s [%s]",
              new LocalDateTime(event.time()),
              event.type(),
              summary,
              reasons.stream().map(e -> e.type()).collect(toList()));

    } else if (event instanceof ClusterEvent) {
        print("%s %s\t%s [%s]",
              new LocalDateTime(event.time()),
              event.type(),
              ((ClusterEvent) event).subject().id(),
              event.subject());

    } else {
        // Unknown Event?
        print("%s %s\t%s [%s]",
              new LocalDateTime(event.time()),
              event.type(),
              event.subject(),
              event);
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:77,代码来源:EventsCommand.java


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