Search in sources :

Example 81 with Consumer

use of java.util.function.Consumer in project waltz by khartec.

the class NonAuthSourceHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    AuthoritativeSourceService authoritativeSourceService = ctx.getBean(AuthoritativeSourceService.class);
    Consumer<NonAuthoritativeSource> dumpRow = r -> {
        System.out.println(String.format("%s | %d - %d", r.sourceReference().name().orElse("?"), r.dataTypeId(), r.count()));
    };
    // authoritativeSourceService.findNonAuthSources(mkRef(EntityKind.ORG_UNIT, 200L)).forEach(dumpRow);
    // authoritativeSourceService.findNonAuthSources(mkRef(EntityKind.DATA_TYPE, 6000L)).forEach(dumpRow);
    authoritativeSourceService.findNonAuthSources(mkRef(EntityKind.APP_GROUP, 41)).forEach(dumpRow);
}
Also used : Consumer(java.util.function.Consumer) NonAuthoritativeSource(com.khartec.waltz.model.authoritativesource.NonAuthoritativeSource) DIConfiguration(com.khartec.waltz.service.DIConfiguration) AuthoritativeSourceService(com.khartec.waltz.service.authoritative_source.AuthoritativeSourceService) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityReference.mkRef(com.khartec.waltz.model.EntityReference.mkRef) EntityKind(com.khartec.waltz.model.EntityKind) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) NonAuthoritativeSource(com.khartec.waltz.model.authoritativesource.NonAuthoritativeSource) AuthoritativeSourceService(com.khartec.waltz.service.authoritative_source.AuthoritativeSourceService)

Example 82 with Consumer

use of java.util.function.Consumer in project xtext-xtend by eclipse.

the class QuickfixTestBuilder method tearDown.

public void tearDown() {
    this.editor = null;
    this._workbenchTestHelper.closeAllEditors(false);
    final Consumer<IFile> _function = (IFile it) -> {
        try {
            NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
            it.delete(true, _nullProgressMonitor);
        } catch (Throwable _e) {
            throw Exceptions.sneakyThrow(_e);
        }
    };
    this._workbenchTestHelper.getFiles().forEach(_function);
    this._workbenchTestHelper.getFiles().clear();
    if ((this.modifiedIssueCodes != null)) {
        IPersistentPreferenceStore _preferenceStore = this.getPreferenceStore();
        final Procedure1<IPersistentPreferenceStore> _function_1 = (IPersistentPreferenceStore it) -> {
            final Consumer<String> _function_2 = (String code) -> {
                it.setToDefault(code);
            };
            this.modifiedIssueCodes.forEach(_function_2);
            it.setToDefault(XbaseBuilderPreferenceAccess.PREF_USE_COMPILER_SOURCE);
            it.setToDefault(XbaseBuilderPreferenceAccess.PREF_JAVA_VERSION);
        };
        ObjectExtensions.<IPersistentPreferenceStore>operator_doubleArrow(_preferenceStore, _function_1);
        this.modifiedIssueCodes = null;
    }
    NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
    this._syncUtil.yieldToQueuedDisplayJobs(_nullProgressMonitor);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) Consumer(java.util.function.Consumer) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore)

Example 83 with Consumer

use of java.util.function.Consumer in project xtext-xtend by eclipse.

the class MemberFromSuperImplementor method appendOverrideFunction.

public void appendOverrideFunction(final XtendTypeDeclaration overrider, final IResolvedOperation overriddenOperation, final ISourceAppender appendable) {
    final JvmDeclaredType inferredType = this.associations.getInferredType(overrider);
    final AbstractMethodBuilder methodBuilder = this.codeBuilderFactory.createMethodBuilder(inferredType);
    this.initializeExecutableBuilder(methodBuilder, inferredType, overriddenOperation);
    methodBuilder.setOverrideFlag(true);
    methodBuilder.setMethodName(overriddenOperation.getDeclaration().getSimpleName());
    methodBuilder.setReturnType(overriddenOperation.getResolvedReturnType());
    boolean _isSynchronized = overriddenOperation.getDeclaration().isSynchronized();
    if (_isSynchronized) {
        methodBuilder.setSynchronizedFlag(true);
    }
    boolean _isEmpty = overriddenOperation.getResolvedTypeParameters().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        final ArrayList<JvmTypeParameter> typeParameters = CollectionLiterals.<JvmTypeParameter>newArrayList();
        final Procedure2<JvmTypeParameter, Integer> _function = (JvmTypeParameter typeParam, Integer idx) -> {
            final JvmTypeParameter newTypeParam = this.typesFactory.createJvmTypeParameter();
            newTypeParam.setName(typeParam.getName());
            final Consumer<LightweightTypeReference> _function_1 = (LightweightTypeReference it) -> {
                final JvmUpperBound upperBound = this.typesFactory.createJvmUpperBound();
                upperBound.setTypeReference(it.toJavaCompliantTypeReference());
                EList<JvmTypeConstraint> _constraints = newTypeParam.getConstraints();
                _constraints.add(upperBound);
            };
            overriddenOperation.getResolvedTypeParameterConstraints((idx).intValue()).forEach(_function_1);
            typeParameters.add(newTypeParam);
        };
        IterableExtensions.<JvmTypeParameter>forEach(overriddenOperation.getResolvedTypeParameters(), _function);
        methodBuilder.setTypeParameters(typeParameters);
    }
    boolean _isAbstract = overriddenOperation.getDeclaration().isAbstract();
    boolean _not_1 = (!_isAbstract);
    if (_not_1) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("super.");
        {
            List<JvmTypeParameter> _resolvedTypeParameters = overriddenOperation.getResolvedTypeParameters();
            boolean _hasElements = false;
            for (final JvmTypeParameter typeParam : _resolvedTypeParameters) {
                if (!_hasElements) {
                    _hasElements = true;
                    _builder.append("<");
                } else {
                    _builder.appendImmediate(", ", "");
                }
                String _simpleName = typeParam.getSimpleName();
                _builder.append(_simpleName);
            }
            if (_hasElements) {
                _builder.append(">");
            }
        }
        String _simpleName_1 = overriddenOperation.getDeclaration().getSimpleName();
        _builder.append(_simpleName_1);
        _builder.append("(");
        final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it) -> {
            return it.getSimpleName();
        };
        String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(overriddenOperation.getDeclaration().getParameters(), _function_1), ", ");
        _builder.append(_join);
        _builder.append(")");
        final String body = _builder.toString();
        final Procedure1<? super ISourceAppender> superTypeRef = this.getImplementedInterface(inferredType, overriddenOperation.getDeclaration().getDeclaringType());
        final Procedure1<ISourceAppender> _function_2 = (ISourceAppender it) -> {
            if (superTypeRef != null) {
                superTypeRef.apply(it);
            }
            it.append(body);
        };
        methodBuilder.setBodyGenerator(_function_2);
    }
    boolean _isValid = methodBuilder.isValid();
    if (_isValid) {
        methodBuilder.build(appendable);
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender) JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) Consumer(java.util.function.Consumer) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) AbstractMethodBuilder(org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder)

Example 84 with Consumer

use of java.util.function.Consumer in project xtext-xtend by eclipse.

the class UIResourceChangeRegistryTest method testConcurrentDiscard.

@Test
public void testConcurrentDiscard() throws Exception {
    try {
        final Consumer<Integer> _function = (Integer it) -> {
            this.resourceChangeRegistry.registerCreateOrModify("/foo", this.uri.appendSegment(it.toString()));
        };
        new IntegerRange(1, 10000).forEach(_function);
        final Runnable _function_1 = () -> {
            final SecureRandom random = new SecureRandom(new byte[] { ((byte) 1) });
            final Consumer<Integer> _function_2 = (Integer it) -> {
                final URI removedURI = this.uri.appendSegment(Integer.valueOf(random.nextInt(10000)).toString());
                this.resourceChangeRegistry.discardCreateOrModifyInformation(removedURI);
            };
            new IntegerRange(1, 1000).forEach(_function_2);
        };
        final Runnable r = _function_1;
        final ExecutorService executorService = Executors.newCachedThreadPool();
        try {
            final Future<?> future1 = executorService.submit(r);
            final Future<?> future2 = executorService.submit(r);
            final Future<?> future3 = executorService.submit(r);
            final Future<?> future4 = executorService.submit(r);
            future1.get();
            future2.get();
            future3.get();
            future4.get();
        } catch (final Throwable _t) {
            if (_t instanceof ExecutionException) {
                final ExecutionException e = (ExecutionException) _t;
                throw e.getCause();
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        } finally {
            executorService.shutdown();
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) Consumer(java.util.function.Consumer) ExecutorService(java.util.concurrent.ExecutorService) SecureRandom(java.security.SecureRandom) ExecutionException(java.util.concurrent.ExecutionException) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 85 with Consumer

use of java.util.function.Consumer in project zhcet-web by zhcet-amu.

the class RealTimeStatusController method realTimeSse.

@GetMapping("/management/task/sse/{id}")
public SseEmitter realTimeSse(@PathVariable String id) {
    SseEmitter emitter = new SseEmitter(TIMEOUT);
    RealTimeStatus status = realTimeStatusService.get(id);
    Consumer<RealTimeStatus> consumer = statusChange -> {
        try {
            emitter.send(statusChange);
        } catch (IOException e) {
            log.error("Error sending event", e);
            emitter.complete();
        }
    };
    Runnable completeListener = emitter::complete;
    Runnable onComplete = () -> {
        status.removeChangeListener(consumer);
        status.removeStopListener(completeListener);
    };
    status.addChangeListener(consumer);
    status.onStop(completeListener);
    emitter.onCompletion(onComplete);
    emitter.onTimeout(onComplete);
    consumer.accept(status);
    if (status.isInvalid() || status.isFailed() || status.isFinished())
        emitter.complete();
    return emitter;
}
Also used : Consumer(java.util.function.Consumer) PathVariable(org.springframework.web.bind.annotation.PathVariable) Slf4j(lombok.extern.slf4j.Slf4j) GetMapping(org.springframework.web.bind.annotation.GetMapping) IOException(java.io.IOException) RestController(org.springframework.web.bind.annotation.RestController) SseEmitter(org.springframework.web.servlet.mvc.method.annotation.SseEmitter) SseEmitter(org.springframework.web.servlet.mvc.method.annotation.SseEmitter) IOException(java.io.IOException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Consumer (java.util.function.Consumer)908 List (java.util.List)445 ArrayList (java.util.ArrayList)288 Test (org.junit.Test)250 Map (java.util.Map)228 IOException (java.io.IOException)223 Collectors (java.util.stream.Collectors)205 Collections (java.util.Collections)185 Arrays (java.util.Arrays)181 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)163 TimeUnit (java.util.concurrent.TimeUnit)157 HashMap (java.util.HashMap)152 Set (java.util.Set)149 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)146 Optional (java.util.Optional)132 Collection (java.util.Collection)127 Function (java.util.function.Function)119 CountDownLatch (java.util.concurrent.CountDownLatch)116 File (java.io.File)112 AtomicReference (java.util.concurrent.atomic.AtomicReference)111