make generic function to generate targets, create initial fullscreen canvas for trials
[rmh3093.git] / motsim / TrialDataDynamic.java
blobc614877475da8d0fc5f484df2873eea1d9ce761f
1 /**
2 * TrialDataDynamic.java
3 * motsim
4 */
6 import java.awt.geom.Point2D;
7 import java.util.HashSet;
8 import java.util.Iterator;
9 import java.util.Random;
11 public class TrialDataDynamic {
13 Random rand;
15 /**
16 * An array of aircraft operator prefixes.
18 final private String[] callsign_prefixes = {
19 "SWA", "AAL", "UAL", "COA", "DAL", "FDX", "NWA", "UPS", "SKW",
20 "ACA", "BTA", "AWE", "JBU", "USA", "ASA", "TRS", "BAW", "ABX",
21 "EGF", "DLH", "WJA", "AFR", "ASH", "ASQ", "AMF", "FFT", "FLG",
22 "COM", "JZA", "CHQ", "QXE", "KLM", "DHL", "MES", "HAL", "USC",
23 "LOF", "VIR", "CJC", "KAL", "JIA", "VRD", "NKS", "TSC", "RPA",
24 "TCF", "CPA", "AWI", "IBE", "MXA", "EJA", "AZA", "SWR", "MEP",
25 "PEN", "LBQ", "GLA", "EIN", "CAL", "AAY", "AMX", "TCX", "MPH",
26 "CCI", "FLX", "BKA", "JAZ", "AIC", "GJS", "JAL", "ANA", "SCX",
27 "MTN", "FTA", "PDT", "LTU", "CPZ", "REX", "AJM", "MPE", "SIA",
28 "ICE", "SAS", "AEA", "CRL", "SKQ", "CMI", "CLX", "FIV", "TAI",
29 "MRA", "CJT", "ELY", "EVA", "NCB", "PCO", "ATN", "TOM", "CFG",
30 "AAR", "LAN", "MAL", "GTI", "JAI", "ERH", "CMP", "AUA", "RZO",
31 "GSM", "SWG", "AVA", "THT", "WAE", "SNC", "WIG", "LOT", "CCA",
32 "AFL", "XLA", "FRL", "GLR", "TAM", "FCA", "UAE", "GWY", "SVX",
33 "MDS", "SAA", "CWC", "BMA", "CAV", "DCS", "LAL", "OOM", "MUI",
34 "OAL", "KFA", "LYM", "WEW", "CTA", "BBR", "HKI", "MKU", "IWD",
35 "WIS", "RAM", "CPT", "CGC", "SUB", "FAB", "FIN", "CUB", "VTS",
36 "CGL", "CLA", "WAV", "ADH", "RJA", "AAH", "CKK", "SSX", "ANZ",
37 "WOA", "TAP", "THU", "VPB", "LNX", "CES", "KAP", "LPE", "GGN",
38 "NWD", "EXA", "WWI", "CHH", "PCE", "CAP", "SLI", "APW", "ACT",
39 "VPA", "CAO", "THY", "WIA", "CNK", "CGR", "CFN", "FPG", "APC",
40 "FWL", "GRC", "TFL", "UKZ", "NMI", "PRO", "ASP", "CON", "EMD",
41 "ETH", "SSV", "GCO", "AJT", "DNJ", "FRE", "BXR", "TAG", "BVN",
42 "BOS", "CKS", "PRY", "PAC", "PGX", "PAG", "NOA", "JDC", "AIP",
43 "BLS", "GLT", "MAH", "BXH", "CFC", "SQC", "VAL", "MAS", "ARG",
44 "MAX", "CGN", "NRL", "LNE", "ETD", "GUN", "OAE", "QTR", "EJM",
45 "ANT", "NDU", "ISR", "TWY", "MSR", "CCY", "OPT", "TEC", "PWA",
46 "LRC", "BOE", "MPD", "QFA", "CFZ", "CJA", "AVI", "CSA", "GEC",
47 "QUE"
50 public TrialDataDynamic() {
52 rand = new Random();
56 /**
57 * Generate a set of random callsigns using a random prefix from
58 * "callsign_prefixes" and a random 3 digit number.
60 * @param count The number of callsigns to generate.
61 * @return A HashSet of callsigns.
63 private HashSet<String> generate_callsigns( int count ) {
65 HashSet<String> callsigns = new HashSet<String>( count );
67 while ( callsigns.size() < count ) {
69 int randomInt = rand.nextInt( callsign_prefixes.length );
70 int callsign_suffix = 0;
72 while ( callsign_suffix < 100 ) {
74 callsign_suffix = rand.nextInt( 1000 );
78 callsigns.add( callsign_prefixes[randomInt] +
79 String.valueOf( callsign_suffix ) );
83 return callsigns;
87 /**
88 * Generate a set of random coordinates between 0.0 and 1.0.
90 * @param count The number of coordinates to generate.
91 * @return A HashSet of coordinates.
93 private HashSet<Point2D.Double> generate_coordinates( int count ) {
95 HashSet<Point2D.Double> coordinates =
96 new HashSet<Point2D.Double>( count );
98 while ( coordinates.size() < count ) {
100 double x = rand.nextDouble();
101 double y = rand.nextDouble();
102 Point2D.Double point = new Point2D.Double();
103 point.setLocation(x, y);
104 coordinates.add( point );
108 return coordinates;
112 * Generate a random set of targets.
114 * @param count The number of callsigns to generate.
115 * @return A HashSet of coordinates.
117 protected HashSet<Target> generage_targets( int count ) {
119 HashSet<Target> targets = new HashSet<Target>( count );
121 HashSet<String> callsigns = generate_callsigns( count );
122 HashSet<Point2D.Double> coordinates = generate_coordinates( count );
124 Iterator<String> callsignsIter = callsigns.iterator();
125 Iterator<Point2D.Double> coordinatesIter = coordinates.iterator();
127 while ( ( targets.size() < count ) &&
128 ( callsignsIter.hasNext() && callsignsIter.hasNext() ) ) {
129 Target target =
130 new Target( callsignsIter.next(), coordinatesIter.next() );
131 targets.add( target );
134 return targets;