Search in sources :

Example 36 with ImmutableList

use of com.google.common.collect.ImmutableList in project presto by prestodb.

the class TestNodeScheduler method setUp.

@BeforeMethod
public void setUp() throws Exception {
    finalizerService = new FinalizerService();
    nodeTaskMap = new NodeTaskMap(finalizerService);
    nodeManager = new InMemoryNodeManager();
    ImmutableList.Builder<Node> nodeBuilder = ImmutableList.builder();
    nodeBuilder.add(new PrestoNode("other1", URI.create("http://127.0.0.1:11"), NodeVersion.UNKNOWN, false));
    nodeBuilder.add(new PrestoNode("other2", URI.create("http://127.0.0.1:12"), NodeVersion.UNKNOWN, false));
    nodeBuilder.add(new PrestoNode("other3", URI.create("http://127.0.0.1:13"), NodeVersion.UNKNOWN, false));
    ImmutableList<Node> nodes = nodeBuilder.build();
    nodeManager.addNode(CONNECTOR_ID, nodes);
    NodeSchedulerConfig nodeSchedulerConfig = new NodeSchedulerConfig().setMaxSplitsPerNode(20).setIncludeCoordinator(false).setMaxPendingSplitsPerTask(10);
    NodeScheduler nodeScheduler = new NodeScheduler(new LegacyNetworkTopology(), nodeManager, nodeSchedulerConfig, nodeTaskMap);
    // contents of taskMap indicate the node-task map for the current stage
    taskMap = new HashMap<>();
    nodeSelector = nodeScheduler.createNodeSelector(CONNECTOR_ID);
    remoteTaskExecutor = Executors.newCachedThreadPool(daemonThreadsNamed("remoteTaskExecutor-%s"));
    finalizerService.start();
}
Also used : FinalizerService(com.facebook.presto.util.FinalizerService) ImmutableList(com.google.common.collect.ImmutableList) Node(com.facebook.presto.spi.Node) PrestoNode(com.facebook.presto.metadata.PrestoNode) LegacyNetworkTopology(com.facebook.presto.execution.scheduler.LegacyNetworkTopology) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) NodeScheduler(com.facebook.presto.execution.scheduler.NodeScheduler) PrestoNode(com.facebook.presto.metadata.PrestoNode) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 37 with ImmutableList

use of com.google.common.collect.ImmutableList in project guava by hceylan.

the class TypeToken method getGenericInterfaces.

/**
   * Returns the generic interfaces that this type directly {@code implements}. This method is
   * similar but different from {@link Class#getGenericInterfaces()}. For example, {@code
   * new TypeToken<List<String>>() {}.getGenericInterfaces()} will return a list that contains
   * {@code new TypeToken<Iterable<String>>() {}}; while {@code List.class.getGenericInterfaces()}
   * will return an array that contains {@code Iterable<T>}, where the {@code T} is the type
   * variable declared by interface {@code Iterable}.
   *
   * <p>If this type is a type variable or wildcard, its upper bounds are examined and those that
   * are either an interface or upper-bounded only by interfaces are returned. This means that the
   * returned types could include type variables too.
   */
final ImmutableList<TypeToken<? super T>> getGenericInterfaces() {
    if (runtimeType instanceof TypeVariable) {
        return boundsAsInterfaces(((TypeVariable<?>) runtimeType).getBounds());
    }
    if (runtimeType instanceof WildcardType) {
        return boundsAsInterfaces(((WildcardType) runtimeType).getUpperBounds());
    }
    ImmutableList.Builder<TypeToken<? super T>> builder = ImmutableList.builder();
    for (Type interfaceType : getRawType().getGenericInterfaces()) {
        // interface of T
        @SuppressWarnings("unchecked") TypeToken<? super T> resolvedInterface = (TypeToken<? super T>) resolveSupertype(interfaceType);
        builder.add(resolvedInterface);
    }
    return builder.build();
}
Also used : WildcardType(java.lang.reflect.WildcardType) GenericArrayType(java.lang.reflect.GenericArrayType) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) TypeVariable(java.lang.reflect.TypeVariable) ImmutableList(com.google.common.collect.ImmutableList)

Example 38 with ImmutableList

use of com.google.common.collect.ImmutableList in project guava by google.

the class QuantilesTest method generatePseudorandomDataset.

private static ImmutableList<Double> generatePseudorandomDataset() {
    Random random = new Random(2211275185798966364L);
    ImmutableList.Builder<Double> largeDatasetBuilder = ImmutableList.builder();
    for (int i = 0; i < PSEUDORANDOM_DATASET_SIZE; i++) {
        largeDatasetBuilder.add(random.nextGaussian());
    }
    return largeDatasetBuilder.build();
}
Also used : Random(java.util.Random) ImmutableList(com.google.common.collect.ImmutableList)

Example 39 with ImmutableList

use of com.google.common.collect.ImmutableList in project guice by google.

the class ProviderMethodsTest method testWildcardProviderMethods.

public void testWildcardProviderMethods() {
    final List<String> strings = ImmutableList.of("A", "B", "C");
    final List<Number> numbers = ImmutableList.<Number>of(1, 2, 3);
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            @SuppressWarnings("unchecked") Key<List<? super Integer>> listOfSupertypesOfInteger = (Key<List<? super Integer>>) Key.get(Types.listOf(Types.supertypeOf(Integer.class)));
            bind(listOfSupertypesOfInteger).toInstance(numbers);
        }

        @Provides
        public List<? extends CharSequence> provideCharSequences() {
            return strings;
        }

        @Provides
        public Class<?> provideType() {
            return Float.class;
        }
    });
    assertSame(strings, injector.getInstance(HasWildcardInjection.class).charSequences);
    assertSame(numbers, injector.getInstance(HasWildcardInjection.class).numbers);
    assertSame(Float.class, injector.getInstance(HasWildcardInjection.class).type);
}
Also used : Provides(com.google.inject.Provides) AbstractModule(com.google.inject.AbstractModule) Injector(com.google.inject.Injector) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Key(com.google.inject.Key)

Example 40 with ImmutableList

use of com.google.common.collect.ImmutableList in project error-prone by google.

the class StrictFormatStringValidation method validateFormatStringParamter.

/** Helps {@code validate()} validate a format string that is declared as a method parameter. */
private static ValidationResult validateFormatStringParamter(ExpressionTree formatStringTree, Symbol formatStringSymbol, List<? extends ExpressionTree> args, VisitorState state) {
    if (!isFormatStringParameter(formatStringSymbol, state)) {
        return ValidationResult.create(null, String.format("Format strings must be compile time constant or parameters annotated " + "@FormatString: %s", formatStringTree));
    }
    List<VarSymbol> ownerParams = ((MethodSymbol) formatStringSymbol.owner).getParameters();
    int ownerFormatStringIndex = ownerParams.indexOf(formatStringSymbol);
    ImmutableList.Builder<Type> ownerFormatArgTypesBuilder = ImmutableList.builder();
    for (VarSymbol paramSymbol : ownerParams.subList(ownerFormatStringIndex + 1, ownerParams.size())) {
        ownerFormatArgTypesBuilder.add(paramSymbol.type);
    }
    ImmutableList<Type> ownerFormatArgTypes = ownerFormatArgTypesBuilder.build();
    Types types = state.getTypes();
    ImmutableList.Builder<Type> calleeFormatArgTypesBuilder = ImmutableList.builder();
    for (ExpressionTree formatArgExpression : args) {
        calleeFormatArgTypesBuilder.add(types.erasure(((JCExpression) formatArgExpression).type));
    }
    ImmutableList<Type> calleeFormatArgTypes = calleeFormatArgTypesBuilder.build();
    if (ownerFormatArgTypes.size() != calleeFormatArgTypes.size()) {
        return ValidationResult.create(null, String.format("The number of format arguments passed " + "with an @FormatString must match the number of format arguments in the " + "@FormatMethod header where the format string was declared.\n\t" + "Format args passed: %d\n\tFormat args expected: %d", calleeFormatArgTypes.size(), ownerFormatArgTypes.size()));
    } else {
        for (int i = 0; i < calleeFormatArgTypes.size(); i++) {
            if (!ASTHelpers.isSameType(ownerFormatArgTypes.get(i), calleeFormatArgTypes.get(i), state)) {
                return ValidationResult.create(null, String.format("The format argument types passed " + "with an @FormatString must match the types of the format arguments in " + "the @FormatMethod header where the format string was declared.\n\t" + "Format arg types passed: %s\n\tFormat arg types expected: %s", calleeFormatArgTypes.toArray(), ownerFormatArgTypes.toArray()));
            }
        }
    }
    // Format string usage was valid.
    return null;
}
Also used : Types(com.sun.tools.javac.code.Types) Type(com.sun.tools.javac.code.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ImmutableList(com.google.common.collect.ImmutableList) ExpressionTree(com.sun.source.tree.ExpressionTree) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)552 Path (java.nio.file.Path)130 List (java.util.List)112 SourcePath (com.facebook.buck.rules.SourcePath)91 Test (org.junit.Test)78 Step (com.facebook.buck.step.Step)76 ImmutableMap (com.google.common.collect.ImmutableMap)69 IOException (java.io.IOException)64 ArrayList (java.util.ArrayList)63 Map (java.util.Map)62 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)52 BuildTarget (com.facebook.buck.model.BuildTarget)47 ImmutableSet (com.google.common.collect.ImmutableSet)44 MkdirStep (com.facebook.buck.step.fs.MkdirStep)39 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)38 Optional (java.util.Optional)38 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)36 HumanReadableException (com.facebook.buck.util.HumanReadableException)36 HashMap (java.util.HashMap)35