Example usage for javafx.util Pair getValue

List of usage examples for javafx.util Pair getValue

Introduction

In this page you can find the example usage for javafx.util Pair getValue.

Prototype

public V getValue() 

Source Link

Document

Gets the value for this pair.

Usage

From source file:org.mskcc.shenkers.view.GenericStackedIntervalView.java

public void setData(List<Pair<Integer, Integer>> intervals, List<T> content) {
    rows.clear();//from  w ww .  j  a  v  a2 s.com
    rowNodes.clear();

    rows.add(TreeRangeSet.create());
    rowNodes.add(new ArrayList<>());

    List<IntervalNode<T>> nodes = Stream.iterate(0, i -> i + 1).limit(intervals.size())
            .map(i -> new IntervalNode<T>(intervals.get(i), content.get(i))).collect(Collectors.toList());

    Collections.sort(nodes, new Comparator<IntervalNode<T>>() {

        @Override
        public int compare(IntervalNode<T> o1, IntervalNode<T> o2) {
            return o1.interval.getKey() - o2.interval.getKey();
        }
    });

    for (IntervalNode inode : nodes) {
        Pair<Integer, Integer> interval = inode.interval;
        Range<Integer> range = Range.closed(interval.getKey(), interval.getValue());
        logger.info("stacking {}", interval);
        int i = 0;
        added: {
            // add the interval to the first row that doesn't intersect with
            while (i < rows.size()) {
                TreeRangeSet<Integer> set = rows.get(i);
                List<IntervalNode<T>> rowContent = rowNodes.get(i);
                RangeSet<Integer> intersection = set.subRangeSet(
                        Range.closed(interval.getKey() - minSpace, interval.getValue() + minSpace));
                if (intersection.isEmpty()) {
                    set.add(range);
                    rowContent.add(inode);
                    logger.info("no intersections in row {}", i);
                    break added;
                }
                logger.info("intersects in row {} {}", i, set);
                i++;
            }

            TreeRangeSet<Integer> row = TreeRangeSet.create();
            row.add(range);
            rows.add(row);

            List<IntervalNode<T>> rowContent = new ArrayList<>();
            rowContent.add(inode);
            rowNodes.add(rowContent);
        }
    }

    //        {
    //            Rectangle background = new Rectangle();
    //            background.setFill(Color.WHITE);
    //            background.widthProperty().bind(widthProperty());
    //            background.heightProperty().bind(heightProperty());
    //            getChildren().add(background);
    //        }

    List<T> children = new ArrayList<>();

    for (List<IntervalNode<T>> row : rowNodes) {
        GenericIntervalView<T> rowView = new GenericIntervalView<>(min, max);

        List<Pair<Integer, Integer>> rowIntervals = new ArrayList<>(row.size());
        List<T> rowContent = new ArrayList<>(row.size());
        row.stream().forEach(i -> {
            rowIntervals.add(i.interval);
            rowContent.add(i.content);
        });
        rowView.setData(rowIntervals, rowContent);
        rowView.flipDomainProperty().bind(flipDomain);

        children.add((T) rowView);
    }

    getChildren().addAll(children);
}

From source file:cz.fi.muni.pa165.facade.GameFacadeImpl.java

@Override
public List<List<GameDTO>> generateSeasonMatches() {
    List<List<Pair>> seasonMatches = gameService.generateSeasonMatches();
    List<List<GameDTO>> seasonMatchesDTO = new ArrayList<>();

    for (List<Pair> rounds : seasonMatches) {
        List<GameDTO> roundsDTO = new ArrayList<>();
        for (Pair match : rounds) {
            GameDTO game = new GameDTO();
            game.setHomeTeam(beanMappingService.mapTo((Team) match.getKey(), TeamDTO.class));
            game.setGuestTeam(beanMappingService.mapTo((Team) match.getValue(), TeamDTO.class));
            roundsDTO.add(game);/*  w  w  w . j a  va 2s. co  m*/
        }
        seasonMatchesDTO.add(roundsDTO);
    }

    return seasonMatchesDTO;
}

From source file:com.walmart.gatling.commons.ScriptExecutor.java

private Object runJob(Object message) {
    Master.Job job = (Master.Job) message;
    TaskEvent taskEvent = (TaskEvent) job.taskEvent;

    CommandLine cmdLine = new CommandLine(agentConfig.getJob().getCommand());
    log.info("Verified Script worker received task: {}", message);
    Map<String, Object> map = new HashMap<>();

    if (StringUtils.isNotEmpty(agentConfig.getJob().getMainClass()))
        cmdLine.addArgument(agentConfig.getJob().getCpOrJar());

    map.put("path", new File(agentConfig.getJob().getJobArtifact(taskEvent.getJobName())));
    cmdLine.addArgument("${path}");

    if (!StringUtils.isEmpty(agentConfig.getJob().getMainClass())) {
        cmdLine.addArgument(agentConfig.getJob().getMainClass());
    }// ww  w . j a  va2  s  .  com
    //parameters come from the task event
    for (Pair<String, String> pair : taskEvent.getParameters()) {
        cmdLine.addArgument(pair.getValue());
    }
    cmdLine.addArgument("-rf").addArgument(agentConfig.getJob().getResultPath(job.roleId, job.jobId));

    cmdLine.setSubstitutionMap(map);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValues(agentConfig.getJob().getExitValues());
    ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
    executor.setWatchdog(watchdog);
    executor.setWorkingDirectory(new File(agentConfig.getJob().getPath()));
    FileOutputStream outFile = null;
    FileOutputStream errorFile = null;
    String outPath = "", errPath = "";
    try {
        outPath = agentConfig.getJob().getOutPath(taskEvent.getJobName(), job.jobId);
        errPath = agentConfig.getJob().getErrorPath(taskEvent.getJobName(), job.jobId);
        //create the std and err files
        outFile = FileUtils.openOutputStream(new File(outPath));
        errorFile = FileUtils.openOutputStream(new File(errPath));

        PumpStreamHandler psh = new PumpStreamHandler(new ExecLogHandler(outFile),
                new ExecLogHandler(errorFile));
        executor.setStreamHandler(psh);
        log.info("command: {}", cmdLine);
        int exitResult = executor.execute(cmdLine);
        //executor.getWatchdog().destroyProcess().
        Worker.Result result = new Worker.Result(exitResult, agentConfig.getUrl(errPath),
                agentConfig.getUrl(outPath), null, job);
        log.info("Exit code: {}", exitResult);
        if (executor.isFailure(exitResult) || exitResult == 1) {
            log.info("Script Executor Failed, job: " + job.jobId);
            //getSender().tell(new Worker.WorkFailed(result), getSelf());
            return new Worker.WorkFailed(result);
        } else {
            result = new Worker.Result(exitResult, agentConfig.getUrl(errPath), agentConfig.getUrl(outPath),
                    agentConfig.getUrl(getMetricsPath(job)), job);
            log.info("Script Executor Completed, job: " + result);
            //getSender().tell(new Worker.WorkComplete(result), getSelf());
            return new Worker.WorkComplete(result);
        }

    } catch (IOException e) {
        log.error(e.toString());
        Worker.Result result = new Worker.Result(-1, agentConfig.getUrl(errPath), agentConfig.getUrl(outPath),
                null, job);
        log.info("Executor Encountered run time exception, result: " + result.toString());
        //getSender().tell(new Worker.WorkFailed(result), getSelf());
        return new Worker.WorkFailed(result);
    } finally {
        IOUtils.closeQuietly(outFile);
        IOUtils.closeQuietly(errorFile);
    }
}

From source file:org.fineract.module.stellar.horizonadapter.HorizonServerUtilities.java

@Autowired
HorizonServerUtilities(@Qualifier("stellarBridgeLogger") final Logger logger) {
    this.logger = logger;

    int STELLAR_TRUSTLINE_BALANCE_REQUIREMENT = 10;
    int initialBalance = Math.max(this.initialBalance,
            STELLAR_MINIMUM_BALANCE + STELLAR_TRUSTLINE_BALANCE_REQUIREMENT);
    if (initialBalance != this.initialBalance) {
        logger.info("Initial balance cannot be lower than 30.  Configured value is being ignored: %i",
                this.initialBalance);
    }/*  w w w.  j  a  v a  2s .com*/
    this.initialBalance = initialBalance;
    accounts = CacheBuilder.newBuilder().build(new CacheLoader<String, Account>() {
        public Account load(final String accountId) throws InvalidConfigurationException {
            final KeyPair accountKeyPair = KeyPair.fromAccountId(accountId);
            final StellarAccountHelpers accountHelper = getAccount(accountKeyPair);
            final Long sequenceNumber = accountHelper.get().getSequenceNumber();
            return new Account(accountKeyPair, sequenceNumber);
        }
    });

    offers = CacheBuilder.newBuilder()
            .build(new CacheLoader<Pair<String, StellarAccountId>, Map<VaultOffer, Long>>() {
                @Override
                public Map<VaultOffer, Long> load(final Pair<String, StellarAccountId> accountIdVaultId) {
                    return VaultOffer.getVaultOffers(server, accountIdVaultId.getKey(),
                            accountIdVaultId.getValue());
                }
            });
}

From source file:ai.grakn.engine.tasks.manager.StandaloneTaskManager.java

public TaskManager stopTask(TaskId id, String requesterName) {
    stateUpdateLock.lock();//w  ww  .  j  a v  a 2s  .c om

    try {
        TaskState state = stateStorage.getState(id);
        if (state == null) {
            return this;
        }

        Pair<ScheduledFuture<?>, BackgroundTask> pair = instantiatedTasks.get(id);
        synchronized (pair) {
            if (state.status() == SCHEDULED
                    || (state.status() == COMPLETED && state.schedule().isRecurring())) {
                LOG.info("Stopping a currently scheduled task " + id);
                pair.getKey().cancel(true);
                state.markStopped();
            } else if (state.status() == RUNNING) {
                LOG.info("Stopping running task " + id);

                BackgroundTask task = pair.getValue();
                if (task != null) {
                    task.stop();
                }

                state.markStopped();
            } else {
                LOG.warn("Task not running - " + id);
            }

            stateStorage.updateState(state);
        }
    } finally {
        stateUpdateLock.unlock();
    }

    return this;
}

From source file:ai.grakn.engine.backgroundtasks.InMemoryTaskManager.java

public TaskManager stopTask(String id, String requesterName) {
    stateUpdateLock.lock();/*from   w w w.j av  a 2  s. c  om*/

    TaskState state = stateStorage.getState(id);
    if (state == null)
        return this;

    Pair<ScheduledFuture<?>, BackgroundTask> pair = instantiatedTasks.get(id);
    String name = this.getClass().getName();

    synchronized (pair) {
        if (state.status() == SCHEDULED || (state.status() == COMPLETED && state.isRecurring())) {
            LOG.info("Stopping a currently scheduled task " + id);
            pair.getKey().cancel(true);
            stateStorage.updateState(id, STOPPED, name, null, null, null, null);
        } else if (state.status() == RUNNING) {
            LOG.info("Stopping running task " + id);

            BackgroundTask task = pair.getValue();
            if (task != null) {
                task.stop();
            }

            stateStorage.updateState(id, STOPPED, name, null, null, null, null);
        } else {
            LOG.warn("Task not running - " + id);
        }
    }
    stateUpdateLock.unlock();

    return this;
}

From source file:DatasetCreation.DatasetCSVBuilder.java

/**
 * Return CSV string which represent the element features vector
 *
 * @param element the element to extract the features from
 * @param featureExtractor a Feature Extractor object
 * @param selectedFeatures the top selected features to build the dataset
 * with/*from  ww  w .  ja v a2s .c  om*/
 * @param classification the classification of given element dataset
 * @param addElementIDColumn add prefix column identifying the record
 * @param addClassificationColumn add suffix column identifying the class of
 * the record
 * @return CSV string which represent the element features vector
 */
public StringBuilder GetFeaturesVectorCSV(T element, IFeatureExtractor<T> featureExtractor,
        ArrayList<Pair<String, Integer>> selectedFeatures, int totalElementsNum,
        FeatureRepresentation featureRepresentation, Classification classification, boolean addElementIDColumn,
        boolean addClassificationColumn) {
    Map<String, Integer> elementFeaturesFrequencies = featureExtractor
            .ExtractFeaturesFrequencyFromSingleElement(element);

    if (elementFeaturesFrequencies.size() > 0) {
        StringBuilder featuresVectorCSV = new StringBuilder();

        if (addElementIDColumn) {
            featuresVectorCSV.append(element.toString()).append(",");
        }

        int mostCommonFeatureFrequencyInElement = GetMostCommonSelectedFeatureFrequencyInElement(
                elementFeaturesFrequencies, selectedFeatures);

        String selectedFeature;
        int featureFrequencyInElement;
        int numOfElementsContainTheFeature;
        double TFIDF;
        String cellValue = "";
        for (Pair<String, Integer> selectedFeaturePair : selectedFeatures) {
            selectedFeature = selectedFeaturePair.getKey();
            switch (featureRepresentation) {
            case Binary:
                if (elementFeaturesFrequencies.containsKey(selectedFeature)) {
                    cellValue = 1 + "";
                } else {
                    cellValue = 0 + "";
                }
                break;
            case TFIDF:
                numOfElementsContainTheFeature = selectedFeaturePair.getValue();
                featureFrequencyInElement = (elementFeaturesFrequencies.containsKey(selectedFeature))
                        ? elementFeaturesFrequencies.get(selectedFeature)
                        : 0;
                TFIDF = MathCalc.GetTFIDF(featureFrequencyInElement, mostCommonFeatureFrequencyInElement,
                        totalElementsNum, numOfElementsContainTheFeature);
                TFIDF = MathCalc.Round(TFIDF, 3);
                cellValue = TFIDF + "";
                break;
            }
            featuresVectorCSV.append(cellValue).append(",");
        }
        if (addClassificationColumn) {
            featuresVectorCSV.append(classification.toString());
        } else {
            featuresVectorCSV.deleteCharAt(featuresVectorCSV.length() - 1);
        }
        return featuresVectorCSV;
    } else {
        return null;
    }
}

From source file:com.sri.tasklearning.ui.core.term.ExerciseStepParameter.java

public void setCurrentSelection(Pair<Integer, Integer> currentSelection) {

    ValueConstraint ovc = vc;/*from   w  ww.j  av a  2s.c o  m*/
    vc = new ValueConstraint();
    vc.setParameter(this.getParameter().getId());

    if (currentSelection.getKey().equals(currentSelection.getValue())) {

        Value val = new Value(currentSelection.getKey().toString(), "integer");
        vc.getValues().add(val);

    } else {

        Value minVal = new Value(currentSelection.getKey().toString(), "integer");
        Value maxVal = new Value(currentSelection.getValue().toString(), "integer");

        vc.setMinValue(minVal);
        vc.setMaxValue(maxVal);
    }

    // also kill the type constraint, as a range is given!
    tc = null;
}

From source file:com.sri.tasklearning.ui.core.term.ExerciseStepParameter.java

public void setCurrentSelection(Pair<String, String> currentSelection, String type) {

    // used for min / max range intervals 

    ValueConstraint ovc = vc;/*from  w  ww  .j  av a  2s . c o m*/
    vc = new ValueConstraint();
    vc.setParameter(this.getParameter().getId());

    if (currentSelection.getKey().equals(currentSelection.getValue())) {

        Value val = new Value("\"" + currentSelection.getKey() + "\"", type);
        vc.getValues().add(val);

    } else {

        Value minVal = new Value("\"" + currentSelection.getKey() + "\"", type);
        Value maxVal = new Value("\"" + currentSelection.getValue() + "\"", type);

        vc.setMinValue(minVal);
        vc.setMaxValue(maxVal);
    }

    // also kill the type constraint, as a range is given!
    tc = null;
}