Example usage for java.util.function Consumer Consumer

List of usage examples for java.util.function Consumer Consumer

Introduction

In this page you can find the example usage for java.util.function Consumer Consumer.

Prototype

Consumer

Source Link

Usage

From source file:com.diversityarrays.kdxplore.trials.TrialExplorerPanel.java

private void handleServiceDetected(String msgTitle, Trial trial, TrialDataEditorService service) {
    CurationParams params = new CurationParams();
    params.title = msgTitle;//from w  ww . j a v a 2 s  .  co  m
    params.trial = trial;
    params.offlineData = offlineData;
    params.messageLogger = messageLogger;
    params.component = TrialExplorerPanel.this;
    params.windowOpener = windowOpener;

    long start = System.currentTimeMillis();

    Consumer<Either<InitError, TrialDataEditorResult>> onComplete = new Consumer<Either<InitError, TrialDataEditorResult>>() {
        @Override
        public void accept(Either<InitError, TrialDataEditorResult> either) {

            long elapsed = System.currentTimeMillis() - start;
            Shared.Log.i(TAG, "doEditTrial.generateResult: Time to load trialData for trialId#"
                    + params.trial.getTrialId() + "=" + elapsed + " ms");

            if (either.isRight()) {
                TrialDataEditorResult result = either.right();

                result.curationData.addSamplesSavedListener(samplesSavedListener);

                result.frame.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosed(WindowEvent e) {
                        result.frame.removeWindowListener(this);

                        result.curationData.removeSamplesSavedListener(samplesSavedListener);

                        Window ownerWindow = GuiUtil.getOwnerWindow(TrialExplorerPanel.this);
                        if (ownerWindow != null) {
                            ownerWindow.toFront();
                            ownerWindow.repaint();
                        }
                    }
                });

                GuiUtil.ensureMaximized(result.frame);
            } else {
                InitError initError = either.left();
                if (initError.throwable == null) {
                    messageLogger.e(TAG, params.title);
                    MsgBox.error(TrialExplorerPanel.this, initError.message,
                            trial.getTrialName() + ": Unable to create editor");
                } else {
                    Throwable error = initError.throwable;
                    messageLogger.e(TAG, params.title, error);
                    MsgBox.error(TrialExplorerPanel.this, error.getMessage(),
                            trial.getTrialName() + ": Unable to create editor");
                }
            }
        }
    };
    service.createUserInterface(backgroundRunner, params, onComplete);
}

From source file:module.siadap.domain.wrappers.PersonSiadapWrapper.java

@Atomic
public void removeFromSiadapStructure(boolean preserveResponsabilityRelations) throws SiadapException {
    if (getSiadap() != null) {
        // shouldn't remove the structure, simply nullify it
        throw new SiadapException("error.should.nullify.not.remove",
                getPerson() != null ? getPerson().getPresentationName() : "-");
    }/*from   w w  w. j  a  va2s .  c om*/

    Set<AccountabilityType> accTypesToConsider = new HashSet<AccountabilityType>();

    if (preserveResponsabilityRelations == false) {
        accTypesToConsider.add(getConfiguration().getUnitRelations());
        accTypesToConsider.add(getConfiguration().getHarmonizationUnitRelations());
        accTypesToConsider.add(getConfiguration().getHarmonizationResponsibleRelation());
    }

    accTypesToConsider.add(getConfiguration().getEvaluationRelation());
    accTypesToConsider.add(getConfiguration().getWorkingRelation());
    accTypesToConsider.add(getConfiguration().getWorkingRelationWithNoQuota());
    accTypesToConsider.add(getConfiguration().getSiadap2HarmonizationRelation());
    accTypesToConsider.add(getConfiguration().getSiadap3HarmonizationRelation());

    getPerson().getParentAccountabilityStream()
            .filter(a -> match(a, accTypesToConsider.toArray(new AccountabilityType[0])))
            .forEach(new Consumer<Accountability>() {
                @Override
                public void accept(final Accountability acc) {
                    if (acc.isActive(SiadapMiscUtilClass.lastDayOfYearWhereAccsAreActive(getYear()))) {
                        if (preserveResponsabilityRelations
                                && acc.getAccountabilityType()
                                        .equals(getConfiguration().getEvaluationRelation())
                                && acc.getParent() instanceof Unit) {
                            //let us not remove this one, because if we did, we would have deleted a responsability towards
                            //evaluating a unit
                            return;
                        }

                        // let's close it on the last day of the previous year, or, in
                        // case it has a beginning year equal to this one, let's delete
                        // it because it was a mistake
                        if (acc.getBeginDate().getYear() == getYear()) {
                            acc.delete(null);
                        } else {
                            acc.setEndDate(
                                    getConfiguration().getPreviousSiadapYearConfiguration().getLastDay());
                        }
                    }
                }
            });
}