小编kuk*_*384的帖子

java interscect,union,join,带谓词的不同列表

您好我有2个包含相同对象的列表.我想通过使用谓词执行任何操作,如intercesct,union,distinct,因为我无法使用equals来进行比较.

例:

class Car{
  public String id;
  public String color;
  public int hashcode(){
    //id field is used for hashcode
  }
  public boolean equals(){
    //id field is used for equals
  }
}
Run Code Online (Sandbox Code Playgroud)

现在我有两个汽车清单.我需要在这个列表中找到重复项,但不能仅通过颜色找到id.

List<Car> carList1 = new ArrayList(){ new Car(1,blue), new Car(2,green)};
List<Car> carList2 = new ArrayList(){ new Car(1,silver), new Car(4,green)};
Run Code Online (Sandbox Code Playgroud)

我需要从carList1找到第二个对象(新车(2,绿色))

列出类似的东西

Collection.intersect(carList1,carList2,comparator).
Run Code Online (Sandbox Code Playgroud)

在C#中我会用它来LINQ.

java union predicate list

7
推荐指数
1
解决办法
3732
查看次数

JUnit在同一对象中使用其他方法的Test方法

您好我正在努力解决简单的问题.

大概的概念:

class Foo(){
  public boolean method1();
  public String method2();
  public String method3();
  public String shortcut(){
    return (method1() == true) ? method2() : method3();
  }
}
Run Code Online (Sandbox Code Playgroud)

我该如何测试快捷方式?

我知道如何模拟使用其他对象的对象和测试方法.样品:

class Car{
  public boolean start(){};
  public boolean stop(){};
  public boolean drive(int km){};
}
class CarAutoPilot(){
  public boolean hasGotExternalDevicesAttached(){
     //Hardware specific func and api calls
     //check if gps is available 
     //check if speaker is on
     //check if display is on 
  }
  public boolean drive(Car car, int km){
    //drive
    boolean found = hasGotExternalDevicesAttached();
    boolean …
Run Code Online (Sandbox Code Playgroud)

java testing tdd junit mocking

5
推荐指数
1
解决办法
3139
查看次数

标签 统计

java ×2

junit ×1

list ×1

mocking ×1

predicate ×1

tdd ×1

testing ×1

union ×1