// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.extensions.api.changes;

import com.google.gerrit.extensions.restapi.NotImplementedException;
import com.google.gerrit.extensions.restapi.RestApiException;

public interface Changes {
  ChangeApi id(int id) throws RestApiException;
  ChangeApi id(String triplet) throws RestApiException;
  ChangeApi id(String project, String branch, String id)
      throws RestApiException;

  /**
   * A default implementation which allows source compatibility
   * when adding new methods to the interface.
   **/
  public class NotImplemented implements Changes {
    @Override
    public ChangeApi id(int id) throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public ChangeApi id(String triplet) throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public ChangeApi id(String project, String branch, String id) throws RestApiException {
      throw new NotImplementedException();
    }
  }
}

@@ -653,16 +653,133 @@
 anges;%0A%0A
+import com.google.gerrit.extensions.common.ChangeInfo;%0Aimport com.google.gerrit.extensions.common.ListChangesOption;%0A
 import c
@@ -902,16 +902,91 @@
 ption;%0A%0A
+import java.util.Arrays;%0Aimport java.util.EnumSet;%0Aimport java.util.List;%0A%0A
 public i
@@ -1197,16 +1197,1526 @@
 ption;%0A%0A
+  /**%0A   * Shorthand for %7B@link #query(QueryParameter)%7D without any conditions (i.e. lists all changes).%0A   */%0A  List%3CChangeInfo%3E query() throws RestApiException;%0A  List%3CChangeInfo%3E query(QueryParameter queryParameter) throws RestApiException;%0A%0A  public class QueryParameter %7B%0A    private String query;%0A    private int limit;%0A    private int start;%0A    private EnumSet%3CListChangesOption%3E options = EnumSet.noneOf(ListChangesOption.class);%0A%0A    public QueryParameter() %7B%7D%0A%0A    public QueryParameter(String query) %7B%0A      this.query = query;%0A    %7D%0A%0A    public QueryParameter withQuery(String query) %7B%0A      this.query = query;%0A      return this;%0A    %7D%0A%0A    public QueryParameter withLimit(int limit) %7B%0A      this.limit = limit;%0A      return this;%0A    %7D%0A%0A    public QueryParameter withStart(int start) %7B%0A      this.start = start;%0A      return this;%0A    %7D%0A%0A    public QueryParameter withOption(ListChangesOption options) %7B%0A      this.options.add(options);%0A      return this;%0A    %7D%0A    public QueryParameter withOptions(ListChangesOption... options) %7B%0A      this.options.addAll(Arrays.asList(options));%0A      return this;%0A    %7D%0A%0A    public QueryParameter withOptions(EnumSet%3CListChangesOption%3E options) %7B%0A      this.options = options;%0A      return this;%0A    %7D%0A%0A    public String getQuery() %7B%0A      return query;%0A    %7D%0A%0A    public int getLimit() %7B%0A      return limit;%0A    %7D%0A%0A    public int getStart() %7B%0A      return start;%0A    %7D%0A%0A    public EnumSet%3CListChangesOption%3E getOptions() %7B%0A      return options;%0A    %7D%0A  %7D%0A%0A
   /**%0A  
@@ -3284,19 +3284,300 @@
 ion();%0A    %7D
+%0A%0A    @Override%0A    public List%3CChangeInfo%3E query() throws RestApiException %7B%0A      throw new NotImplementedException();%0A    %7D%0A%0A    @Override%0A    public List%3CChangeInfo%3E query(QueryParameter queryParameter) throws RestApiException %7B%0A      throw new NotImplementedException();%0A    %7D
 %0A  %7D%0A%7D%0A

Extend extensions-api Changes with query methods