View Javadoc
1   package us.codecraft.webmagic;
2   
3   import java.util.LinkedHashMap;
4   import java.util.Map;
5   
6   /**
7    * Object contains extract results.<br>
8    * It is contained in Page and will be processed in pipeline.
9    *
10   * @author code4crafter@gmail.com <br>
11   * @since 0.1.0
12   * @see Page
13   * @see us.codecraft.webmagic.pipeline.Pipeline
14   */
15  public class ResultItems {
16  
17      private Map<String, Object> fields = new LinkedHashMap<String, Object>();
18  
19      private Request request;
20  
21      private boolean skip;
22  
23      @SuppressWarnings("unchecked")
24      public <T> T get(String key) {
25          Object o = fields.get(key);
26          if (o == null) {
27              return null;
28          }
29          return (T) fields.get(key);
30      }
31  
32      public Map<String, Object> getAll() {
33          return fields;
34      }
35  
36      public <T> ResultItems put(String key, T value) {
37          fields.put(key, value);
38          return this;
39      }
40  
41      public Request getRequest() {
42          return request;
43      }
44  
45      public ResultItems setRequest(Request request) {
46          this.request = request;
47          return this;
48      }
49  
50      /**
51       * Whether to skip the result.<br>
52       * Result which is skipped will not be processed by Pipeline.
53       *
54       * @return whether to skip the result
55       */
56      public boolean isSkip() {
57          return skip;
58      }
59  
60  
61      /**
62       * Set whether to skip the result.<br>
63       * Result which is skipped will not be processed by Pipeline.
64       *
65       * @param skip whether to skip the result
66       * @return this
67       */
68      public ResultItems setSkip(boolean skip) {
69          this.skip = skip;
70          return this;
71      }
72  
73      @Override
74      public String toString() {
75          return "ResultItems{" +
76                  "fields=" + fields +
77                  ", request=" + request +
78                  ", skip=" + skip +
79                  '}';
80      }
81  }