Search in sources :

Example 61 with ImmutableList

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

the class Template method expectedTypes.

/**
   * Returns a list of the expected types to be matched.  This consists of the argument types from
   * the @BeforeTemplate method, concatenated with the return types of expression placeholders, 
   * sorted by the name of the placeholder method.
   *
   * @throws CouldNotResolveImportException if a referenced type could not be resolved
   */
protected List<Type> expectedTypes(Inliner inliner) throws CouldNotResolveImportException {
    ArrayList<Type> result = new ArrayList<>();
    ImmutableList<UType> types = expressionArgumentTypes().values().asList();
    ImmutableList<String> argNames = expressionArgumentTypes().keySet().asList();
    for (int i = 0; i < argNames.size(); i++) {
        String argName = argNames.get(i);
        Optional<JCExpression> singleBinding = inliner.getOptionalBinding(new UFreeIdent.Key(argName));
        if (!singleBinding.isPresent()) {
            Optional<java.util.List<JCExpression>> exprs = inliner.getOptionalBinding(new URepeated.Key(argName));
            if (!exprs.isPresent() || exprs.get().isEmpty()) {
                // It is a repeated template variable and matches no expressions.
                continue;
            }
        }
        result.add(types.get(i).inline(inliner));
    }
    for (PlaceholderExpressionKey key : Ordering.natural().immutableSortedCopy(Iterables.filter(inliner.bindings.keySet(), PlaceholderExpressionKey.class))) {
        result.add(key.method.returnType().inline(inliner));
    }
    return List.from(result);
}
Also used : ArrayList(java.util.ArrayList) MethodType(com.sun.tools.javac.code.Type.MethodType) Type(com.sun.tools.javac.code.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) List(com.sun.tools.javac.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) PlaceholderExpressionKey(com.google.errorprone.refaster.PlaceholderMethod.PlaceholderExpressionKey)

Example 62 with ImmutableList

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

the class Template method actualTypes.

/**
   * Returns a list of the actual types to be matched.  This consists of the types of the 
   * expressions bound to the @BeforeTemplate method parameters, concatenated with the types
   * of the expressions bound to expression placeholders, sorted by the name of the placeholder 
   * method.
   */
protected List<Type> actualTypes(Inliner inliner) {
    ArrayList<Type> result = new ArrayList<>();
    ImmutableList<String> argNames = expressionArgumentTypes().keySet().asList();
    for (int i = 0; i < expressionArgumentTypes().size(); i++) {
        String argName = argNames.get(i);
        Optional<JCExpression> singleBinding = inliner.getOptionalBinding(new UFreeIdent.Key(argName));
        if (singleBinding.isPresent()) {
            result.add(singleBinding.get().type);
        } else {
            Optional<java.util.List<JCExpression>> exprs = inliner.getOptionalBinding(new URepeated.Key(argName));
            if (exprs.isPresent() && !exprs.get().isEmpty()) {
                Type[] exprTys = new Type[exprs.get().size()];
                for (int j = 0; j < exprs.get().size(); j++) {
                    exprTys[j] = exprs.get().get(j).type;
                }
                // Get the least upper bound of the types of all expressions that the argument matches.
                // In the special case where exprs is empty, returns the "bottom" type, which is a
                // subtype of everything.
                result.add(inliner.types().lub(List.from(exprTys)));
            }
        }
    }
    for (PlaceholderExpressionKey key : Ordering.natural().immutableSortedCopy(Iterables.filter(inliner.bindings.keySet(), PlaceholderExpressionKey.class))) {
        result.add(inliner.getBinding(key).type);
    }
    return List.from(result);
}
Also used : ArrayList(java.util.ArrayList) MethodType(com.sun.tools.javac.code.Type.MethodType) Type(com.sun.tools.javac.code.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) List(com.sun.tools.javac.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) PlaceholderExpressionKey(com.google.errorprone.refaster.PlaceholderMethod.PlaceholderExpressionKey)

Example 63 with ImmutableList

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

the class CycleDetectingLockTest method testCycleReporting.

/**
   * Verifies that factories deadlocks report the correct cycles.
   *
   * <pre>
   *   Thread 1: takes locks a, b
   *   Thread 2: takes locks b, c
   *   Thread 3: takes locks c, a
   * </pre>
   *
   * <p>In order to ensure a deadlock, each thread will wait on a barrier right after grabbing the
   * first lock.
   */
public void testCycleReporting() throws Exception {
    final CycleDetectingLockFactory<String> factory = new CycleDetectingLockFactory<String>();
    final CycleDetectingLock<String> lockA = factory.create("a");
    final CycleDetectingLock<String> lockB = factory.create("b");
    final CycleDetectingLock<String> lockC = factory.create("c");
    final CyclicBarrier barrier = new CyclicBarrier(3);
    ImmutableList<Future<ListMultimap<Thread, String>>> futures = ImmutableList.of(grabLocksInThread(lockA, lockB, barrier), grabLocksInThread(lockB, lockC, barrier), grabLocksInThread(lockC, lockA, barrier));
    // At least one of the threads will report a lock cycle, it is possible that they all will, but
    // there is no guarantee, so we just scan for the first thread that reported a cycle
    ListMultimap<Thread, String> cycle = null;
    for (Future<ListMultimap<Thread, String>> future : futures) {
        ListMultimap<Thread, String> value = future.get(DEADLOCK_TIMEOUT_SECONDS * 3, TimeUnit.SECONDS);
        if (!value.isEmpty()) {
            cycle = value;
            break;
        }
    }
    // We don't really care about the keys in the multimap, but we want to make sure that all locks
    // were reported in the right order.
    assertEquals(6, cycle.size());
    Collection<List<String>> edges = Multimaps.asMap(cycle).values();
    assertTrue(edges.contains(ImmutableList.of("a", "b")));
    assertTrue(edges.contains(ImmutableList.of("b", "c")));
    assertTrue(edges.contains(ImmutableList.of("c", "a")));
}
Also used : CycleDetectingLockFactory(com.google.inject.internal.CycleDetectingLock.CycleDetectingLockFactory) CyclicBarrier(java.util.concurrent.CyclicBarrier) Future(java.util.concurrent.Future) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ListMultimap(com.google.common.collect.ListMultimap)

Example 64 with ImmutableList

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

the class HiveMetadata method computePartitionUpdatesForMissingBuckets.

private ImmutableList<PartitionUpdate> computePartitionUpdatesForMissingBuckets(HiveWritableTableHandle handle, Table table, List<PartitionUpdate> partitionUpdates) {
    ImmutableList.Builder<PartitionUpdate> partitionUpdatesForMissingBucketsBuilder = ImmutableList.builder();
    HiveStorageFormat storageFormat = table.getPartitionColumns().isEmpty() ? handle.getTableStorageFormat() : handle.getPartitionStorageFormat();
    for (PartitionUpdate partitionUpdate : partitionUpdates) {
        int bucketCount = handle.getBucketProperty().get().getBucketCount();
        List<String> fileNamesForMissingBuckets = computeFileNamesForMissingBuckets(storageFormat, partitionUpdate.getTargetPath(), handle.getFilePrefix(), bucketCount, partitionUpdate);
        partitionUpdatesForMissingBucketsBuilder.add(new PartitionUpdate(partitionUpdate.getName(), partitionUpdate.isNew(), partitionUpdate.getWritePath(), partitionUpdate.getTargetPath(), fileNamesForMissingBuckets));
    }
    return partitionUpdatesForMissingBucketsBuilder.build();
}
Also used : HiveTableProperties.getHiveStorageFormat(com.facebook.presto.hive.HiveTableProperties.getHiveStorageFormat) StorageFormat.fromHiveStorageFormat(com.facebook.presto.hive.metastore.StorageFormat.fromHiveStorageFormat) ImmutableList(com.google.common.collect.ImmutableList) Constraint(com.facebook.presto.spi.Constraint)

Example 65 with ImmutableList

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

the class KafkaRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
    KafkaSplit kafkaSplit = convertSplit(split);
    ImmutableList.Builder<DecoderColumnHandle> handleBuilder = ImmutableList.builder();
    ImmutableMap.Builder<DecoderColumnHandle, FieldDecoder<?>> keyFieldDecoderBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<DecoderColumnHandle, FieldDecoder<?>> messageFieldDecoderBuilder = ImmutableMap.builder();
    RowDecoder keyDecoder = registry.getRowDecoder(kafkaSplit.getKeyDataFormat());
    RowDecoder messageDecoder = registry.getRowDecoder(kafkaSplit.getMessageDataFormat());
    for (ColumnHandle handle : columns) {
        KafkaColumnHandle columnHandle = convertColumnHandle(handle);
        handleBuilder.add(columnHandle);
        if (!columnHandle.isInternal()) {
            if (columnHandle.isKeyDecoder()) {
                FieldDecoder<?> fieldDecoder = registry.getFieldDecoder(kafkaSplit.getKeyDataFormat(), columnHandle.getType().getJavaType(), columnHandle.getDataFormat());
                keyFieldDecoderBuilder.put(columnHandle, fieldDecoder);
            } else {
                FieldDecoder<?> fieldDecoder = registry.getFieldDecoder(kafkaSplit.getMessageDataFormat(), columnHandle.getType().getJavaType(), columnHandle.getDataFormat());
                messageFieldDecoderBuilder.put(columnHandle, fieldDecoder);
            }
        }
    }
    ImmutableList<DecoderColumnHandle> handles = handleBuilder.build();
    ImmutableMap<DecoderColumnHandle, FieldDecoder<?>> keyFieldDecoders = keyFieldDecoderBuilder.build();
    ImmutableMap<DecoderColumnHandle, FieldDecoder<?>> messageFieldDecoders = messageFieldDecoderBuilder.build();
    return new KafkaRecordSet(kafkaSplit, consumerManager, handles, keyDecoder, messageDecoder, keyFieldDecoders, messageFieldDecoders);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) KafkaHandleResolver.convertColumnHandle(com.facebook.presto.kafka.KafkaHandleResolver.convertColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) RowDecoder(com.facebook.presto.decoder.RowDecoder) ImmutableMap(com.google.common.collect.ImmutableMap) FieldDecoder(com.facebook.presto.decoder.FieldDecoder)

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