Java Code Examples for javafx.util.Pair#getValue()

The following examples show how to use javafx.util.Pair#getValue() . 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: ChartPlugin.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: InventoryEstimateService.java    From blue-marlin with Apache License 2.0 6 votes vote down vote up
/**
 * This service returns available inventory for a specific targeting channel in a period of time.
 * <p>
 * THIS SERVICE DOES NOT CONSIDER REGION RATIOS. Refer to ERD for details.
 *
 * @param targetingChannel
 * @param ranges
 * @param price
 * @return
 * @throws JSONException
 * @throws ESConnectionException
 * @throws IOException
 */
public InventoryResult aggregateInventory(TargetingChannel targetingChannel, List<Range> ranges, double price) throws JSONException, ESConnectionException, IOException, ExecutionException, InterruptedException
{
    InventoryResult result = new InventoryResult();
    Pair<Impression, Long> inventoryValue = aggregateInventory(targetingChannel, ranges);
    long value = inventoryValue.getKey().countImpressions(price, targetingChannel.getPm());
    long booked = inventoryValue.getValue();
    value -= booked;
    if (value < 0)
    {
        LOGGER.info("Estimate impressions < 0");
        value = 0;
    }
    result.setAvailCount(value);
    LOGGER.info("inventory estimate:{}", value);
    return result;
}
 
Example 3
Source File: InventoryEstimateService.java    From blue-marlin with Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source File: InventoryEstimateService.java    From blue-marlin with Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source File: Solution2.java    From code with Apache License 2.0 6 votes vote down vote up
/**
 * 题目地址: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 6
Source File: Solution2.java    From code with Apache License 2.0 6 votes vote down vote up
/**
 * 题目地址:https://leetcode-cn.com/problems/binary-tree-paths/
 * -------------------------------------------------------------------
 * 思考:
 * -------------------------------------------------------------------
 * 思路:先序遍历-迭代
 * -------------------------------------------------------------------
 * 时间复杂度:
 * 空间复杂度:
 */
public List<String> binaryTreePaths(TreeNode root) {
    List<String> result = new ArrayList<>();
    if (root == null) {
        return result;
    }
    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));
        }
    }
    return result;
}
 
Example 7
Source File: DataPointTooltip.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
private 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 8
Source File: LeetCode111.java    From Project with Apache License 2.0 5 votes vote down vote up
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 9
Source File: TreeUtils.java    From code with Apache License 2.0 5 votes vote down vote up
/**
 * 二叉树根节点至叶子节点的最小高度
 *
 * @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 10
Source File: Solution2.java    From code with Apache License 2.0 5 votes vote down vote up
/**
 * 题目地址: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 11
Source File: Solution5.java    From code with Apache License 2.0 5 votes vote down vote up
/**
 * 题目地址: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 12
Source File: ChartPlugin.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: AddCustomBlazeAction.java    From constellation with Apache License 2.0 5 votes vote down vote up
@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 14
Source File: TreeUtil.java    From code with Apache License 2.0 5 votes vote down vote up
/**
 * 二叉树根节点至叶子节点的最小高度
 *
 * @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 15
Source File: SystemFunctionUtil.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
/**
 * @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 16
Source File: SystemFunctionUtil.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
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 17
Source File: SmartTextFieldListCell.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public final void updateItem(T item, boolean empty) {
    super.updateItem(item, empty);

    if (isEmpty() || item == null) {
        setGraphic(null);
        textField = null;
        if (subscriber != null) {
            subscriber.unsubscribe();
            subscriber = Subscription.EMPTY;
        }
    } else {
        if (isEditing()) {
            if (textField != null) {
                textField.setText(extractEditable(item).getValue());
            } else {
                textField = getEditingGraphic(item);
            }
            setGraphic(textField);
        } else {
            textField = null;
            Pair<Node, Subscription> nodeAndSub = getNonEditingGraphic(item);

            setGraphic(nodeAndSub.getKey());
            if (subscriber != null) {
                subscriber.unsubscribe();
            }
            subscriber = nodeAndSub.getValue();
        }
    }
}
 
Example 18
Source File: AddBlazeAction.java    From constellation with Apache License 2.0 5 votes vote down vote up
@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 19
Source File: PropertyMapView.java    From pmd-designer with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected Var<String> extractEditable(Pair<PropertyDescriptorSpec, Var<String>> item) {
    return item.getValue();
}
 
Example 20
Source File: ConstellationHttpProxySelector.java    From constellation with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}