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);
}
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);
}
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")));
}
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();
}
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);
}
Aggregations