001    package jp.osdl.jbento2.analyzer;
002    
003    import java.util.Iterator;
004    
005    public class RampUpDownFilter {
006    
007        private long rampUpMillis = 60000;
008    
009        private long rampDownMillis = 60000;
010    
011        public RampUpDownFilter(long rampUpMillis, long rampDownMillis) {
012            this.rampUpMillis = rampUpMillis;
013            this.rampDownMillis = rampDownMillis;
014        }
015    
016        public SampleList doFilter(SampleList src) {
017            if (src.isEmpty() || (rampUpMillis == 0 && rampDownMillis == 0)) {
018                return src;
019            }
020    
021            SampleList result = new SampleList();
022    
023            long first = Long.MAX_VALUE;
024            long last = 0;
025    
026            for (Iterator it = src.iterator(); it.hasNext();) {
027                Sample s = (Sample) it.next();
028                if (first > s.getStartTime().getMillitime()) {
029                    first = s.getStartTime().getMillitime();
030                }
031                if (last < s.getEndTime().getMillitime()) {
032                    last = s.getEndTime().getMillitime();
033                }
034            }
035    
036            long start = first + rampUpMillis;
037            long end = last - rampDownMillis;
038    
039            for (Iterator it = src.iterator(); it.hasNext();) {
040                Sample s = (Sample) it.next();
041                if (start <= s.getStartTime().getMillitime()
042                        && end >= s.getEndTime().getMillitime()) {
043                    result.add(s);
044                }
045            }
046    
047            return result;
048        }
049    }