在我的应用程序中,我有两个arraylist,两个arraylist是多个对象,这里一个arraylist是领域结果,另一个是包含多个对象的简单类arraylist。 现在,我尝试用另一个数组列表的内容过滤掉领域数组列表“ item”,例如:如果我的数组列表“ A”的对象“名称”包含“ 123”,则数组列表“ B”中所有具有“ 123”的元素被删除,但我真的很困惑如何执行此操作,这是我的完整代码:
这是我尝试通过领域查询获取结果的方式,但是我没有运气:
var item=realm.where(Devicesdatabase::class.java).notEqualTo("devicename",hosts.get(0).hostname).findAll()
//项目是我要过滤的arraylist
// hosts arrylist我想将此arraylist的值进行比较以过滤和删除与主机数据匹配的过滤器数据
for(i in hosts!!.indices )
{
var nm = hosts!!.get(i).hostname
var mac = hosts!!.get(i).hardwareAddress
var typ = hosts!!.get(i).deviceType
}
领域数据库类:
@RealmClass
open class Devicesdatabase : RealmModel{
@PrimaryKey
var id:Int?=null
var wifi:String?=null
var devicename: String? = null
var macAddress: String? = null
var status:Boolean = false
var type:String?=null
}
包含主机arraylist的Hostbean类的对象:
public class HostBean implements Parcelable {
public static final String EXTRA = ActivityMain.Companion.getPKG() + ".extra";
public static final String EXTRA_POSITION = ActivityMain.Companion.getPKG() + ".extra_position";
public static final String EXTRA_HOST = ActivityMain.Companion.getPKG() + ".extra_host";
public static final String EXTRA_TIMEOUT = ActivityMain.Companion.getPKG() + ".network.extra_timeout";
public static final String EXTRA_HOSTNAME = ActivityMain.Companion.getPKG() + ".extra_hostname";
public static final String EXTRA_BANNERS = ActivityMain.Companion.getPKG() + ".extra_banners";
public static final String EXTRA_PORTSO = ActivityMain.Companion.getPKG() + ".extra_ports_o";
public static final String EXTRA_PORTSC = ActivityMain.Companion.getPKG() + ".extra_ports_c";
public static final String EXTRA_SERVICES = ActivityMain.Companion.getPKG() + ".extra_services";
public static final int TYPE_GATEWAY = 0;
public static final int TYPE_COMPUTER = 1;
public int deviceType = TYPE_COMPUTER;
public int isAlive = 1;
public int position = 0;
public int responseTime = 0; // ms
public String ipAddress = null;
public String hostname = null;
public String hostsection = null;
public String hardwareAddress = NetInfo.NOMAC;
public String nicVendor = "Unknown";
public String os = "Unknown";
public HashMap<Integer, String> services = null;
public HashMap<Integer, String> banners = null;
public ArrayList<Integer> portsOpen = null;
public ArrayList<Integer> portsClosed = null;
public HostBean() {
// New object
}
public HostBean(Parcel in) {
// Object from parcel
readFromParcel(in);
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(deviceType);
dest.writeInt(isAlive);
dest.writeString(ipAddress);
dest.writeString(hostname);
dest.writeString( hostsection );
dest.writeString(hardwareAddress);
dest.writeString(nicVendor);
dest.writeString(os);
dest.writeInt(responseTime);
dest.writeInt(position);
dest.writeMap(services);
dest.writeMap(banners);
dest.writeList(portsOpen);
dest.writeList(portsClosed);
}
private void readFromParcel(Parcel in) {
deviceType = in.readInt();
isAlive = in.readInt();
ipAddress = in.readString();
hostname = in.readString();
hardwareAddress = in.readString();
nicVendor = in.readString();
os = in.readString();
hostsection=in.readString();
responseTime = in.readInt();
position = in.readInt();
services = in.readHashMap(null);
banners = in.readHashMap(null);
portsOpen = in.readArrayList(Integer.class.getClassLoader());
portsClosed = in.readArrayList(Integer.class.getClassLoader());
}
@SuppressWarnings("unchecked")
public static final Creator CREATOR = new Creator() {
public HostBean createFromParcel(Parcel in) {
return new HostBean(in);
}
public HostBean[] newArray(int size) {
return new HostBean[size];
}
};
}