Java Code Examples for javafx.util.Pair#getKey()
The following examples show how to use
javafx.util.Pair#getKey() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InventoryEstimateService.java From blue-marlin with Apache License 2.0 | 6 votes |
/** * This method returns total inventory (ignoring bookings) that is associated with * one booking-bucket minus a targeting channel. * * @param bookingBucket * @param query * @param day * @param bookingsMap * @return * @throws IOException * @throws JSONException * @throws ESConnectionException */ public Impression getInventoryForBookingBucketMinusQuery(BookingBucket bookingBucket, TargetingChannel query, Day day, Map<String, Booking> bookingsMap) throws IOException, JSONException, ESConnectionException { List<TargetingChannel> Bns = extractTargetingChannelsFromBookingsByBookingIds(bookingsMap, bookingBucket.getAndBookingsIds()); List<TargetingChannel> Bms = extractTargetingChannelsFromBookingsByBookingIds(bookingsMap, bookingBucket.getMinusBookingsIds()); if (CommonUtil.isEmpty(Bns)) { LOGGER.info("Bookings of BB have been removed"); return new Impression(); } Pair<Double, Impression> result = getAverageTBRForBookingBucketMinusQ(day, bookingBucket, Bns, query, bookingsMap.keySet()); double avgTbr = result.getKey(); Impression maxImpression = result.getValue(); Impression impression = getInventoryFor_BNs_Minus_BMs_Minus_q(day, Bns, Bms, query, avgTbr, maxImpression); return impression; }
Example 2
Source File: Solution2.java From code with Apache License 2.0 | 6 votes |
/** * 题目地址:https://leetcode-cn.com/problems/sum-of-left-leaves/ * ------------------------------------------------------------------- * 思考: * ------------------------------------------------------------------- * 思路:将递归改成迭代 * ------------------------------------------------------------------- * 时间复杂度: * 空间复杂度: */ public int sumOfLeftLeaves(TreeNode root) { if (root == null) { return 0; } LinkedList<Pair<TreeNode, Boolean>> stack = new LinkedList<>(); stack.push(new Pair<>(root, false)); int sum = 0; Boolean flag; while (!stack.isEmpty()) { Pair<TreeNode, Boolean> pair = stack.pop(); root = pair.getKey(); flag = pair.getValue(); if (flag && root.left == null && root.right == null) { sum += root.val; } if (root.left != null) { stack.push(new Pair<>(root.left, true)); } if (root.right != null) { stack.push(new Pair<>(root.right, false)); } } return sum; }
Example 3
Source File: ChartPlugin.java From chart-fx with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private <T extends InputEvent> void addEventHandlers(final Node node) { if (node == null) { return; } for (final Pair<EventType<? extends InputEvent>, EventHandler<? extends InputEvent>> pair : mouseEventHandlers) { final EventType<T> type = (EventType<T>) pair.getKey(); final EventHandler<T> handler = (EventHandler<T>) pair.getValue(); node.addEventHandler(type, handler); node.sceneProperty().addListener((ch, o, n) -> { if (o == n) { return; } if (o != null) { o.removeEventHandler(type, handler); } if (n != null) { n.addEventHandler(type, handler); } }); } }
Example 4
Source File: InventoryEstimateService.java From blue-marlin with Apache License 2.0 | 6 votes |
/** * This method returns total inventory (ignoring bookings) that is associated with intersection of * one booking-bucket and a targeting channel. * * @param bookingBucket * @param query * @param day * @param bookingsMap * @return * @throws IOException * @throws JSONException * @throws ESConnectionException */ public Impression getInventoryForBookingBucketCrossQuery(BookingBucket bookingBucket, TargetingChannel query, Day day, Map<String, Booking> bookingsMap) throws IOException, JSONException, ESConnectionException { List<TargetingChannel> Bns = extractTargetingChannelsFromBookingsByBookingIds(bookingsMap, bookingBucket.getAndBookingsIds()); List<TargetingChannel> Bms = extractTargetingChannelsFromBookingsByBookingIds(bookingsMap, bookingBucket.getMinusBookingsIds()); if (CommonUtil.isEmpty(Bns)) { LOGGER.info("Bookings of BB have been removed"); return new Impression(); } Pair<Double, Impression> result = getAverageTBRForBookingBucketMinusQBar(day, bookingBucket, Bns, query, bookingsMap.keySet()); double avgTbr = result.getKey(); Impression maxImpression = result.getValue(); Impression impression = getInventoryFor_BNs_DOT_q_Minus_BMs(day, Bns, query, Bms, avgTbr, maxImpression); return impression; }
Example 5
Source File: StatisticCEPRuleUtil.java From WeEvent with Apache License 2.0 | 5 votes |
public static StatisticWeEvent statisticOrderType(StatisticWeEvent statisticWeEvent, Pair<String, String> type) { if (!("".equals(type.getValue()))) { StatisticRule statisticRule = statisticWeEvent.getStatisticRuleMap().get(type.getValue()); switch (type.getKey()) { case ConstantsHelper.HIT_TIMES: statisticRule.setHitTimes(statisticRule.getHitTimes() + 1); break; case ConstantsHelper.NOT_HIT_TIMES: statisticRule.setNotHitTimes(statisticRule.getNotHitTimes() + 1); break; case ConstantsHelper.WRITE_DB_SUCCESS: case ConstantsHelper.PUBLISH_EVENT_SUCCESS: statisticRule.setDataFlowSuccess(statisticRule.getDataFlowSuccess() + 1); break; case ConstantsHelper.WRITE_DB_FAIL: case ConstantsHelper.PUBLISH_EVENT_FAIL: statisticRule.setDataFlowFail(statisticRule.getDataFlowFail() + 1); break; case ConstantsHelper.LAST_FAIL_REASON: statisticRule.setLastFailReason(statisticRule.getLastFailReason()); break; default: log.info("other type:{}", type); break; } } return statisticWeEvent; }
Example 6
Source File: TreeUtils.java From code with Apache License 2.0 | 5 votes |
/** * 二叉树根节点至叶子节点的最小高度 * * @param root 根节点 * @return int 高度 */ public int minDepth(TreeNode root) { if (root == null) { return 0; } LinkedList<Pair<TreeNode, Integer>> queue = new LinkedList<>(); queue.add(new Pair<>(root, 1)); // 当前深度 int currentDepth = 0; Pair<TreeNode, Integer> pair = null; while (!queue.isEmpty()) { pair = queue.poll(); root = pair.getKey(); currentDepth = pair.getValue(); // 找到层中第一个叶子节点 if (root.left == null && root.right == null) { break; } if (root.left != null) { queue.add(new Pair<>(root.left, currentDepth + 1)); } if (root.right != null) { queue.add(new Pair<>(root.right, currentDepth + 1)); } } return currentDepth; }
Example 7
Source File: Solution2.java From code with Apache License 2.0 | 5 votes |
/** * 题目地址:https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/ * ------------------------------------------------------------------- * 思考:二叉树的所有路径_257 * ------------------------------------------------------------------- * 思路:先序遍历-迭代 * ------------------------------------------------------------------- * 时间复杂度: * 空间复杂度: */ public int sumNumbers(TreeNode root) { if (root == null) { return 0; } List<String> result = new ArrayList<>(); LinkedList<Pair<TreeNode, String>> stack = new LinkedList<>(); stack.push(new Pair<>(root, String.valueOf(root.val))); while (!stack.isEmpty()) { Pair<TreeNode, String> pair = stack.pop(); root = pair.getKey(); String path = pair.getValue(); if (root.left == null && root.right == null) { result.add(path); } if (root.left != null) { stack.push(new Pair<>(root.left, path + root.left.val)); } if (root.right != null) { stack.push(new Pair<>(root.right, path + root.right.val)); } } int sum = 0; for (String s : result) { sum += Integer.parseInt(s); } return sum; }
Example 8
Source File: Solution5.java From code with Apache License 2.0 | 5 votes |
/** * 题目地址:https://leetcode-cn.com/problems/path-sum/ * ------------------------------------------------------------------- * 思考: * ------------------------------------------------------------------- * 思路:先序遍历-迭代; * 在根节点到叶子节点的路径总和=sum即可 * ------------------------------------------------------------------- * 时间复杂度: * 空间复杂度: */ public boolean hasPathSum(TreeNode root, int sum) { if (root == null) { return false; } // 节点 LinkedList<Pair<TreeNode, Integer>> stack = new LinkedList<>(); stack.push(new Pair<>(root, sum)); Pair<TreeNode, Integer> pair; // 暂存当前位置sum还剩下的值 Integer parentSum; while (!stack.isEmpty()) { pair = stack.pop(); root = pair.getKey(); parentSum = pair.getValue(); if (root.left == null && root.right == null) { if (parentSum - root.val == 0) { return true; } } if (root.left != null) { stack.push(new Pair<>(root.left, parentSum - root.val)); } if (root.right != null) { stack.push(new Pair<>(root.right, parentSum - root.val)); } } return false; }
Example 9
Source File: EditDataSet.java From chart-fx with Apache License 2.0 | 5 votes |
protected List<DataPoint> findNeighborPoints(final XYChart chart, final double searchedX) { final List<DataPoint> points = new LinkedList<>(); for (final DataSet dataSet : chart.getAllDatasets()) { final Pair<DataPoint, DataPoint> neighborPoints = findNeighborPoints(dataSet, searchedX); if (neighborPoints.getKey() != null) { points.add(neighborPoints.getKey()); } if (neighborPoints.getValue() != null) { points.add(neighborPoints.getValue()); } } return points; }
Example 10
Source File: Solution3.java From code with Apache License 2.0 | 5 votes |
/** * 题目地址:https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/ * ------------------------------------------------------------------- * 思考:从根节点到叶子节点的路径上的节点数量。BFS按照树的层次去迭代, * 第一个访问到的叶子就是最小深度的节点,这样就不要遍历所有的节点了。 * ------------------------------------------------------------------- * 思路:BFS迭代 * ------------------------------------------------------------------- * 时间复杂度:最多访问n/2个节点,O(n) * 空间复杂度:最多队列中保存n/2个节点,O(n) */ public int minDepth(TreeNode root) { if (root == null) { return 0; } LinkedList<Pair<TreeNode, Integer>> queue = new LinkedList<>(); queue.add(new Pair<>(root, 1)); // 当前深度 int currentDepth = 0; Pair<TreeNode, Integer> pair = null; while (!queue.isEmpty()) { pair = queue.poll(); root = pair.getKey(); currentDepth = pair.getValue(); // 找到层中第一个叶子节点 if (root.left == null && root.right == null) { break; } if (root.left != null) { queue.add(new Pair<>(root.left, currentDepth + 1)); } if (root.right != null) { queue.add(new Pair<>(root.right, currentDepth + 1)); } } return currentDepth; }
Example 11
Source File: ChartPlugin.java From chart-fx with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private <T extends InputEvent> void removeEventHandlers(final Node node) { if (node == null) { return; } for (final Pair<EventType<? extends InputEvent>, EventHandler<? extends InputEvent>> pair : mouseEventHandlers) { final EventType<T> type = (EventType<T>) pair.getKey(); final EventHandler<T> handler = (EventHandler<T>) pair.getValue(); node.removeEventHandler(type, handler); if (node.getScene() != null) { node.getScene().removeEventFilter(type, handler); } } }
Example 12
Source File: SystemFunctionUtil.java From WeEvent with Apache License 2.0 | 5 votes |
/** * @param arr enhance function message * @param conditionField original condition details * @param payload payload * @return condition */ public static String replaceCondition(String[][] arr, String conditionField, Map payload) { StringBuilder sb = new StringBuilder(conditionField); int changePosition = 0; for (int i = 0; i < arr.length; i++) { Pair<StringBuilder, Integer> ret = replaceCase(sb, conditionField, payload, arr[i], changePosition); sb = ret.getKey(); changePosition = ret.getValue(); } log.info("sb:{}", sb); return sb.toString(); }
Example 13
Source File: SystemFunctionUtil.java From WeEvent with Apache License 2.0 | 5 votes |
public static Pair<StringBuilder, Integer> replaceCase(StringBuilder sb, String conditionField, Map payload, String[] arr, int changePosition) { String type = arr[2]; Pair<StringBuilder, Integer> ret; int changePositionAfter = 0; StringBuilder sbTransform = null; switch (type) { case "now": case "currentDate": case "currentTime": ret = timeOperator(sb, conditionField, arr, changePosition); sbTransform = ret.getKey(); changePositionAfter = ret.getValue(); break; case "abs": case "ceil": case "floor": case "round": ret = numberOperator(sb, conditionField, arr, payload, changePosition); sbTransform = ret.getKey(); changePositionAfter = ret.getValue(); break; case "substring": case "concat": case "trim": case "lcase": ret = stringOperator(sb, conditionField, arr, payload, changePosition); sbTransform = ret.getKey(); changePositionAfter = ret.getValue(); break; default: log.info("conditionField:{}", conditionField); break; } return new Pair<>(sbTransform, changePositionAfter); }
Example 14
Source File: LeetCode111.java From Project with Apache License 2.0 | 5 votes |
public int minDepth3(TreeNode root) { // Pair<key value>,表示一对值, List<pair<>> 近似可以理解为 map<> LinkedList<Pair<TreeNode, Integer>> stack = new LinkedList<>(); if (root == null) { return 0; } else { // 根节点的高度设置为 1 stack.add(new Pair(root, 1)); } int minDepth = Integer.MAX_VALUE; while (!stack.isEmpty()) { // 弹出栈顶元素 Pair<TreeNode, Integer> current = stack.pollLast(); root = current.getKey(); int currentDepth = current.getValue(); if ((root.left == null) && (root.right == null)) { minDepth = Math.min(minDepth, currentDepth); } if (root.left != null) { stack.add(new Pair(root.left, currentDepth + 1)); } if (root.right != null) { stack.add(new Pair(root.right, currentDepth + 1)); } } return minDepth; }
Example 15
Source File: LeetCode111.java From Project with Apache License 2.0 | 5 votes |
public int minDepth3(TreeNode root) { // Pair<key value>,表示一对值, List<pair<>> 近似可以理解为 map<> LinkedList<Pair<TreeNode, Integer>> stack = new LinkedList<>(); if (root == null) { return 0; } else { // 根节点的高度设置为 1 stack.add(new Pair(root, 1)); } int minDepth = Integer.MAX_VALUE; while (!stack.isEmpty()) { // 弹出栈顶元素 Pair<TreeNode, Integer> current = stack.pollLast(); root = current.getKey(); int currentDepth = current.getValue(); if ((root.left == null) && (root.right == null)) { minDepth = Math.min(minDepth, currentDepth); } if (root.left != null) { stack.add(new Pair(root.left, currentDepth + 1)); } if (root.right != null) { stack.add(new Pair(root.right, currentDepth + 1)); } } return minDepth; }
Example 16
Source File: QualityControlViewPane.java From constellation with Apache License 2.0 | 5 votes |
/** * Display a dialog containing all Rule objects registered with the Quality * Control View and which matched for a given identifier. * * @param owner The owner Node * @param identifier The identifier of the graph node being displayed. * @param rules The list of rules measured against this graph node. */ private static void showRuleDialog(final Node owner, final String identifier, final List<Pair<Integer, String>> rules) { final ScrollPane sp = new ScrollPane(); sp.setPrefHeight(512); sp.setPrefWidth(512); sp.setFitToWidth(true); sp.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS); sp.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); final VBox vbox = new VBox(); vbox.prefWidthProperty().bind(sp.widthProperty()); vbox.setPadding(Insets.EMPTY); for (final Pair<Integer, String> rule : rules) { final String[] t = rule.getValue().split("§"); final String quality = rule.getKey() == 0 ? Bundle.MSG_NotApplicable() : "" + rule.getKey(); final String title = String.format("%s - %s", quality, t[0]); final Text content = new Text(t[1]); content.wrappingWidthProperty().bind(sp.widthProperty().subtract(16)); // Subtract a random number to avoid the vertical scrollbar. final TitledPane tp = new TitledPane(title, content); tp.prefWidthProperty().bind(vbox.widthProperty()); tp.setExpanded(false); tp.setWrapText(true); vbox.getChildren().add(tp); } sp.setContent(vbox); final Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setHeaderText(String.format(Bundle.MSG_QualtyControlRules(), identifier)); alert.getDialogPane().setContent(sp); alert.setResizable(true); alert.show(); }
Example 17
Source File: AddBlazeAction.java From constellation with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(final ActionEvent e) { final Pair<BitSet, ConstellationColor> selectionResult = BlazeUtilities.getSelection(context.getGraph(), null); final BitSet selectedVertices = selectionResult.getKey(); final ConstellationColor blazeColor = selectionResult.getValue(); if (!selectedVertices.isEmpty()) { PluginExecution.withPlugin(VisualGraphPluginRegistry.ADD_CUSTOM_BLAZE) .withParameter(BlazeUtilities.VERTEX_IDS_PARAMETER_ID, selectedVertices) .withParameter(BlazeUtilities.COLOR_PARAMETER_ID, blazeColor) .executeLater(context.getGraph()); } }
Example 18
Source File: AddCustomBlazeAction.java From constellation with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(final ActionEvent e) { final Pair<BitSet, ConstellationColor> selectionResult = BlazeUtilities.getSelection(context.getGraph(), null); final BitSet selectedVertices = selectionResult.getKey(); ConstellationColor blazeColor = selectionResult.getValue(); if (!selectedVertices.isEmpty()) { final Pair<Boolean, ConstellationColor> colorResult = BlazeUtilities.colorDialog(blazeColor); blazeColor = colorResult.getValue(); PluginExecution.withPlugin(VisualGraphPluginRegistry.ADD_CUSTOM_BLAZE) .withParameter(BlazeUtilities.VERTEX_IDS_PARAMETER_ID, selectedVertices) .withParameter(BlazeUtilities.COLOR_PARAMETER_ID, blazeColor) .executeLater(context.getGraph()); } }
Example 19
Source File: SnippetsContentGenerator.java From ballerina-integrator with Apache License 2.0 | 4 votes |
static void generateSnippetContent(List<Snippet> snippetList) throws IOException { String snippetLine; String snippetBody; String snippetFooter; File sourceFile = Paths.get("vscode","snippets","ei-snippets", "src", "main", "java", "org", "wso2", "integration", "ballerina", "autogen", "SnippetsContent.java").toFile(); try { if (sourceFile.createNewFile()) { log.info("Successfully created ItemResolverConstants.java file"); } } catch (IOException e) { String message = "Error while generating SnippetsContent.java file."; log.error(message, e); } String snippetContentHeder = "package org.wso2.integration.ballerina.autogen;\n\n" + "import org.apache.commons.lang3.tuple.ImmutablePair;\n" + "import org.ballerinalang.langserver.SnippetBlock;\n\n\n" + "public class SnippetsContent {\n\n" + " private SnippetsContent() { \n } \n"; String snippetContent = ""; for (int i = 0; i < snippetList.size(); i++) { StringBuilder stringBuilder = new StringBuilder(); Pair<String, List<String>> pair = getImportText(snippetList.get(i)); String[] namesParts = snippetList.get(i).getName().split(":"); snippetLine = "\n public static SnippetBlock get" + namesParts[1].trim(). replaceAll("_", "") + "() { \n" + pair.getKey(); String generated = snippetList.get(i).getCode().replaceAll("\"", "\\\\\""); snippetBody = "\n \n String snippet =\"" + generated + "\" ;"; snippetFooter = "\n \nreturn new SnippetBlock(ItemResolverConstants." + namesParts[1].trim(). toUpperCase() + ", snippet,ItemResolverConstants.SNIPPET_TYPE," + "SnippetBlock.SnippetType.SNIPPET,"; for (int index = 0; index < pair.getValue().size(); index++) { if (index < pair.getValue().size() - 1) { snippetFooter = snippetFooter + pair.getValue().get(index) + ","; } else { snippetFooter += pair.getValue().get(index); } } snippetFooter += "); \n }"; snippetContent = stringBuilder.append(snippetContent).append(snippetLine).append(snippetBody). append(snippetFooter).append("\n").toString(); } String finalSnippet = snippetContentHeder + snippetContent + "}"; FileWriter writer = new FileWriter(sourceFile); writer.write(finalSnippet); writer.close(); }
Example 20
Source File: ConstellationHttpProxySelector.java From constellation with Apache License 2.0 | 3 votes |
/** * Construct a {@link Proxy} object from the given {@link Pair} containing * an address and port for the proxy. * * @param proxy a {@link Pair} object containing an address and port for the * proxy. * @return a {@link Proxy} object representing the proxy. */ private List<Proxy> makeProxy(final Pair<String, Integer> proxy) { final Proxy proxyObject = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy.getKey(), proxy.getValue())); LOGGER.log(Level.FINER, "Proxy {0}", proxyObject); return Collections.singletonList(proxyObject); }