001 package jp.osdl.jbento2.analyzer; 002 003 import java.util.ArrayList; 004 import java.util.Collections; 005 import java.util.Iterator; 006 import java.util.List; 007 import java.util.TreeSet; 008 009 010 public class SampleUtils { 011 012 public static Time getMinStartTime(SampleList samples) { 013 TreeSet ts = new TreeSet(); 014 for (Iterator it = samples.iterator(); it.hasNext(); ) { 015 Sample sample = (Sample)it.next(); 016 ts.add(sample.getStartTime()); 017 } 018 if (ts.isEmpty()) { 019 return Time.ZERO; 020 } 021 return (Time)ts.first(); 022 } 023 024 public static Time getMaxStartTime(SampleList samples) { 025 TreeSet ts = new TreeSet(); 026 for (Iterator it = samples.iterator(); it.hasNext(); ) { 027 Sample sample = (Sample)it.next(); 028 ts.add(sample.getStartTime()); 029 } 030 if (ts.isEmpty()) { 031 return Time.ZERO; 032 } 033 return (Time)ts.last(); 034 } 035 036 public static Time getMinEndTime(SampleList samples) { 037 TreeSet ts = new TreeSet(); 038 for (Iterator it = samples.iterator(); it.hasNext(); ) { 039 Sample sample = (Sample)it.next(); 040 ts.add(sample.getEndTime()); 041 } 042 if (ts.isEmpty()) { 043 return Time.ZERO; 044 } 045 return (Time)ts.first(); 046 } 047 048 public static Time getMaxEndTime(SampleList samples) { 049 TreeSet ts = new TreeSet(); 050 for (Iterator it = samples.iterator(); it.hasNext(); ) { 051 Sample sample = (Sample)it.next(); 052 ts.add(sample.getEndTime()); 053 } 054 if (ts.isEmpty()) { 055 return Time.ZERO; 056 } 057 return (Time)ts.last(); 058 } 059 060 public static Time[] getStartTimes(SampleList samples) { 061 Time[] result = new Time[samples.size()]; 062 for (int i = 0; i < result.length; i++) { 063 result[i] = samples.get(i).getStartTime(); 064 } 065 return result; 066 } 067 068 public static Time[] getEndTimes(SampleList samples) { 069 Time[] result = new Time[samples.size()]; 070 for (int i = 0; i < result.length; i++) { 071 result[i] = samples.get(i).getEndTime(); 072 } 073 return result; 074 } 075 076 public static String[] getRequestTypes(SampleList samples) { 077 List result = new ArrayList(); 078 for (Iterator it = samples.iterator(); it.hasNext(); ) { 079 Sample sample = (Sample)it.next(); 080 if (!result.contains(sample.getRequestType())) { 081 result.add(sample.getRequestType()); 082 } 083 } 084 Collections.sort(result); 085 return (String[])result.toArray(new String[result.size()]); 086 } 087 088 public static SampleList select(SampleList samples, String requestType) { 089 SampleList result = new SampleList(); 090 for (Iterator it = samples.iterator(); it.hasNext(); ) { 091 Sample sample = (Sample)it.next(); 092 if (requestType.equals(sample.getRequestType())) { 093 result.add(sample); 094 } 095 } 096 return result; 097 } 098 099 }