View Javadoc

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