View Javadoc

1   /*
2    * @(#) MaxPointFilter.java Oct 26, 2004 Copyright (c) 2002-2005 Delft University of Technology Jaffalaan 5,
3    * 2628 BX Delft, the Netherlands. All rights reserved. This software is proprietary information of Delft
4    * University of Technology The code is published under the Lesser General Public License
5    */
6   package nl.tudelft.simulation.language.filters;
7   
8   /***
9    * The histogram specifies a histogram chart for the DSOL framework.
10   * <p>
11   * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft University of Technology </a>, the
12   * Netherlands.
13   * <p>
14   * See for project information <a
15   * href="http://www.simulation.tudelft.nl/dsol/language">www.simulation.tudelft.nl/language </a> <br>
16   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser General Public License (LGPL)
17   * </a>, no warranty
18   * 
19   * @author <a href="http://www.peter-jacobs.com/index.htm"> Peter Jacobs </a>
20   * @version $Revision: 1.8 $ $Date: 2005/08/04 12:08:54 $
21   * @since 1.5
22   */
23  public class MaxPointFilter extends AbstractFilter
24  {
25      /*** the maxPoints to use. */
26      private long maxPoints = -1;
27  
28      /*** the amount of points already accepted. */
29      private long accepted = 0;
30  
31      /***
32       * constructs a new MaxPointFilter.
33       * 
34       * @param maxPoints
35       *            the maximum points to display
36       */
37      public MaxPointFilter(final long maxPoints)
38      {
39          super();
40          this.maxPoints = maxPoints;
41      }
42  
43      /***
44       * @see nl.tudelft.simulation.language.filters.AbstractFilter#filter(java.lang.Object)
45       */
46      @Override
47      protected synchronized boolean filter(final Object entry)
48      {
49          this.accepted++;
50          if (this.accepted > this.maxPoints)
51          {
52              return false;
53          }
54          return true;
55      }
56  
57      /***
58       * @see nl.tudelft.simulation.language.filters.Filterinterface#getCriterium()
59       */
60      @Override
61      public String getCriterium()
62      {
63          return "accepts the first MaxPoint(=" + this.maxPoints + ") entries";
64      }
65  }