!htc replace Parameter interface with ju.Map.Entry in japi.Uri

This commit is contained in:
2beaucoup 2014-12-05 16:21:15 +01:00
parent a9dc7e0449
commit 0b3120d690
3 changed files with 14 additions and 17 deletions

View file

@ -12,7 +12,7 @@ import java.nio.charset.Charset;
import java.util.Map;
/**
* Represents a Uri. Use the `withX` methods to create modified copies of a given instance.
* Represents an Uri. Use the `withX` methods to create modified copies of a given instance.
*/
public abstract class Uri {
/**
@ -76,22 +76,18 @@ public abstract class Uri {
public abstract boolean containsParameter(String key);
/**
* Returns an Iterable of all query parameters of this Uri.
* Returns an `Iterable` of all query parameters of this Uri. Use the `parameterMap()`
* method to filter out entries with duplicated keys.
*/
public abstract Iterable<Parameter> parameters();
public abstract Iterable<Map.Entry<String, String>> parameters();
/**
* Returns a key/value map of the query parameters of this Uri. Use
* the `parameters()` method to returns all parameters if keys may occur
* the `parameters()` method to return all parameters if keys may occur
* multiple times.
*/
public abstract Map<String, String> parameterMap();
public static interface Parameter {
String key();
String value();
}
/**
* Returns the fragment part of this Uri.
*/

View file

@ -40,11 +40,12 @@ protected[model] case class JavaUri(uri: model.Uri) extends Uri {
def queryString(): String = uri.query.toString
def parameterMap(): ju.Map[String, String] = uri.query.toMap.asJava
def parameters(): jl.Iterable[Uri.Parameter] = uri.query.map(t Param(t._1, t._2): Uri.Parameter).toIterable.asJava
def parameters(): jl.Iterable[Param] =
uri.query.map { case (k, v) new ju.AbstractMap.SimpleImmutableEntry(k, v): Param }.toIterable.asJava
def containsParameter(key: String): Boolean = uri.query.get(key).isDefined
def parameter(key: String): Option[String] = uri.query.get(key)
case class Param(key: String, value: String) extends Uri.Parameter
type Param = ju.Map.Entry[String, String]
def fragment: Option[String] = uri.fragment

View file

@ -44,14 +44,14 @@ class JavaApiSpec extends FreeSpec with MustMatchers {
Accessors.Uri("/abc?name=blub&age=28&name=blub2")
.parameters.asScala.toSeq
param1.key() must be("name")
param1.value() must be("blub")
param1.getKey must be("name")
param1.getValue must be("blub")
param2.key() must be("age")
param2.value() must be("28")
param2.getKey must be("age")
param2.getValue must be("28")
param3.key() must be("name")
param3.value() must be("blub2")
param3.getKey must be("name")
param3.getValue must be("blub2")
}
"containsParameter" in {
val uri = Accessors.Uri("/abc?name=blub")