diff options
| author | Kevin Sawicki | 2011-04-11 21:00:22 +0000 |
|---|---|---|
| committer | Chris Aniszczyk | 2011-04-12 13:16:27 +0000 |
| commit | dc7921597a3568f6d9ce9a0ef4dd8fe69b6bd649 (patch) | |
| tree | 8c024f7b1302cfda0d5d5226314423494577fa04 | |
| parent | e7ee811bf6a32569ed2a75627b1c0215a84c67c1 (diff) | |
| download | egit-github-dc7921597a3568f6d9ce9a0ef4dd8fe69b6bd649.tar.gz egit-github-dc7921597a3568f6d9ce9a0ef4dd8fe69b6bd649.tar.xz egit-github-dc7921597a3568f6d9ce9a0ef4dd8fe69b6bd649.zip | |
Add utility for storing values in a repository query attribute
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.java | 78 |
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 00000000..c2496f3d --- /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; + } + +} |
