我有一个类的列表结构;假设GeomFit <- ggproto("GeomFit", GeomBar,
required_aes = c("x", "y"),
setup_data = function(self, data, params) {
data <- ggproto_parent(GeomBar, self)$setup_data(data, params)
## here's the hack: add a field which is not needed in this geom,
## but which is used by Facet*$train_scales which
## eventually sets up the scales
data$ymax_final <- 2 * data$y
data
},
draw_panel = function(self, data, panel_scales, coord, width = NULL) {
bars <- ggproto_parent(GeomBar, self)$draw_panel(data,
panel_scales,
coord)
coords <- coord$transform(data, panel_scales)
tg <- textGrob("test", coords$x, coords$y * 2 - coords$ymin)
grobTree(bars, tg)
}
)
。
List<Client> myList;
具有Client
和name
之类的字段。
如果我想检查列表中是否包含与之相关的类,该如何检查?因为我正在尝试使用passwd
,但似乎无法正常工作。
myList.contains(new Client(name,surname))
我应该检查该类的所有变量是否等于我的变量,还是可以以某种方式检查它?
答案 0 :(得分:2)
那是contain(Object t)内部的JDK ArrayList实现
public int indexOf(Object o) {
if (o == null) {
for (int i = 0; i < size; i++)
if (elementData[i]==null)
return i;
} else {
for (int i = 0; i < size; i++)
if (o.equals(elementData[i]))
return i;
}
return -1;
}
因此,这取决于对象的equal()方法。
答案 1 :(得分:0)
如@dirch所建议,它取决于equals()方法。默认情况下,Object.equals()仅比较对象引用。如果要覆盖此行为,则可能要覆盖FirstDup类中的equals()方法,如下所示
public boolean equals (Object dup) {
return this.name.equals(((DBClient)dup).getName()) && this.surName.equals(((DBClient)dup).getSurName());
}