List of usage examples for javafx.util Pair getKey
public K getKey()
From source file:com.flipkart.flux.impl.task.TaskExecutor.java
/** * The HystrixCommand run method. Executes the Task and returns the result or throws an exception in case of a {@link FluxError} * @see com.netflix.hystrix.HystrixCommand#run() *//*from w ww .ja v a 2s. com*/ protected Event run() throws Exception { Pair<Object, FluxError> result = this.task.execute(events); if (result.getValue() != null) { throw result.getValue(); } final Object returnObject = result.getKey(); if (returnObject != null) { return new Event(outputeEventName, returnObject.getClass().getCanonicalName(), Event.EventStatus.triggered, stateMachineId, objectMapper.writeValueAsString(returnObject), MANAGED_RUNTIME); } return null; }
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 a2s . c o m*/ 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: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 w ww . ja va 2s. 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:ai.grakn.engine.backgroundtasks.InMemoryTaskManager.java
public TaskManager stopTask(String id, String requesterName) { stateUpdateLock.lock();/* w w w . j ava 2 s .c o m*/ 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:ai.grakn.engine.tasks.manager.StandaloneTaskManager.java
public TaskManager stopTask(TaskId id, String requesterName) { stateUpdateLock.lock();/*from w ww.j a v a 2 s . 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: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); }//from w w w . j a v a 2 s. co m 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:com.sri.tasklearning.ui.core.term.ExerciseStepParameter.java
public void setCurrentSelection(Pair<Integer, Integer> currentSelection) { ValueConstraint ovc = vc;/*w ww . ja v a 2 s .com*/ 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;// ww w . j av a 2s .co 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; }