You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/06/27 17:39:04 UTC
[5/6] git commit: [OLINGO-328] improve AcceptType for multi value
support
[OLINGO-328] improve AcceptType for multi value support
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/0ffc26d1
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/0ffc26d1
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/0ffc26d1
Branch: refs/heads/olingo-328
Commit: 0ffc26d1b26488a030cdaa1ce539fd60898e698c
Parents: af3f998
Author: Stephan Klevenz <st...@sap.com>
Authored: Fri Jun 27 14:22:23 2014 +0200
Committer: Stephan Klevenz <st...@sap.com>
Committed: Fri Jun 27 14:22:23 2014 +0200
----------------------------------------------------------------------
.../olingo/commons/api/format/AcceptType.java | 20 +++++----
.../commons/api/format/AcceptTypeTest.java | 46 ++++++++++++++++++++
2 files changed, 58 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0ffc26d1/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
index 07a5452..844e0c4 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
@@ -50,7 +50,7 @@ public class AcceptType {
private static final String PARAMETER_Q = "q";
private static final Pattern Q_PARAMETER_VALUE_PATTERN = Pattern.compile("1|0|1\\.0{1,3}|0\\.\\d{1,3}");
- public static final AcceptType WILDCARD = create(MEDIA_TYPE_WILDCARD, MEDIA_TYPE_WILDCARD, null, 1F);
+ public static final AcceptType WILDCARD = create(MEDIA_TYPE_WILDCARD, MEDIA_TYPE_WILDCARD, createParameterMap(), 1F);
private final String type;
private final String subtype;
@@ -66,7 +66,7 @@ public class AcceptType {
this.quality = quality;
}
- private TreeMap<String, String> createParameterMap() {
+ private static TreeMap<String, String> createParameterMap() {
return new TreeMap<String, String>(new Comparator<String>() {
@Override
public int compare(final String o1, final String o2) {
@@ -123,11 +123,15 @@ public class AcceptType {
* @return a new <code>AcceptType</code> object
* @throws IllegalArgumentException if input string is not parseable
*/
- public static AcceptType create(final String format) {
- if (format == null) {
- throw new IllegalArgumentException("Parameter format MUST NOT be NULL.");
+ public static List<AcceptType> create(final String format) {
+ List<AcceptType> result = new ArrayList<AcceptType>();
+
+ String[] values = format.split(",");
+ for (String value : values) {
+ result.add(new AcceptType(value.trim()));
}
- return new AcceptType(format);
+
+ return result;
}
/**
@@ -136,7 +140,7 @@ public class AcceptType {
* @param format
* @return a new <code>ContentType</code> object
*/
- public static AcceptType parse(final String format) {
+ public static List<AcceptType> parse(final String format) {
try {
return AcceptType.create(format);
} catch (IllegalArgumentException e) {
@@ -222,7 +226,7 @@ public class AcceptType {
public static List<AcceptType> create(final List<String> acceptTypeStrings) {
List<AcceptType> acceptTypes = new ArrayList<AcceptType>(acceptTypeStrings.size());
for (String contentTypeString : acceptTypeStrings) {
- acceptTypes.add(create(contentTypeString));
+ acceptTypes.addAll(create(contentTypeString));
}
return acceptTypes;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0ffc26d1/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java b/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java
new file mode 100644
index 0000000..b3e3a2c
--- /dev/null
+++ b/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.api.format;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class AcceptTypeTest {
+
+ @Test
+ public void testMultiValueCreate() {
+ List<AcceptType> atl = AcceptType.create("1/1,2/2 , 3/3 ");
+
+ assertEquals(3, atl.size());
+ assertEquals("1/1", atl.get(0).toString());
+ assertEquals("2/2", atl.get(1).toString());
+ assertEquals("3/3", atl.get(2).toString());
+ }
+
+ @Test
+ public void testSingleValueCreate() {
+ List<AcceptType> atl = AcceptType.create(" a/a ");
+
+ assertEquals(1, atl.size());
+ assertEquals("a/a", atl.get(0).toString());
+ }
+}