【发布时间】:2019-03-18 15:25:05
【问题描述】:
我有一个类,这个类构造了 7 个 ArrayList:
public class Fruchtplanungsmodul {
private ArrayList<Crops> fruchtliste1F;
private ArrayList<Crops> fruchtliste2F;
private ArrayList<Crops> fruchtliste3F;
private ArrayList<Crops> fruchtliste4F;
private ArrayList<Crops> fruchtliste5F;
private ArrayList<Crops> fruchtliste6F;
private ArrayList<Crops> fruchtliste7F;
// Constructor
public Fruchtplanungsmodul() {
fruchtliste1F = new ArrayList<>();
fruchtliste2F = new ArrayList<>();
fruchtliste3F = new ArrayList<>();
fruchtliste4F = new ArrayList<>();
fruchtliste5F = new ArrayList<>();
fruchtliste6F = new ArrayList<>();
fruchtliste7F = new ArrayList<>();
}
functions for deleting Objects....
}
我想用 Drools-rules 加载这个列表中的对象。 我确实将相同的 Objecttypes 加载到所有 Arraylist 中。例如,在这条规则中,我将 4 个 Objects Crops 加载到第一个 ArrayList 中。
rule "Körnerlegmunosen: Planung erste Feldrigkeit"
when
//$grund: Grundbedingung(grundbedingung == 1)
$feld: Feldrigkeit(feldrigkeit1 == "Körnerleguminosen")
$m: Fruchtplanungsmodul()
then
Crops erbse = new Crops("Erbse", "Koernerleguminose","BF", "Hafer", "Silomais", "Sommerung", 6);
Crops ackerbohne = new Crops("Ackerbohne" , "Koernerleguminose", "BF", "Silomais", "Wintergerste", "Sommerung", 4);
Crops lupine = new Crops("Lupine", "Koernerleguminose", "BF", "Späte Kartoffel", "Winterroggen", "Sommerung", 4);
Crops sojabohne = new Crops("Sojabohne", "Koernerleguminose", "BF", "Futterrübe", "winterroggen", "Sommerung", 3);
insert(erbse);
insert(ackerbohne);
insert(lupine);
insert(sojabohne);
$m.addFrucht1(erbse);
$m.addFrucht1(ackerbohne);
$m.addFrucht1(lupine);
$m.addFrucht1(sojabohne);
end
在其他规则中,我将不同的 Crops 从 Class Fruchtplanungsmodul() 加载到其他 ArrayLists 中。
我的问题是:有没有办法比较来自不同 ArrayLists 的对象?
例如,ArrayList "fruchtliste2F" 有 4 个 Crops 类型的对象,ArrayList "fruchtliste3F" 也有 4 个 Crops 类型的对象。现在我需要检查两个 ArrayList 中是否有一个具有相同名称的对象。如果这是真的,规则应该从第二个列表中删除该对象。
感谢您的帮助! 菲利普
【问题讨论】:
标签: java arraylist compare drools