Java Code Examples for com.google.common.base.MoreObjects#firstNonNull()

The following examples show how to use com.google.common.base.MoreObjects#firstNonNull() . 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: GoogleFormatterMojo.java    From googleformatter-maven-plugin with Apache License 2.0 6 votes vote down vote up
private Set<File> filterUnchangedFiles(Set<File> originalFiles) throws MojoExecutionException {
  MavenProject topLevelProject = session.getTopLevelProject();
  try {
    if (topLevelProject.getScm().getConnection() == null && topLevelProject.getScm().getDeveloperConnection() == null) {
      throw new MojoExecutionException(
          "You must supply at least one of scm.connection or scm.developerConnection in your POM file if you " +
              "specify the filterModified or filter.modified option.");
    }
    String connectionUrl = MoreObjects.firstNonNull(topLevelProject.getScm().getConnection(), topLevelProject.getScm().getDeveloperConnection());
    ScmRepository repository = scmManager.makeScmRepository(connectionUrl);
    ScmFileSet scmFileSet = new ScmFileSet(topLevelProject.getBasedir());
    String basePath = topLevelProject.getBasedir().getAbsoluteFile().getPath();
    List<String> changedFiles =
        scmManager.status(repository, scmFileSet).getChangedFiles().stream()
            .map(f -> new File(basePath, f.getPath()).toString())
            .collect(Collectors.toList());

    return originalFiles.stream().filter(f -> changedFiles.contains(f.getPath())).collect(Collectors.toSet());

  } catch (ScmException e) {
    throw new MojoExecutionException(e.getMessage(), e);
  }
}
 
Example 2
Source File: KvMap.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private KvMap(Builder builder) {
    Assert.notNull(builder.mapper, "mapper is null");
    Assert.notNull(builder.path, "path is null");
    this.adapter = builder.adapter;
    this.localListener = builder.localListener;
    this.listener = builder.listener;
    this.passDirty = builder.passDirty;
    Assert.isTrue(!this.passDirty || this.adapter != KvMapAdapter.DIRECT, "Direct adapter does not support passDirty flag.");
    Class<Object> mapperType = MoreObjects.firstNonNull(builder.valueType, (Class<Object>)builder.type);
    this.mapper = builder.mapper.buildClassMapper(mapperType)
      .prefix(builder.path)
      .factory(builder.factory)
      .build();
    builder.mapper.getStorage().subscriptions().subscribeOnKey(this::onKvEvent, builder.path);
}
 
Example 3
Source File: MatchPredicateColumnIdent.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public MatchPredicateColumnIdent(Expression ident, @Nullable Expression boost) {
    this.ident = ident;
    if (boost != null) {
        Preconditions.checkArgument(
                boost instanceof LongLiteral || boost instanceof DoubleLiteral || boost instanceof ParameterExpression,
                "'boost' value must be a numeric literal or a parameter expression");
    }
    this.boost = MoreObjects.firstNonNull(boost, new NullLiteral());
}
 
Example 4
Source File: ESGetTask.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
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));
    }
}
 
Example 5
Source File: SubscriberRegistry.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 6
Source File: CycleDetectingLockFactory.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static Map<? extends Enum, LockGraphNode> getOrCreateNodes(Class<? extends Enum> clazz) {
  Map<? extends Enum, LockGraphNode> existing = lockGraphNodesPerType.get(clazz);
  if (existing != null) {
    return existing;
  }
  Map<? extends Enum, LockGraphNode> created = createNodes(clazz);
  existing = lockGraphNodesPerType.putIfAbsent(clazz, created);
  return MoreObjects.firstNonNull(existing, created);
}
 
Example 7
Source File: Striped.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public L getAt(int index) {
  if (size != Integer.MAX_VALUE) {
    Preconditions.checkElementIndex(index, size());
  } // else no check necessary, all index values are valid
  L existing = locks.get(index);
  if (existing != null) {
    return existing;
  }
  L created = supplier.get();
  existing = locks.putIfAbsent(index, created);
  return MoreObjects.firstNonNull(existing, created);
}
 
Example 8
Source File: ImmutableTable.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @throws NullPointerException if {@code rowKey} is {@code null}
 */

@Override
public ImmutableMap<C, V> row(R rowKey) {
  checkNotNull(rowKey);
  return MoreObjects.firstNonNull((ImmutableMap<C, V>) rowMap().get(rowKey), ImmutableMap.<C, V>of());
}
 
Example 9
Source File: ImmutableTable.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * {@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());
}
 
Example 10
Source File: ContainerCreator.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
private static String resolveImageName(ContainerSource nc) {
    String name = ContainerUtils.getFixedImageName(nc);
    if(name == null) {
        //getFixedImageName skip getImage value when it is Id
        name = MoreObjects.firstNonNull(nc.getImageId(), nc.getImage());
    }
    return name;
}
 
Example 11
Source File: ImmutableTable.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * {@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());
}
 
Example 12
Source File: CacheBuilder.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
Strength getValueStrength() {
return MoreObjects.firstNonNull(valueStrength, Strength.STRONG);
}
 
Example 13
Source File: InfoCollector.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Create new instance of info collector.
 * @param rootPath path to mounter root, if not specified use '/'
 */
public InfoCollector(String rootPath) {
    this.rootPath = MoreObjects.firstNonNull(rootPath, "/");
    this.collectors = ImmutableList.of(new ProcStatCollector(this), new ProcMeminfoCollector(this), new NetCollector(this));
}
 
Example 14
Source File: CacheBuilder.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
Strength getKeyStrength() {
  return MoreObjects.firstNonNull(keyStrength, Strength.STRONG);
}
 
Example 15
Source File: CacheBuilder.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
Equivalence<Object> getValueEquivalence() {
  return MoreObjects.firstNonNull(valueEquivalence, getValueStrength().defaultEquivalence());
}
 
Example 16
Source File: MapMaker.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
Equivalence<Object> getKeyEquivalence() {
  return MoreObjects.firstNonNull(keyEquivalence, getKeyStrength().defaultEquivalence());
}
 
Example 17
Source File: CacheBuilder.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("unchecked") <K1 extends K, V1 extends V> RemovalListener<K1, V1> getRemovalListener() {
  return (RemovalListener<K1, V1>) MoreObjects.firstNonNull(removalListener, NullListener.INSTANCE);
}
 
Example 18
Source File: MapMaker.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
Strength getKeyStrength() {
  return MoreObjects.firstNonNull(keyStrength, Strength.STRONG);
}
 
Example 19
Source File: FilteredEntryMultimap.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Collection<V> removeAll(@Nullable Object key) {
  return MoreObjects.firstNonNull(asMap().remove(key), unmodifiableEmptyCollection());
}
 
Example 20
Source File: SubscriberRegistry.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
Set<Subscriber> getSubscribersForTesting(Class<?> eventType) {
  return MoreObjects.firstNonNull(subscribers.get(eventType), ImmutableSet.<Subscriber>of());
}