001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.getahead.dwrdemo.util;
017:
018: import java.util.Random;
019:
020: /**
021: * @author Joe Walker [joe at getahead dot ltd dot uk]
022: */
023: public class RandomData {
024: /**
025: * @param isUS US numbers look different to UK ones
026: * @return A phone number
027: */
028: public static String getPhoneNumber(boolean isUS) {
029: String phoneNumber;
030: if (isUS) {
031: // US
032: phoneNumber = "+1 (" + random.nextInt(9)
033: + random.nextInt(9) + random.nextInt(9) + ") "
034: + random.nextInt(9) + random.nextInt(9)
035: + random.nextInt(9) + " - " + random.nextInt(9)
036: + random.nextInt(9) + random.nextInt(9)
037: + random.nextInt(9);
038: } else {
039: // UK
040: phoneNumber = "+44 (0) 1" + random.nextInt(9)
041: + random.nextInt(9) + random.nextInt(9) + " "
042: + random.nextInt(9) + random.nextInt(9)
043: + random.nextInt(9) + random.nextInt(9)
044: + random.nextInt(9) + random.nextInt(9);
045: }
046: return phoneNumber;
047: }
048:
049: public static String getFirstName() {
050: return FIRSTNAMES[random.nextInt(FIRSTNAMES.length)];
051: }
052:
053: public static String getSurname() {
054: return SURNAMES[random.nextInt(SURNAMES.length)];
055: }
056:
057: public static String getFullName() {
058: return getFirstName() + " " + getSurname();
059: }
060:
061: public static String getAddress() {
062: String housenum = (random.nextInt(99) + 1) + " ";
063: String road1 = ROADS1[random.nextInt(ROADS1.length)];
064: String road2 = ROADS2[random.nextInt(ROADS2.length)];
065: int townNum = random.nextInt(TOWNS.length);
066: String town = TOWNS[townNum];
067: return housenum + road1 + " " + road2 + ", " + town;
068: }
069:
070: public static String[] getAddressAndNumber() {
071: String[] reply = new String[2];
072:
073: String housenum = (random.nextInt(99) + 1) + " ";
074: String road1 = ROADS1[random.nextInt(ROADS1.length)];
075: String road2 = ROADS2[random.nextInt(ROADS2.length)];
076: int townNum = random.nextInt(TOWNS.length);
077: String town = TOWNS[townNum];
078:
079: reply[0] = housenum + road1 + " " + road2 + ", " + town;
080: reply[1] = getPhoneNumber(townNum < 5);
081:
082: return reply;
083: }
084:
085: public static float getSalary() {
086: return Math.round(10 + 90 * random.nextFloat()) * 1000;
087: }
088:
089: private static final Random random = new Random();
090:
091: private static final String[] FIRSTNAMES = { "Fred", "Jim",
092: "Shiela", "Jack", "Betty", "Jacob", "Martha", "Kelly",
093: "Luke", "Matt", "Gemma", "Joe", "Ben", "Jessie", "Leanne",
094: "Becky", "William", "Jo" };
095:
096: private static final String[] SURNAMES = { "Sutcliffe",
097: "MacDonald", "Duckworth", "Smith", "Wisner", "Nield",
098: "Turton", "Trelfer", "Wilson", "Johnson", "Daniels",
099: "Jones", "Wilkinson", "Wilton" };
100:
101: private static final String[] ROADS1 = { "Green", "Red", "Yellow",
102: "Brown", "Blue", "Black", "White", };
103:
104: private static final String[] ROADS2 = { "Close", "Drive",
105: "Street", "Avenue", "Crescent", "Road", "Place", };
106:
107: private static final String[] TOWNS = { "San Mateo",
108: "San Francisco", "San Diego", "New York", "Atlanta",
109: "Sandford", "York", "London", "Coventry", "Exeter",
110: "Knowle", };
111: }
|