java中columnindex什么意思_Java GridPane.getColumnIndex方法代码示例

这段Java代码展示了如何在GridPane中检查一个节点是否与指定列索引(col)和行索引(row)处的其他节点重叠。方法通过遍历GridPane的子节点,利用`GridPane.getColumnIndex(child)`获取列索引,判断是否有碰撞。若节点满足条件,则会继续检查是否重叠。
摘要由CSDN通过智能技术生成

import javafx.scene.layout.GridPane; //导入方法依赖的package包/类

/**

* Checks if a tile with the given width and height would overlap a pre-existing tile at the point {@code (col, row)},

* ignoring some nodes when calculating collisions. Note that this method does not perform bounds checking;

* use {@link #isOpen(int, int, int, int, Predicate) isOpen} to check if a widget can be placed at that point.

*

* @param col the column index of the point to check

* @param row the row index of the point to check

* @param tileWidth the width of the tile

* @param tileHeight the height of the tile

* @param ignore a predicate to use to ignore nodes when calculating collisions

*/

public boolean isOverlapping(int col, int row, int tileWidth, int tileHeight, Predicate ignore) {

for (Node child : getChildren()) {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以考虑使用以下方式进行优化: 1. 将查询操作放在子线程执行,避免在主线程执行数据库操作导致UI卡顿; 2. 使用缓存机制,将查询结果缓存起来,避免重复查询数据库; 3. 对于查询结果为空的情况,可以直接返回空的JSONArray,无需返回一个空的JSONArray对象; 4. 对于Cursor对象,最好在使用完之后进行关闭操作,以释放资源。 优化后的代码如下所示: @SuppressLint("Range") public void selectApmList(final Long sceneStartTime, final Callback<JSONArray> callback) { new Thread(new Runnable() { @Override public void run() { JSONArray apmJsonArray = new JSONArray(); String selection = "scene_start_time=?"; String[] selectionArgs = {String.valueOf(sceneStartTime)}; String orderBy = "_id"; Cursor cursor = mRDB.query(TABLE_PERFORMANCE, null, selection, selectionArgs, null, null, orderBy, null); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { int tsIndex = cursor.getColumnIndex("ts"); int pssIndex = cursor.getColumnIndex("pss"); int cpuIndex = cursor.getColumnIndex("cpu"); int currentIndex = cursor.getColumnIndex("current"); int voltageIndex = cursor.getColumnIndex("voltage"); int batteryPercentIndex = cursor.getColumnIndex("battery_percent"); do { JSONObject apmEntity = new JSONObject(); JsonUtils.put(apmEntity, ConfigConst.send_apmTsCollect, cursor.getLong(tsIndex)); JsonUtils.put(apmEntity, ConfigConst.send_apmPss, cursor.getLong(pssIndex)); JsonUtils.put(apmEntity, ConfigConst.send_apmCpu, cursor.getLong(cpuIndex)); JsonUtils.put(apmEntity, ConfigConst.send_apmCurrent, cursor.getLong(currentIndex)); JsonUtils.put(apmEntity, ConfigConst.send_apmVoltage, cursor.getLong(voltageIndex)); JsonUtils.put(apmEntity, ConfigConst.send_apmBatteryPercent, cursor.getLong(batteryPercentIndex)); apmJsonArray.put(apmEntity); } while (cursor.moveToNext()); callback.onSuccess(apmJsonArray); } else { callback.onSuccess(null); } if (cursor != null) { cursor.close(); } } }).start(); } 其,Callback是自定义的回调接口,用于在查询完成后返回结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值