use of java.util.Collections in project component-runtime by Talend.
the class ConfigurationMapper method map.
private Map<String, String> map(final List<ParameterMeta> nestedParameters, final Object instance, final Map<Integer, Integer> indexes) {
if (nestedParameters == null) {
return emptyMap();
}
return nestedParameters.stream().map(param -> {
final Object value = getValue(instance, param.getName());
if (value == null) {
return Collections.<String, String>emptyMap();
}
switch(param.getType()) {
case OBJECT:
return map(param.getNestedParameters(), value, indexes);
case ARRAY:
final Collection<Object> values = Collection.class.isInstance(value) ? Collection.class.cast(value) : /* array */
asList(Object[].class.cast(value));
final int arrayIndex = indexes.keySet().size();
final AtomicInteger valuesIndex = new AtomicInteger(0);
final Map<String, String> config = values.stream().map((Object item) -> {
indexes.put(arrayIndex, valuesIndex.getAndIncrement());
final Map<String, String> res = param.getNestedParameters().stream().filter(ConfigurationMapper::isPrimitive).collect(toMap(p -> evaluateIndexes(p.getPath(), indexes), p -> getValue(item, p.getName()).toString()));
res.putAll(map(param.getNestedParameters().stream().filter(p -> !isPrimitive(p)).collect(toList()), item, indexes));
return res;
}).flatMap(m -> m.entrySet().stream()).collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
// clear index after the end of array handling
indexes.clear();
return config;
default:
// primitives
return singletonMap(evaluateIndexes(param.getPath(), indexes), value.toString());
}
}).flatMap(m -> m.entrySet().stream()).collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}
use of java.util.Collections in project neo4j by neo4j.
the class JoltNodeSerializer method serialize.
@Override
public void serialize(Node node, JsonGenerator generator, SerializerProvider provider) throws IOException {
generator.writeStartObject(node);
generator.writeFieldName(Sigil.NODE.getValue());
generator.writeStartArray();
generator.writeNumber(node.getId());
generator.writeStartArray();
for (Label label : node.getLabels()) {
generator.writeString(label.name());
}
generator.writeEndArray();
var properties = Optional.ofNullable(node.getAllProperties()).orElseGet(Collections::emptyMap);
generator.writeStartObject();
for (var entry : properties.entrySet()) {
generator.writeFieldName(entry.getKey());
generator.writeObject(entry.getValue());
}
generator.writeEndObject();
generator.writeEndArray();
generator.writeEndObject();
}
use of java.util.Collections in project flink by apache.
the class TaskAsyncCallTest method createTask.
private Task createTask(Class<? extends AbstractInvokable> invokableClass) throws Exception {
final TestingClassLoaderLease classLoaderHandle = TestingClassLoaderLease.newBuilder().setGetOrResolveClassLoaderFunction((permanentBlobKeys, urls) -> TestingUserCodeClassLoader.newBuilder().setClassLoader(new TestUserCodeClassLoader()).build()).build();
ResultPartitionConsumableNotifier consumableNotifier = new NoOpResultPartitionConsumableNotifier();
PartitionProducerStateChecker partitionProducerStateChecker = mock(PartitionProducerStateChecker.class);
Executor executor = mock(Executor.class);
TaskMetricGroup taskMetricGroup = UnregisteredMetricGroups.createUnregisteredTaskMetricGroup();
JobInformation jobInformation = new JobInformation(new JobID(), "Job Name", new SerializedValue<>(new ExecutionConfig()), new Configuration(), Collections.emptyList(), Collections.emptyList());
TaskInformation taskInformation = new TaskInformation(new JobVertexID(), "Test Task", 1, 1, invokableClass.getName(), new Configuration());
return new Task(jobInformation, taskInformation, new ExecutionAttemptID(), new AllocationID(), 0, 0, Collections.<ResultPartitionDeploymentDescriptor>emptyList(), Collections.<InputGateDeploymentDescriptor>emptyList(), mock(MemoryManager.class), mock(IOManager.class), shuffleEnvironment, new KvStateService(new KvStateRegistry(), null, null), mock(BroadcastVariableManager.class), new TaskEventDispatcher(), ExternalResourceInfoProvider.NO_EXTERNAL_RESOURCES, new TestTaskStateManager(), mock(TaskManagerActions.class), mock(InputSplitProvider.class), mock(CheckpointResponder.class), new NoOpTaskOperatorEventGateway(), new TestGlobalAggregateManager(), classLoaderHandle, mock(FileCache.class), new TestingTaskManagerRuntimeInfo(), taskMetricGroup, consumableNotifier, partitionProducerStateChecker, executor);
}
use of java.util.Collections in project flink by apache.
the class ExecutingTest method testFalseReportsViaUpdateTaskExecutionStateAreIgnored.
@Test
public void testFalseReportsViaUpdateTaskExecutionStateAreIgnored() throws Exception {
try (MockExecutingContext ctx = new MockExecutingContext()) {
MockExecutionGraph returnsFailedStateExecutionGraph = new MockExecutionGraph(false, Collections::emptyList);
Executing exec = new ExecutingStateBuilder().setExecutionGraph(returnsFailedStateExecutionGraph).build(ctx);
Exception exception = new RuntimeException();
TestingAccessExecution execution = TestingAccessExecution.newBuilder().withExecutionState(ExecutionState.FAILED).withErrorInfo(new ErrorInfo(exception, System.currentTimeMillis())).build();
returnsFailedStateExecutionGraph.registerExecution(execution);
TaskExecutionStateTransition taskExecutionStateTransition = createFailingStateTransition(execution.getAttemptId(), exception);
exec.updateTaskExecutionState(taskExecutionStateTransition);
ctx.assertNoStateTransition();
}
}
use of java.util.Collections in project druid by druid-io.
the class LookupSegmentWrangler method getSegmentsForIntervals.
@Override
public Iterable<Segment> getSegmentsForIntervals(final DataSource dataSource, final Iterable<Interval> intervals) {
final LookupDataSource lookupDataSource = (LookupDataSource) dataSource;
final Optional<LookupExtractorFactoryContainer> maybeContainer = lookupProvider.get(lookupDataSource.getLookupName());
return maybeContainer.map(container -> Collections.<Segment>singletonList(new LookupSegment(lookupDataSource.getLookupName(), container.getLookupExtractorFactory()))).orElse(Collections.emptyList());
}
Aggregations