Search in sources :

Example 1 with LinkedHashMultimap

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);
}
Also used : LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) Event(org.apache.flink.cep.Event) Test(org.junit.Test)

Example 2 with LinkedHashMultimap

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();
}
Also used : ProjectComparisonEntry(org.eclipse.n4js.compare.ProjectComparisonEntry) Inject(com.google.inject.Inject) TClass(org.eclipse.n4js.ts.types.TClass) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) TSetter(org.eclipse.n4js.ts.types.TSetter) Logger(org.apache.log4j.Logger) TGetterImpl(org.eclipse.n4js.ts.types.impl.TGetterImpl) TMethodImpl(org.eclipse.n4js.ts.types.impl.TMethodImpl) Type(org.eclipse.n4js.ts.types.Type) MemberList(org.eclipse.n4js.ts.types.util.MemberList) N4InterfaceDeclaration(org.eclipse.n4js.n4JS.N4InterfaceDeclaration) TFieldImpl(org.eclipse.n4js.ts.types.impl.TFieldImpl) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) TField(org.eclipse.n4js.ts.types.TField) EObject(org.eclipse.emf.ecore.EObject) PROVIDES_DEFAULT_IMPLEMENTATION(org.eclipse.n4js.AnnotationDefinition.PROVIDES_DEFAULT_IMPLEMENTATION) PROVIDES_INITIALZER(org.eclipse.n4js.AnnotationDefinition.PROVIDES_INITIALZER) TMethod(org.eclipse.n4js.ts.types.TMethod) Collectors(java.util.stream.Collectors) TGetter(org.eclipse.n4js.ts.types.TGetter) List(java.util.List) Stream(java.util.stream.Stream) TClassifier(org.eclipse.n4js.ts.types.TClassifier) Resource(org.eclipse.emf.ecore.resource.Resource) Optional(java.util.Optional) Pair(org.eclipse.xtext.xbase.lib.Pair) TypesFactory(org.eclipse.n4js.ts.types.TypesFactory) Singleton(com.google.inject.Singleton) HashMap(java.util.HashMap) TypeUtils(org.eclipse.n4js.ts.utils.TypeUtils) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TModule(org.eclipse.n4js.ts.types.TModule) TN4Classifier(org.eclipse.n4js.ts.types.TN4Classifier) TInterface(org.eclipse.n4js.ts.types.TInterface) ProjectCompareHelper(org.eclipse.n4js.compare.ProjectCompareHelper) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) TAnnotableElement(org.eclipse.n4js.ts.types.TAnnotableElement) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) LinkedHashSet(java.util.LinkedHashSet) Iterator(java.util.Iterator) TMember(org.eclipse.n4js.ts.types.TMember) Script(org.eclipse.n4js.n4JS.Script) Consumer(java.util.function.Consumer) TypesPackage(org.eclipse.n4js.ts.types.TypesPackage) AdapterImpl(org.eclipse.emf.common.notify.impl.AdapterImpl) TSetterImpl(org.eclipse.n4js.ts.types.impl.TSetterImpl) Collections(java.util.Collections) TMethod(org.eclipse.n4js.ts.types.TMethod) Consumer(java.util.function.Consumer) TInterface(org.eclipse.n4js.ts.types.TInterface) TModule(org.eclipse.n4js.ts.types.TModule) ProjectComparisonEntry(org.eclipse.n4js.compare.ProjectComparisonEntry)

Example 3 with LinkedHashMultimap

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;
}
Also used : LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) Consumer(java.util.function.Consumer) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List)

Example 4 with LinkedHashMultimap

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;
}
Also used : ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) SerializationContext(org.eclipse.xtext.serializer.analysis.SerializationContext) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) IGrammarConstraintProvider(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider) List(java.util.List) SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Pair(org.eclipse.xtext.xbase.lib.Pair)

Aggregations

LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)4 List (java.util.List)3 Consumer (java.util.function.Consumer)2 EObject (org.eclipse.emf.ecore.EObject)2 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)2 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)2 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1