View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package net.sf.ehcache.search.aggregator;
18  
19  import net.sf.ehcache.search.Attribute;
20  
21  /***
22   * Helper class to construct the builtin aggregator types. These methods can be statically imported to make query building looker better in
23   * source code
24   *
25   * @author teck
26   */
27  public final class Aggregators {
28  
29      private Aggregators() {
30          //
31      }
32  
33      /***
34       * Construct a minimum value aggregator
35       *
36       * @param attribute
37       * @return min aggregator
38       */
39      public static Aggregator min(final Attribute<?> attribute) {
40          return new Aggregator() {
41              public <T> AggregatorInstance<T> createInstance() {
42                  return new Min(attribute);
43              }
44          };
45      }
46  
47      /***
48       * Construct a maximum value aggregator
49       *
50       * @param attribute
51       * @return max aggregator
52       */
53      public static Aggregator max(final Attribute<?> attribute) {
54          return new Aggregator() {
55              public <T> AggregatorInstance<T> createInstance() {
56                  return new Max(attribute);
57              }
58          };
59      }
60  
61      /***
62       * Construct an average value aggregator
63       *
64       * @param attribute
65       * @return average aggregator
66       */
67      public static Aggregator average(final Attribute<?> attribute) {
68          return new Aggregator() {
69              public AggregatorInstance<Double> createInstance() {
70                  return new Average(attribute);
71              }
72          };
73      }
74  
75      /***
76       * Construct a sum aggregator
77       *
78       * @param attribute
79       * @return sum aggregator
80       */
81      public static Aggregator sum(final Attribute<?> attribute) {
82          return new Aggregator() {
83              public AggregatorInstance<Long> createInstance() {
84                  return new Sum(attribute);
85              }
86          };
87      }
88  
89      /***
90       * Construct a counting aggregator
91       *
92       * @return count aggregator
93       */
94      public static Aggregator count() {
95          return new Aggregator() {
96              public AggregatorInstance<Integer> createInstance() {
97                  return new Count();
98              }
99          };
100 
101     }
102 }