summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-11 17:00:22 (EDT)
committer Chris Aniszczyk2011-04-12 09:16:27 (EDT)
commitdc7921597a3568f6d9ce9a0ef4dd8fe69b6bd649 (patch)
tree8c024f7b1302cfda0d5d5226314423494577fa04
parente7ee811bf6a32569ed2a75627b1c0215a84c67c1 (diff)
downloadegit-github-dc7921597a3568f6d9ce9a0ef4dd8fe69b6bd649.zip
egit-github-dc7921597a3568f6d9ce9a0ef4dd8fe69b6bd649.tar.gz
egit-github-dc7921597a3568f6d9ce9a0ef4dd8fe69b6bd649.tar.bz2
Add utility for storing values in a repository query attributerefs/changes/59/3059/4
Change-Id: Iae11bb46d4f04b5ae96aead7168aec4b7ad5a56d Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/QueryUtils.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/QueryUtils.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/QueryUtils.java
new file mode 100644
index 0000000..c2496f3
--- /dev/null
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/QueryUtils.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
+
+/**
+ * Utilities for working with {@link IRepositoryQuery} objects.
+ *
+ * @author Kevin Sawicki (kevin@github.com)
+ */
+public abstract class QueryUtils {
+
+ /**
+ * DELIMITER
+ */
+ public static final String DELIMITER = "::"; //$NON-NLS-1$
+
+ /**
+ * Set attribute
+ *
+ * @param key
+ * @param values
+ * @param query
+ */
+ public static void setAttribute(String key, Collection<String> values,
+ IRepositoryQuery query) {
+ if (key == null || query == null)
+ return;
+
+ if (values != null && !values.isEmpty()) {
+ StringBuilder value = new StringBuilder();
+ for (String entry : values)
+ value.append(entry).append(DELIMITER);
+ query.setAttribute(key, value.toString());
+ } else
+ query.setAttribute(key, null);
+
+ }
+
+ /**
+ * Get attribute
+ *
+ * @param key
+ * @param query
+ * @return non-null but possibly empty list
+ */
+ public static List<String> getAttributes(String key, IRepositoryQuery query) {
+ if (key == null || query == null)
+ return Collections.emptyList();
+
+ String attribute = query.getAttribute(key);
+ if (attribute == null || attribute.length() == 0)
+ return Collections.emptyList();
+
+ List<String> attrs = new LinkedList<String>();
+ String[] values = attribute.split(DELIMITER);
+ for (String value : values)
+ if (value.length() > 0)
+ attrs.add(value);
+
+ return attrs;
+ }
+
+}