use of com.google.common.collect.LinkedHashMultimap in project flink by apache.
the class SharedBufferTest method testSharedBuffer.
@Test
public void testSharedBuffer() {
SharedBuffer<String, Event> sharedBuffer = new SharedBuffer<>(Event.createTypeSerializer());
int numberEvents = 8;
Event[] events = new Event[numberEvents];
final long timestamp = 1L;
for (int i = 0; i < numberEvents; i++) {
events[i] = new Event(i + 1, "e" + (i + 1), i);
}
LinkedHashMultimap<String, Event> expectedPattern1 = LinkedHashMultimap.create();
expectedPattern1.put("a1", events[2]);
expectedPattern1.put("a[]", events[3]);
expectedPattern1.put("b", events[5]);
LinkedHashMultimap<String, Event> expectedPattern2 = LinkedHashMultimap.create();
expectedPattern2.put("a1", events[0]);
expectedPattern2.put("a[]", events[1]);
expectedPattern2.put("a[]", events[2]);
expectedPattern2.put("a[]", events[3]);
expectedPattern2.put("a[]", events[4]);
expectedPattern2.put("b", events[5]);
LinkedHashMultimap<String, Event> expectedPattern3 = LinkedHashMultimap.create();
expectedPattern3.put("a1", events[0]);
expectedPattern3.put("a[]", events[1]);
expectedPattern3.put("a[]", events[2]);
expectedPattern3.put("a[]", events[3]);
expectedPattern3.put("a[]", events[4]);
expectedPattern3.put("a[]", events[5]);
expectedPattern3.put("a[]", events[6]);
expectedPattern3.put("b", events[7]);
sharedBuffer.put("a1", events[0], timestamp, null, null, 0, DeweyNumber.fromString("1"));
sharedBuffer.put("a[]", events[1], timestamp, "a1", events[0], timestamp, DeweyNumber.fromString("1.0"));
sharedBuffer.put("a1", events[2], timestamp, null, null, 0, DeweyNumber.fromString("2"));
sharedBuffer.put("a[]", events[2], timestamp, "a[]", events[1], timestamp, DeweyNumber.fromString("1.0"));
sharedBuffer.put("a[]", events[3], timestamp, "a[]", events[2], timestamp, DeweyNumber.fromString("1.0"));
sharedBuffer.put("a[]", events[3], timestamp, "a1", events[2], timestamp, DeweyNumber.fromString("2.0"));
sharedBuffer.put("a[]", events[4], timestamp, "a[]", events[3], timestamp, DeweyNumber.fromString("1.0"));
sharedBuffer.put("a[]", events[5], timestamp, "a[]", events[4], timestamp, DeweyNumber.fromString("1.1"));
sharedBuffer.put("b", events[5], timestamp, "a[]", events[3], timestamp, DeweyNumber.fromString("2.0.0"));
sharedBuffer.put("b", events[5], timestamp, "a[]", events[4], timestamp, DeweyNumber.fromString("1.0.0"));
sharedBuffer.put("a[]", events[6], timestamp, "a[]", events[5], timestamp, DeweyNumber.fromString("1.1"));
sharedBuffer.put("b", events[7], timestamp, "a[]", events[6], timestamp, DeweyNumber.fromString("1.1.0"));
Collection<LinkedHashMultimap<String, Event>> patterns3 = sharedBuffer.extractPatterns("b", events[7], timestamp, DeweyNumber.fromString("1.1.0"));
sharedBuffer.remove("b", events[7], timestamp);
Collection<LinkedHashMultimap<String, Event>> patterns4 = sharedBuffer.extractPatterns("b", events[7], timestamp, DeweyNumber.fromString("1.1.0"));
Collection<LinkedHashMultimap<String, Event>> patterns1 = sharedBuffer.extractPatterns("b", events[5], timestamp, DeweyNumber.fromString("2.0.0"));
Collection<LinkedHashMultimap<String, Event>> patterns2 = sharedBuffer.extractPatterns("b", events[5], timestamp, DeweyNumber.fromString("1.0.0"));
sharedBuffer.remove("b", events[5], timestamp);
assertTrue(sharedBuffer.isEmpty());
assertTrue(patterns4.isEmpty());
assertEquals(Collections.singletonList(expectedPattern1), patterns1);
assertEquals(Collections.singletonList(expectedPattern2), patterns2);
assertEquals(Collections.singletonList(expectedPattern3), patterns3);
}
use of com.google.common.collect.LinkedHashMultimap in project n4js by eclipse.
the class ScriptApiTracker method computeMissingApiMethods.
/**
* Looking for at.ProvidesDefaultImplementation on Methods. Normal method declarations are not taken into account,
* since they would not be executed on the interface level.
*
* Beware: also the inheritance in the original API will be taken into account since compiled client code will link
* against that.
*
* @param type
* type to search for apis.
* @return List of {@link VirtualApiTMethod}
*/
public List<TMethod> computeMissingApiMethods(TInterface type, EObject context) {
Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(context.eResource());
if (optAdapt.isPresent()) {
ProjectComparisonAdapter projectComparisonAdapter = optAdapt.get();
ProjectComparisonEntry compareEntry = projectComparisonAdapter.getEntryFor(EcoreUtil2.getContainerOfType(type, TModule.class));
ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(type);
if (typeCompare == null) {
// are we in a completely missing API implementation (super-interfaces not implemented ?)
typeCompare = compareEntry.getChildForElementAPI(type);
}
if (typeCompare == null) {
if (logger.isDebugEnabled()) {
logger.debug(" want to throw new IllegalstateException() --> comparison for implementation not found type=" + type.getTypeAsString() + " in Implementation " + compareEntry.getElementImpl()[0]);
}
return emptyList();
}
LinkedHashMultimap<TMethod, TInterface> lhmmMehodInterface = LinkedHashMultimap.<TMethod, TInterface>create();
Predicate<ProjectComparisonEntry> filter = (pce -> pce.getElementAPI() instanceof TMethod);
filter = filter.and(pce -> pce.getElementImpl()[0] == null).and(pce -> PROVIDES_DEFAULT_IMPLEMENTATION.hasAnnotation((TMethod) pce.getElementAPI()));
Function<TInterface, Consumer<? super ProjectComparisonEntry>> actionProvider = pivot -> pce -> {
TMethod method = ((TMethod) pce.getElementAPI());
lhmmMehodInterface.put(method, pivot);
};
if (!checkInterfaceImplementsInterface(type, typeCompare.getElementAPI())) {
return emptyList();
}
// Call the supertype iterations scaffolding:
interfaceApiSupertypeWalker(filter, actionProvider, projectComparisonAdapter, (TInterface) typeCompare.getElementAPI(), TInterface.class);
// out in the caller when processing our results...
return lhmmMehodInterface.keySet().stream().map(m -> new VirtualApiTMethod(m.getName(), TypeUtils.copyPartial(m, TypesPackage.Literals.SYNTAX_RELATED_TELEMENT__AST_ELEMENT))).collect(Collectors.toList());
}
return emptyList();
}
use of com.google.common.collect.LinkedHashMultimap in project xtext-core by eclipse.
the class SerializerFragment2 method genCondition.
private StringConcatenationClient genCondition(final List<ISerializationContext> contexts, final IGrammarConstraintProvider.IConstraint constraint, final Multimap<EObject, IGrammarConstraintProvider.IConstraint> ctx2ctr) {
StringConcatenationClient _xblockexpression = null;
{
final List<ISerializationContext> sorted = IterableExtensions.<ISerializationContext>sort(contexts);
final LinkedHashMultimap<EObject, ISerializationContext> index = LinkedHashMultimap.<EObject, ISerializationContext>create();
final Consumer<ISerializationContext> _function = (ISerializationContext it) -> {
index.put(this.getContextObject(it), it);
};
sorted.forEach(_function);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
Set<EObject> _keySet = index.keySet();
boolean _hasElements = false;
for (final EObject obj : _keySet) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate("\n\t\t|| ", "");
}
StringConcatenationClient _genObjectSelector = SerializerFragment2.this.genObjectSelector(obj);
_builder.append(_genObjectSelector);
{
int _size = ctx2ctr.get(obj).size();
boolean _greaterThan = (_size > 1);
if (_greaterThan) {
StringConcatenationClient _genParameterSelector = SerializerFragment2.this.genParameterSelector(obj, index.get(obj), constraint);
_builder.append(_genParameterSelector);
}
}
}
}
}
};
_xblockexpression = _client;
}
return _xblockexpression;
}
use of com.google.common.collect.LinkedHashMultimap in project xtext-core by eclipse.
the class SerializerFragment2 method genMethodCreateSequenceCaseBody.
private StringConcatenationClient genMethodCreateSequenceCaseBody(final Map<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint> superConstraints, final EClass type) {
StringConcatenationClient _xblockexpression = null;
{
final Function1<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>, String> _function = (Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>> it) -> {
return it.getKey().getName();
};
final List<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>> contexts = IterableExtensions.<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>, String>sortBy(this._semanticSequencerExtensions.getGrammarConstraints(this.getGrammar(), type).entrySet(), _function);
final LinkedHashMultimap<EObject, IGrammarConstraintProvider.IConstraint> context2constraint = LinkedHashMultimap.<EObject, IGrammarConstraintProvider.IConstraint>create();
for (final Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>> e : contexts) {
List<ISerializationContext> _value = e.getValue();
for (final ISerializationContext ctx : _value) {
context2constraint.put(((SerializationContext) ctx).getActionOrRule(), e.getKey());
}
}
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
int _size = contexts.size();
boolean _greaterThan = (_size > 1);
if (_greaterThan) {
{
Iterable<Pair<Integer, Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>>> _indexed = IterableExtensions.<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>>indexed(contexts);
for (final Pair<Integer, Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>> ctx : _indexed) {
{
Integer _key = ctx.getKey();
boolean _greaterThan_1 = ((_key).intValue() > 0);
if (_greaterThan_1) {
_builder.append("else ");
}
}
_builder.append("if (");
StringConcatenationClient _genCondition = SerializerFragment2.this.genCondition(ctx.getValue().getValue(), ctx.getValue().getKey(), context2constraint);
_builder.append(_genCondition);
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
StringConcatenationClient _genMethodCreateSequenceCall = SerializerFragment2.this.genMethodCreateSequenceCall(superConstraints, type, ctx.getValue().getKey());
_builder.append(_genMethodCreateSequenceCall, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
}
_builder.append("else break;");
_builder.newLine();
} else {
int _size_1 = contexts.size();
boolean _equals = (_size_1 == 1);
if (_equals) {
StringConcatenationClient _genMethodCreateSequenceCall_1 = SerializerFragment2.this.genMethodCreateSequenceCall(superConstraints, type, IterableExtensions.<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>>head(contexts).getKey());
_builder.append(_genMethodCreateSequenceCall_1);
_builder.newLineIfNotEmpty();
} else {
_builder.append("// error, no contexts. ");
_builder.newLine();
}
}
}
}
};
_xblockexpression = _client;
}
return _xblockexpression;
}
Aggregations