diff options
| author | Kevin Sawicki | 2011-05-02 23:32:28 +0000 |
|---|---|---|
| committer | Chris Aniszczyk | 2011-05-03 14:06:07 +0000 |
| commit | 6180fab51874473a6dc4f423f1d278d528dd5978 (patch) | |
| tree | f734060949b2e7fc4f809ab6ee7a385ca060389f | |
| parent | 6689d9bb91121b00bfdb35032d65d66e5a24a554 (diff) | |
| download | egit-github-6180fab51874473a6dc4f423f1d278d528dd5978.tar.gz egit-github-6180fab51874473a6dc4f423f1d278d528dd5978.tar.xz egit-github-6180fab51874473a6dc4f423f1d278d528dd5978.zip | |
Add request class and interfaces for pagination support
These classes will be used to support task queries that
span multiple pages.
Change-Id: I8c5421d6983d0c732f9e218cb7f8769525acd60d
Signed-off-by: Kevin Sawicki <kevin@github.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
4 files changed, 230 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRequest.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRequest.java new file mode 100644 index 00000000..bd62411c --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/GitHubRequest.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylyn.github.internal; + +import java.lang.reflect.Type; +import java.util.Map; + +/** + * GitHub API request class. + */ +public class GitHubRequest { + + private String uri; + + private Map<String, String> params; + + private Type type; + + private int page = 1; + + /** + * @return uri + */ + public String getUri() { + return this.uri; + } + + /** + * @param uri + * @return this request + */ + public GitHubRequest setUri(StringBuilder uri) { + return setUri(uri != null ? uri.toString() : null); + } + + /** + * @param uri + * @return this request + */ + public GitHubRequest setUri(String uri) { + this.uri = uri; + return this; + } + + /** + * @return params + */ + public Map<String, String> getParams() { + return this.params; + } + + /** + * @param params + * @return this request + */ + public GitHubRequest setParams(Map<String, String> params) { + this.params = params; + return this; + } + + /** + * @return type + */ + public Type getType() { + return this.type; + } + + /** + * @param type + * @return this request + */ + public GitHubRequest setType(Type type) { + this.type = type; + return this; + } + + /** + * @return page + */ + public int getPage() { + return this.page; + } + + /** + * @param page + * @return this request + */ + public GitHubRequest setPage(int page) { + this.page = page; + return this; + } + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java index 62a1a7a1..99cc89ec 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java @@ -125,4 +125,49 @@ public interface IGitHubConstants { */ String PARAM_PER_PAGE = "per_page"; //$NON-NLS-1$ + /** + * PARAM_PAGE + */ + String PARAM_PAGE = "page"; //$NON-NLS-1$ + + /** + * HEADER_LINK + */ + String HEADER_LINK = "Link"; //$NON-NLS-1$ + + /** + * HEADER_NEXT + */ + String HEADER_NEXT = "X-Next"; //$NON-NLS-1$ + + /** + * HEADER_LAST + */ + String HEADER_LAST = "X-Last"; //$NON-NLS-1$ + + /** + * META_REL + */ + String META_REL = "rel"; //$NON-NLS-1$ + + /** + * META_LAST + */ + String META_LAST = "last"; //$NON-NLS-1$ + + /** + * META_NEXT + */ + String META_NEXT = "next"; //$NON-NLS-1$ + + /** + * META_FIRST + */ + String META_FIRST = "first"; //$NON-NLS-1$ + + /** + * META_PREV + */ + String META_PREV = "prev"; //$NON-NLS-1$ + } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceCollector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceCollector.java new file mode 100644 index 00000000..57028d59 --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IResourceCollector.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylyn.github.internal; + +import java.util.Collection; + +/** + * Interface for accepting collections of resources page by page. + * + * @param <V> + */ +public interface IResourceCollector<V> { + + /** + * Accept page response. + * + * @param page + * @param response + * @return true to continue collecting, false to abort + */ + boolean accept(int page, Collection<V> response); + +} diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/ListResourceCollector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/ListResourceCollector.java new file mode 100644 index 00000000..1772f95b --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/ListResourceCollector.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2011 GitHub Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Kevin Sawicki (GitHub Inc.) - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylyn.github.internal; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +/** + * {@link LinkedList} based resource collector + * + * @param <V> + */ +public class ListResourceCollector<V> implements IResourceCollector<V> { + + private List<V> resources = new LinkedList<V>(); + + /** + * Clear resources from collector + * + * @return this collector + */ + public ListResourceCollector<V> clear() { + this.resources.clear(); + return this; + } + + /** + * Get resources + * + * @return collection of resources + */ + public List<V> getResources() { + return this.resources; + } + + /** + * @see org.eclipse.mylyn.github.internal.IResourceCollector#accept(int, + * java.util.Collection) + */ + public boolean accept(int page, Collection<V> resources) { + return this.resources.addAll(resources); + } + +} |
