View Javadoc

1   /*
2    * @(#) ModulusFilter.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 modulus filter only accepts the nth event where n % given modulus = 0.
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 ModulusFilter extends AbstractFilter
24  {
25      /*** the maxPoints to use. */
26      private long modulus = -1;
27  
28      /*** the amount of points already accepted. */
29      private long current = -1;
30  
31      /***
32       * constructs a new ModulusFilter.
33       * 
34       * @param modulus
35       *            the modulus to use
36       */
37      public ModulusFilter(final long modulus)
38      {
39          super();
40          this.modulus = modulus;
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.current++;
50          if (this.current % this.modulus == 0)
51          {
52              return true;
53          }
54          return false;
55      }
56  
57      /***
58       * @see nl.tudelft.simulation.language.filters.Filterinterface#getCriterium()
59       */
60      @Override
61      public String getCriterium()
62      {
63          return "accepts every " + this.modulus + "nth entry";
64      }
65  }