Example usage for com.google.common.collect ImmutableList isEmpty

List of usage examples for com.google.common.collect ImmutableList isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:google.registry.whois.NameserverLookupByIpCommand.java

@Override
public WhoisResponse executeQuery(DateTime now) throws WhoisException {
    ImmutableList<HostResource> hosts = FluentIterable
            .from(queryNotDeleted(HostResource.class, now, "inetAddresses", ipAddress))
            .filter(new Predicate<HostResource>() {
                @Override/*from  w w  w .j  a  va 2s  .co  m*/
                public boolean apply(final HostResource host) {
                    return Registries.findTldForName(InternetDomainName.from(host.getFullyQualifiedHostName()))
                            .isPresent();
                }
            }).toList();
    if (hosts.isEmpty()) {
        throw new WhoisException(now, SC_NOT_FOUND, "No nameservers found.");
    }
    return new NameserverWhoisResponse(hosts, now);
}

From source file:com.netflix.metacat.connector.hive.HiveConnectorTableService.java

void updateTable(final ConnectorRequestContext requestContext, final Table table, final TableInfo tableInfo)
        throws MetaException {
    if (table.getParameters() == null || table.getParameters().isEmpty()) {
        table.setParameters(Maps.newHashMap());
    }/*from w  ww.java2 s .c o  m*/
    //if this a type of table, we all mark it external table
    //otherwise leaves it as such as VIRTUAL_VIEW
    if (!isVirtualView(table)) {
        table.getParameters().putIfAbsent(PARAMETER_EXTERNAL, "TRUE");
    } else {
        validAndUpdateVirtualView(table);
    }

    if (tableInfo.getMetadata() != null) {
        table.getParameters().putAll(tableInfo.getMetadata());
    }

    //storage
    final StorageDescriptor sd = table.getSd() != null ? table.getSd() : new StorageDescriptor();
    String inputFormat = null;
    String outputFormat = null;
    Map<String, String> sdParameters = Maps.newHashMap();
    final String location = tableInfo.getSerde() == null ? null : tableInfo.getSerde().getUri();
    if (location != null) {
        sd.setLocation(location);
    } else if (sd.getLocation() == null) {
        final String locationStr = hiveConnectorDatabaseService.get(requestContext, QualifiedName
                .ofDatabase(tableInfo.getName().getCatalogName(), tableInfo.getName().getDatabaseName()))
                .getUri();
        final Path databasePath = new Path(locationStr);
        final Path targetPath = new Path(databasePath, tableInfo.getName().getTableName());
        sd.setLocation(targetPath.toString());
    }
    if (sd.getSerdeInfo() == null) {
        sd.setSerdeInfo(new SerDeInfo());
    }
    final SerDeInfo serdeInfo = sd.getSerdeInfo();
    serdeInfo.setName(tableInfo.getName().getTableName());
    final StorageInfo storageInfo = tableInfo.getSerde();
    if (storageInfo != null) {
        if (!Strings.isNullOrEmpty(storageInfo.getSerializationLib())) {
            serdeInfo.setSerializationLib(storageInfo.getSerializationLib());
        }
        if (storageInfo.getSerdeInfoParameters() != null && !storageInfo.getSerdeInfoParameters().isEmpty()) {
            serdeInfo.setParameters(storageInfo.getSerdeInfoParameters());
        }
        inputFormat = storageInfo.getInputFormat();
        outputFormat = storageInfo.getOutputFormat();
        if (storageInfo.getParameters() != null && !storageInfo.getParameters().isEmpty()) {
            sdParameters = storageInfo.getParameters();
        }
    } else if (table.getSd() != null) {
        final HiveStorageFormat hiveStorageFormat = this.extractHiveStorageFormat(table);
        serdeInfo.setSerializationLib(hiveStorageFormat.getSerde());
        serdeInfo.setParameters(ImmutableMap.of());
        inputFormat = hiveStorageFormat.getInputFormat();
        outputFormat = hiveStorageFormat.getOutputFormat();
    }

    final ImmutableList.Builder<FieldSchema> columnsBuilder = ImmutableList.builder();
    final ImmutableList.Builder<FieldSchema> partitionKeysBuilder = ImmutableList.builder();
    if (tableInfo.getFields() != null) {
        for (FieldInfo column : tableInfo.getFields()) {
            final FieldSchema field = hiveMetacatConverters.metacatToHiveField(column);
            if (column.isPartitionKey()) {
                partitionKeysBuilder.add(field);
            } else {
                columnsBuilder.add(field);
            }
        }
    }
    final ImmutableList<FieldSchema> columns = columnsBuilder.build();
    if (!columns.isEmpty()) {
        sd.setCols(columns);
    }
    if (!Strings.isNullOrEmpty(inputFormat)) {
        sd.setInputFormat(inputFormat);
    }
    if (!Strings.isNullOrEmpty(outputFormat)) {
        sd.setOutputFormat(outputFormat);
    }
    if (sd.getParameters() == null) {
        sd.setParameters(sdParameters);
    }

    //partition keys
    final ImmutableList<FieldSchema> partitionKeys = partitionKeysBuilder.build();
    if (!partitionKeys.isEmpty()) {
        table.setPartitionKeys(partitionKeys);
    }
    table.setSd(sd);
}

From source file:org.elasticsearch.client.transport.TransportClientNodesService.java

public <T> T execute(NodeCallback<T> callback) throws ElasticsearchException {
    ImmutableList<DiscoveryNode> nodes = this.nodes;
    if (nodes.isEmpty()) {
        throw new NoNodeAvailableException();
    }/*from   ww w.  j a v a2s  .  co  m*/
    int index = randomNodeGenerator.incrementAndGet();
    if (index < 0) {
        index = 0;
        randomNodeGenerator.set(0);
    }
    for (int i = 0; i < nodes.size(); i++) {
        DiscoveryNode node = nodes.get((index + i) % nodes.size());
        try {
            return callback.doWithNode(node);
        } catch (ElasticsearchException e) {
            if (!(e.unwrapCause() instanceof ConnectTransportException)) {
                throw e;
            }
        }
    }
    throw new NoNodeAvailableException();
}

From source file:org.elasticsearch.client.transport.TransportClientNodesService.java

public <Response> void execute(NodeListenerCallback<Response> callback, ActionListener<Response> listener)
        throws ElasticsearchException {
    ImmutableList<DiscoveryNode> nodes = this.nodes;
    if (nodes.isEmpty()) {
        throw new NoNodeAvailableException();
    }/*w w w.  j a  va  2  s .  c  om*/
    int index = randomNodeGenerator.incrementAndGet();
    if (index < 0) {
        index = 0;
        randomNodeGenerator.set(0);
    }
    RetryListener<Response> retryListener = new RetryListener<>(callback, listener, nodes, index);
    try {
        callback.doWithNode(nodes.get((index) % nodes.size()), retryListener);
    } catch (ElasticsearchException e) {
        if (e.unwrapCause() instanceof ConnectTransportException) {
            retryListener.onFailure(e);
        } else {
            throw e;
        }
    }
}

From source file:org.apache.calcite.rel.rules.FilterJoinRule.java

protected void perform(RelOptRuleCall call, Filter filter, Join join) {
    final List<RexNode> joinFilters = RelOptUtil.conjunctions(join.getCondition());
    final List<RexNode> origJoinFilters = ImmutableList.copyOf(joinFilters);

    // If there is only the joinRel,
    // make sure it does not match a cartesian product joinRel
    // (with "true" condition), otherwise this rule will be applied
    // again on the new cartesian product joinRel.
    if (filter == null && joinFilters.isEmpty()) {
        return;/*from w w w. j  a v  a2 s  .co m*/
    }

    final List<RexNode> aboveFilters = filter != null ? RelOptUtil.conjunctions(filter.getCondition())
            : Lists.<RexNode>newArrayList();
    final ImmutableList<RexNode> origAboveFilters = ImmutableList.copyOf(aboveFilters);

    // Simplify Outer Joins
    JoinRelType joinType = join.getJoinType();
    if (smart && !origAboveFilters.isEmpty() && join.getJoinType() != JoinRelType.INNER) {
        joinType = RelOptUtil.simplifyJoin(join, origAboveFilters, joinType);
    }

    final List<RexNode> leftFilters = new ArrayList<>();
    final List<RexNode> rightFilters = new ArrayList<>();

    // TODO - add logic to derive additional filters.  E.g., from
    // (t1.a = 1 AND t2.a = 2) OR (t1.b = 3 AND t2.b = 4), you can
    // derive table filters:
    // (t1.a = 1 OR t1.b = 3)
    // (t2.a = 2 OR t2.b = 4)

    // Try to push down above filters. These are typically where clause
    // filters. They can be pushed down if they are not on the NULL
    // generating side.
    boolean filterPushed = false;
    if (RelOptUtil.classifyFilters(join, aboveFilters, joinType, !(join instanceof EquiJoin),
            !joinType.generatesNullsOnLeft(), !joinType.generatesNullsOnRight(), joinFilters, leftFilters,
            rightFilters)) {
        filterPushed = true;
    }

    // Move join filters up if needed
    validateJoinFilters(aboveFilters, joinFilters, join, joinType);

    // If no filter got pushed after validate, reset filterPushed flag
    if (leftFilters.isEmpty() && rightFilters.isEmpty() && joinFilters.size() == origJoinFilters.size()) {
        if (Sets.newHashSet(joinFilters).equals(Sets.newHashSet(origJoinFilters))) {
            filterPushed = false;
        }
    }

    // Try to push down filters in ON clause. A ON clause filter can only be
    // pushed down if it does not affect the non-matching set, i.e. it is
    // not on the side which is preserved.
    if (RelOptUtil.classifyFilters(join, joinFilters, joinType, false, !joinType.generatesNullsOnRight(),
            !joinType.generatesNullsOnLeft(), joinFilters, leftFilters, rightFilters)) {
        filterPushed = true;
    }

    // if nothing actually got pushed and there is nothing leftover,
    // then this rule is a no-op
    if ((!filterPushed && joinType == join.getJoinType())
            || (joinFilters.isEmpty() && leftFilters.isEmpty() && rightFilters.isEmpty())) {
        return;
    }

    // create Filters on top of the children if any filters were
    // pushed to them
    final RexBuilder rexBuilder = join.getCluster().getRexBuilder();
    final RelBuilder relBuilder = call.builder();
    final RelNode leftRel = relBuilder.push(join.getLeft()).filter(leftFilters).build();
    final RelNode rightRel = relBuilder.push(join.getRight()).filter(rightFilters).build();

    // create the new join node referencing the new children and
    // containing its new join filters (if there are any)
    final ImmutableList<RelDataType> fieldTypes = ImmutableList.<RelDataType>builder()
            .addAll(RelOptUtil.getFieldTypeList(leftRel.getRowType()))
            .addAll(RelOptUtil.getFieldTypeList(rightRel.getRowType())).build();
    final RexNode joinFilter = RexUtil.composeConjunction(rexBuilder,
            RexUtil.fixUp(rexBuilder, joinFilters, fieldTypes), false);

    // If nothing actually got pushed and there is nothing leftover,
    // then this rule is a no-op
    if (joinFilter.isAlwaysTrue() && leftFilters.isEmpty() && rightFilters.isEmpty()
            && joinType == join.getJoinType()) {
        return;
    }

    RelNode newJoinRel = join.copy(join.getTraitSet(), joinFilter, leftRel, rightRel, joinType,
            join.isSemiJoinDone());
    call.getPlanner().onCopy(join, newJoinRel);
    if (!leftFilters.isEmpty()) {
        call.getPlanner().onCopy(filter, leftRel);
    }
    if (!rightFilters.isEmpty()) {
        call.getPlanner().onCopy(filter, rightRel);
    }

    relBuilder.push(newJoinRel);

    // Create a project on top of the join if some of the columns have become
    // NOT NULL due to the join-type getting stricter.
    relBuilder.convert(join.getRowType(), false);

    // create a FilterRel on top of the join if needed
    relBuilder.filter(RexUtil.fixUp(rexBuilder, aboveFilters,
            RelOptUtil.getFieldTypeList(relBuilder.peek().getRowType())));

    call.transformTo(relBuilder.build());
}

From source file:com.google.devtools.build.skyframe.SkyFunctionEnvironment.java

NestedSet<TaggedEvents> buildEvents(NodeEntry entry, boolean missingChildren) throws InterruptedException {
    // Aggregate the nested set of events from the direct deps, also adding the events from
    // building this value.
    NestedSetBuilder<TaggedEvents> eventBuilder = NestedSetBuilder.stableOrder();
    ImmutableList<Event> events = eventHandler.getEvents();
    if (!events.isEmpty()) {
        eventBuilder.add(new TaggedEvents(getTagFromKey(), events));
    }/* w  w w.  j  av a2  s.c om*/
    if (evaluatorContext.getStoredEventFilter().storeEvents()) {
        // Only do the work of processing children if we're going to store events.
        GroupedList<SkyKey> depKeys = entry.getTemporaryDirectDeps();
        Collection<SkyValue> deps = getDepValuesForDoneNodeMaybeFromError(depKeys);
        if (!missingChildren && depKeys.numElements() != deps.size()) {
            throw new IllegalStateException("Missing keys for " + skyKey + ". Present values: " + deps
                    + " requested from: " + depKeys + ", " + entry);
        }
        for (SkyValue value : deps) {
            eventBuilder.addTransitive(ValueWithMetadata.getEvents(value));
        }
    }
    return eventBuilder.build();
}

From source file:org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState.java

/**
 * If a component declares that it belongs to a platform, we add an edge to the platform.
 *
 * @param discoveredEdges the collection of edges for this component
 *///  w  w  w . j ava 2s .  c o  m
private void visitOwners(Collection<EdgeState> discoveredEdges) {
    ImmutableList<? extends ComponentIdentifier> owners = component.getMetadata().getPlatformOwners();
    if (!owners.isEmpty()) {
        PendingDependenciesVisitor visitor = resolveState.newPendingDependenciesVisitor();
        for (ComponentIdentifier owner : owners) {
            if (owner instanceof ModuleComponentIdentifier) {
                ModuleComponentIdentifier platformId = (ModuleComponentIdentifier) owner;
                final ModuleComponentSelector cs = DefaultModuleComponentSelector
                        .newSelector(platformId.getModuleIdentifier(), platformId.getVersion());

                // There are 2 possibilities here:
                // 1. the "platform" referenced is a real module, in which case we directly add it to the graph
                // 2. the "platform" is a virtual, constructed thing, in which case we add virtual edges to the graph
                addPlatformEdges(discoveredEdges, platformId, cs);
                visitor.markNotPending(platformId.getModuleIdentifier());
            }
        }
        visitor.complete();
    }
}

From source file:org.openqa.selenium.remote.server.NewSessionPayload.java

private void validateSpecCompliance(Map<String, Object> fragment) {
    ImmutableList<String> badKeys = fragment.keySet().stream().filter(ACCEPTED_W3C_PATTERNS.negate())
            .collect(ImmutableList.toImmutableList());

    if (!badKeys.isEmpty()) {
        throw new IllegalArgumentException(
                "W3C payload contained keys that do not comply with the spec: " + badKeys);
    }/*from  ww w.java  2 s  . c om*/
}

From source file:com.squareup.javapoet.CodeWriter.java

/**
 * Emit type variables with their bounds. This should only be used when declaring type variables;
 * everywhere else bounds are omitted.//  w  w w  .j ava2  s .co  m
 */
public void emitTypeVariables(ImmutableList<TypeVariable<?>> typeVariables) throws IOException {
    if (typeVariables.isEmpty())
        return;

    emit("<");
    boolean firstTypeVariable = true;
    for (TypeVariable<?> typeVariable : typeVariables) {
        if (!firstTypeVariable)
            emit(", ");
        emit("$L", typeVariable.getName());
        boolean firstBound = true;
        for (Type bound : typeVariable.getBounds()) {
            if (isObject(bound))
                continue;
            emit(firstBound ? " extends $T" : " & $T", bound);
            firstBound = false;
        }
        firstTypeVariable = false;
    }
    emit(">");
}

From source file:com.google.auto.value.processor.BuilderMethodClassifier.java

/**
 * Checks that the given setter method has a parameter type that is compatible with the return
 * type of the given getter. Compatible means either that it is the same, or that it is a type
 * that can be copied using a method like {@code ImmutableList.copyOf} or {@code Optional.of}.
 *
 * @return true if the types correspond, false if an error has been reported.
 *//*from w  w  w  .ja  v a2  s  .  co  m*/
private boolean checkSetterParameter(ExecutableElement valueGetter, ExecutableElement setter) {
    TypeMirror targetType = valueGetter.getReturnType();
    TypeMirror parameterType = setter.getParameters().get(0).asType();
    if (TYPE_EQUIVALENCE.equivalent(parameterType, targetType)) {
        return true;
    }
    ImmutableList<ExecutableElement> copyOfMethods = copyOfMethods(targetType);
    if (!copyOfMethods.isEmpty()) {
        return canMakeCopyUsing(copyOfMethods, valueGetter, setter);
    }
    String error = String.format("Parameter type %s of setter method should be %s to match getter %s.%s",
            parameterType, targetType, autoValueClass, valueGetter.getSimpleName());
    errorReporter.reportError(error, setter);
    return false;
}