コード例 #1
0
 @Override
 public void delete(ToolRequest req) throws Exception {
   for (ToolRequest tr : this.requests) {
     if (tr.getKey().equals(req.getKey())) {
       this.requests.remove(tr);
       break;
     }
   }
 }
コード例 #2
0
  @Override
  public List<ToolRequest> select(ToolRequest req, String selectType) throws Exception {
    List<ToolRequest> requests = new ArrayList<>();

    switch (selectType) {
      case "clientRequest":
        for (ToolRequest tr : this.requests) {
          if (tr.getClientRequest().getKey().equals(req.getClientRequest().getKey())) {
            requests.add(tr);
          }
        }
        break;
      case "key":
        for (ToolRequest tr : this.requests) {
          if (tr.getKey().equals(req.getKey())) {
            requests.add(tr);
          }
        }
        break;
      case "tool":
        for (ToolRequest tr : this.requests) {
          if (tr.getTool().getKey().equals(req.getTool().getKey())) {
            requests.add(tr);
          }
        }
        break;
      default:
        throw new InvalidParameterException("Select type isn't valid");
    }

    if (requests.isEmpty()) {
      throw new InvalidParameterException("No one tool request matched");
    } else {
      return requests;
    }
  }