1
1
/*
2
- * Copyright 2014 the original author or authors.
2
+ * Copyright 2014-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
import java .net .URI ;
19
19
import java .util .HashMap ;
20
20
import java .util .Map ;
21
+ import java .util .stream .StreamSupport ;
21
22
22
- import org .springframework .core .ParameterizedTypeReference ;
23
23
import org .springframework .hateoas .MediaTypes ;
24
24
import org .springframework .hateoas .PagedResources ;
25
25
import org .springframework .hateoas .PagedResources .PageMetadata ;
26
26
import org .springframework .hateoas .Resource ;
27
27
import org .springframework .hateoas .client .Traverson ;
28
+ import org .springframework .hateoas .mvc .TypeReferences .PagedResourcesType ;
28
29
29
30
/**
30
31
* @author Oliver Gierke
31
32
*/
32
33
public class StarbucksClient {
33
34
34
- private static final ParameterizedTypeReference <PagedResources <Resource <Store >>> TYPE_REFERENCE = new ParameterizedTypeReference <PagedResources <Resource <Store >>>() {};
35
-
36
35
public static void main (String [] args ) {
37
36
38
37
Traverson traverson = new Traverson (URI .create ("http://localhost:8080" ), MediaTypes .HAL_JSON );
@@ -44,19 +43,16 @@ public static void main(String[] args) {
44
43
PagedResources <Resource <Store >> resources = traverson . //
45
44
follow ("stores" , "search" , "by-location" ).//
46
45
withTemplateParameters (parameters ).//
47
- toObject (TYPE_REFERENCE );
46
+ toObject (new PagedResourcesType < Resource < Store >>() {} );
48
47
49
48
PageMetadata metadata = resources .getMetadata ();
50
49
51
50
System .out .println (String .format ("Got %s of %s stores: " , resources .getContent ().size (),
52
51
metadata .getTotalElements ()));
53
52
54
- for (Resource <Store > resource : resources ) {
55
-
56
- Store store = resource .getContent ();
57
-
58
- System .out .println (String .format ("- %s - %s" , store .name , store .address ));
59
- }
53
+ StreamSupport .stream (resources .spliterator (), false ).//
54
+ map (Resource ::getContent ).//
55
+ forEach (store -> String .format ("- %s - %s" , store .name , store .address ));
60
56
}
61
57
62
58
static class Store {
0 commit comments