PageRenderTime 154ms CodeModel.GetById 60ms app.highlight 10ms RepoModel.GetById 81ms app.codeStats 0ms

/src/mpv5/utils/text/RandomText.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 205 lines | 139 code | 15 blank | 51 comment | 2 complexity | 7e7eccfc5b21d48cd9699ee9af10aacb MD5 | raw file
  1
  2/*
  3*  This file is part of YaBS.
  4*
  5*      YaBS is free software: you can redistribute it and/or modify
  6*      it under the terms of the GNU General Public License as published by
  7*      the Free Software Foundation, either version 3 of the License, or
  8*      (at your option) any later version.
  9*
 10*      YaBS is distributed in the hope that it will be useful,
 11*      but WITHOUT ANY WARRANTY; without even the implied warranty of
 12*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13*      GNU General Public License for more details.
 14*
 15*      You should have received a copy of the GNU General Public License
 16*      along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
 17 */
 18package mpv5.utils.text;
 19
 20//~--- JDK imports ------------------------------------------------------------
 21
 22import java.util.List;
 23import java.util.Vector;
 24
 25/**
 26 * A random text generator
 27 *
 28 */
 29public class RandomText {
 30    private static String source =
 31        new String(
 32            "43Atowelitsaysisaboutthemostmassivelyusefu"
 33            + "lthinganinterstellarhitchhikercanhavePartlyithasgreatpracticalvalue"
 34            + "youcanwrapitaroundyouforwarmthasyouboundacrossthecoldmoonsofJaglanBet"
 35            + "ayoucanlieonitonthebrilliantmarblesandedbeachesofSantraginusVinhalingt"
 36            + "394060333188397074520172340739371965868498876592311755875219798318317206994017"
 37            + "heheadyseavapoursyoucansleepunderitbeneaththestarswhichshinesoredlyont"
 38            + "hedesertworldofKakrafoonuseittosailaminiraftdowntheslowheavyriverMothw"
 39            + "etitforuseinhandtohandcombatwrapitroundyourheadtowardoffnoxiousfumesora"
 40            + "voidthegazeoftheRavenousBugblatterBeastofTraalamindbogginglystupidanimali"
 41            + "eckonedwith308399816614085306859704892269592775111711855313343669299238236306"
 42            + "tassumesthatifyoucantseeititcantseeyoudaftasabrushbutveryveryravenousyouc"
 43            + "anwaveyourtowelinemergenciesasadistresssignalandofcoursedryyourselfoffwithit"
 44            + "ifitstillseemstobecleanenoughMoreimportantlyatowelhasimmensepsychologicalval"
 45            + "ueForsomereasonifastragstragnonhitchhikerdiscoversthatahitchhikerhashistowel"
 46            + "withhimhewillautomaticallyassumethatheisalsoinpossessionofatoothbrushfacefl"
 47            + "386832922784929950232869659529615917138847v64003519483258392515302176217868694"
 48            + "annelsoaptinofbiscuitsflaskcompassmapballofstringgnatspraywetweathergearspa"
 49            + "cesuitetcetcFurthermorethestragwillthenhappilylendthehitchhikeranyoftheseor"
 50            + "adozenotheritemsthatthehitchhikermightaccidentallyhavelostWhatthestragwillt"
 51            + "hinkisthatanymanwhocanhitchthelengthandbreadthofthegalaxyroughitslumitstrugg"
 52            + "leagainstterribleoddswinthroughandstillknowswherehistowelisisclearlyamantober"
 53            + "2324989105969625913643ThehistoryoftheGalaxyhasgotalittlemuddledforanumber"
 54            + "ofreasonspartlybecausethosewhoaretryingtokeeptrackofithavegotalittlemuddledbut"
 55            + "alsobecausesomeverymuddlingthingshavebeenhappeninganywayOneoftheproblemshas"
 56            + "todowiththespeedoflightandthedifficultiesinvolvedintryingtoexceeditYoucantNothingtravels"
 57            + "fasterthanthespeedoflightwiththepossibleexceptionofbadnewswhichobeysitsownspeciallawsT"
 58            + "heHingefreelpeopleofArkintoofleMinordidtrytobuildspaceshipsthatwerepoweredbybadnewsb"
 59            + "uttheydidntworkparticularlywellandweresoextremelyunwelcomewhenevertheyarrivedanywh"
 60            + "erethattherewasntreallyanypointinbeingthereSobyandlargethepeoplesoftheGalaxytended"
 61            + "tolanguishintheirownlocalmuddlesandthehistoryoftheGalaxyitselfwasforalongtimelargelycosm"
 62            + "ologicalWhichisnottosaythatpeoplewerenttryingTheytriedsendingofffleetsofspaceshipstodoba"
 63            + "ttleorbusinessindistantpartsbuttheseusuallytookthousandsofyearstogetanywhereBythetimethe"
 64            + "yeventuallyarrivedotherformsoftravelhadbeendiscoveredwhichmadeuseofhyperspacetocircumven"
 65            + "tthespeedoflightsothatwhateverbattlesitwasthattheslowerthanlightfleetshadbeensenttofighthadal"
 66            + "readybeentakencareofcenturiesearlierbythetimetheyactuallygotthereThisdidntofcoursedetertheirc"
 67            + "rewsfromwantingtofightthebattlesanywayTheyweretrainedtheywerereadytheydhadacoupleofthousand"
 68            + "yearssleeptheydcomealongwaytodoatoughjobandbyZarquontheyweregoingtodoitThiswaswhent"
 69            + "hefirstmajormuddlesofGalactichistorysetinwithbattlescontinuallyreeruptingcenturiesaftertheissu"
 70            + "estheyhadbeenfoughtoverhadsupposedlybeensettledHoweverthesemuddleswereasnothingtothe"
 71            + "oneswhichhistorianshadtotryandunraveloncetimetravelwasdiscoveredandbattlesstartedpreerupt"
 72            + "inghundredsofyearsbeforetheissuesevenaroseWhentheInfiniteImprobabilityDrivearrivedandwholep"
 73            + "lanetsstartedturningunexpectedlyintobananafruitcakethegreathistoryfacultyoftheUniversityofMaxiM"
 74            + "egalonfinallygaveupcloseditselfdownandsurrendereditsbuildingstotherapidlygrowingjointfacultyofDiv"
 75            + "inityandWaterPolowhichhadbeenafterthemforyearsWhichisallverywellofcoursebutitalmostcertainlym"
 76            + "eansthatnoonewilleverknowforsurewhereforinstancetheGrebulonscamefromorexactlywhatitwasthey"
 77            + "wantedAndthisisapitybecauseifanybodyhadknownanythingaboutthemitisjustpossiblethatamostterrib"
 78            + "lecatastrophewouldhavebeenavertedoratleastwouldhavehadtofindadifferentwaytohappenClickhum"
 79            + "OnboardtheshipeverythingwasasithadbeenformillenniadeeplydarkandSilentClickhumAtleastalmostev"
 80            + "erythingClickclickhumClickhumclickhumclickhumClickclickclickclickclickhumHmmmAlowlevelsupervisin"
 81            + "gprogramwokeupaslightlyhigherlevelsupervisingprogramdeepintheshipssemisomnolentcyberbrainandre"
 82            + "portedtoitthatwheneveritwentclickallitgotwasahumThehigherlevelsupervisingprogramaskeditwhatitwass"
 83            + "upposedtogetandthelowlevelsupervisingprogramsaidthatitcouldntrememberexactlybutthoughtitwasprob"
 84            + "ablymoreofasortofdistantsatisfiedsighwasntitItdidntknowwhatthishumwasClickhumclickhumThatwasallitwa"
 85            + "sgettingThehigherlevelsupervisingprogramconsideredthisanddidntlikeitItaskedthelowlevelsupervisingprog"
 86            + "ramwhatexactlyitwassupervisingandthelowlevelsupervisingprogramsaiditcouldntrememberthateitherjusttha"
 87            + "titwassomethingthatwasmeanttogoclicksigheverytenyearsorsowhichusuallyhappenedwithoutfailIthadtriedto"
 88            + "consultitserrorlookuptablebutcouldntfinditwhichwaswhyithadalertedthehigherlevelsupervisingprogramtotheproblem"
 89            + "Thehigherlevelsupervisingprogramwenttoconsultoneofitsownlookuptablestofindoutwhatthelowlevelsupervisingprogr"
 90            + "amwasmeanttobesupervisingItcouldntfindthelookuptableOddItlookedagainAllitgotwasanerrormessageIttriedtolooku"
 91            + "ptheerrormessageinitserrormessagelookuptableandcouldntfindthateitherItallowedacoupleofnanosecondstogobywhile"
 92            + "itwentthroughallthisagainThenitwokeupitssectorfunctionsupervisorThesectorfunctionsupervisorhitimmediateproblemsI"
 93            + "tcalleditssupervisingagentwhichhitproblemstooWithinafewmillionthsofasecondvirtualcircuitsthathadlaindormantsomefo"
 94            + "ryearssomeforcenturieswereflaringintolifethroughouttheshipSomethingsomewherehadgoneterriblywrongbutnoneofthe"
 95            + "supervisingprogramscouldtellwhatitwasAteverylevelvitalinstructionsweremissingandtheinstructionsaboutwhattodointhe"
 96            + "eventofdiscoveringthatvitalinstructionsweremissingwerealsomissingSmallmodulesofsoftwareagentssurgedthroughthel"
 97            + "ogicalpathwaysgroupingconsultingregroupingTheyquicklyestablishedthattheshipsmemoryallthewaybacktoitscentralmis"
 98            + "sionmodulewasintattersNoamountofinterrogationcoulddeterminewhatitwasthathadhappenedEventhecentralmissionmo"
 99            + "duleitselfseemedtobedamagedThismadethewholeproblemverysimpletodealwithReplacethecentralmissionmoduleThere"
100            + "wasanotheroneabackupanexactduplicateoftheoriginalIthadtobephysicallyreplacedbecauseforsafetyreasonstherewasn"
101            + "olinkwhatsoeverbetweentheoriginalanditsbackupOncethecentralmissionmodulewasreplaceditcoulditselfsupervisethere"
102            + "constructionoftherestofthesystemineverydetailandallwouldbewellRobotswereinstructedtobringthebackupcentralmissio"
103            + "nmodulefromtheshieldedstrongroomwheretheyguardedittotheshipslogicchamberforinstallationThisinvolvedthelengthy"
104            + "exchangeofemergencycodesandprotocolsastherobotsinterrogatedtheagentsastotheauthenticityoftheinstructionsAtlas"
105            + "ttherobotsweresatisfiedthatallprocedureswerecorrectTheyunpackedthebackupcentralmissionmodulefromitsstorageho"
106            + "usingcarrieditoutofthestoragechamberfelloutoftheshipandwentspinningoffintothevoidThisprovidedthefirstmajorclueast"
107            + "owhatitwasthatwaswrongFurtherinvestigationquicklyestablishedwhatitwasthathadhappenedAmeteoritehadknockedala"
108            + "rgeholeintheshipTheshiphadnotpreviouslydetectedthisbecausethemeteoritehadneatlyknockedoutthatpartoftheshipsp"
109            + "rocessingequipmentwhichwassupposedtodetectiftheshiphadbeenhitbyameteoriteThefirstthingtodowastotrytosealupth"
110            + "eholeThisturnedouttobeimpossiblebecausetheshipssensorscouldntseethattherewasaholeandthesupervisorswhichsho"
111            + "uldhavesaidthatthesensorswerentworkingproperlywerentworkingproperlyandkeptsayingthatthesensorswerefineTheshi"
112            + "pcouldonlydeducetheexistenceoftheholefromthefactthattherobotshadclearlyfallenoutofittakingitssparebrainwhichwoul"
113            + "dhaveenabledittoseetheholewiththemTheshiptriedtothinkintelligentlyaboutthisfailedandthenblankedoutcompletelyfora"
114            + "bitItdidntrealiseithadblankedoutofcoursebecauseithadblankedoutItwasmerelysurprisedtoseethestarsjumpAfterthethird"
115            + "timethestarsjumpedtheshipfinallyrealisedthatitmustbeblankingoutandthatitwastimetotakesomeseriousdecisionsItrelax"
116            + "edThenitrealisedithadntactuallytakentheseriousdecisionsyetandpanickedItblankedoutagainf"
117            + "orabitWhenitawokeagainitsealedallthebulkheadsaroundwhereitknewtheunseenholemustbeItclearlyh"
118            + "adntgottoitsdestinationyetitthoughtfitfullybutsinceitnolongerhadthefaintestideawhereitsdestinationwasorh"
119            + "owtoreachitthereseemedtobelittlepointincontinuingItconsultedwhattinyscrapsofinstructionsitcouldreconstr"
120            + "uctfromthetattersofitscentralmissionmoduleYouryearmissionistolandasafedistancelandmonitoritAlloftherestw"
121            + "ascompletegarbageBeforeitblankedoutforgoodtheshipwouldhavetopassonthoseinstructionssuchastheyweretoitsm"
122            + "oreprimitivesubsidiarysystemsItmustalsoreviveallofitscrewTherewasanotherproblemWhilethecrewwasinhibernationthe"
123            + "mindsofallofitsmemberstheirmemoriestheiridentitiesandtheirunderstandingofwhattheyhadcometodohadallbeentransferre"
124            + "dintotheshipscentralmissionmoduleforsafekeepingThecrewwouldnothavethefaintestideaofwhotheywereorwhattheyweredoin"
125            + "gthereOhwellJustbeforeitblankedoutforthefinaltimetheshiprealisedthatitsengineswerebeginningtogiveouttooTheshipandits"
126            + "revivedandconfusedcrewcoastedonunderthecontrolofitssubsidiaryautomaticsystemswhichsimplylookedtolandwherevertheyc"
127            + "ouldfindtolandandmonitorwhatevertheycouldfindtomonitorAsfarasfindingsomethingtolandonwasconcernedtheydidntdove"
128            + "rywellTheplanettheyfoundwasdesolatelycoldandlonelysoachinglyfarfromthesunthatshouldwarmitthatittookalloftheEnvir"
129            + "OFormmachineryandLifeSupportOSystemstheycarriedwiththemtorenderitoratleastenoughpartsofithabitableTherew"
130            + "erebetterplanetsnearerinbuttheshipsStrateejOMatwasobviouslylockedintoLurkmodeandchosethemostdistanta"
131            + "ndunobtrusiveplanetandfurthermorewouldnotbegainsaidbyanybodyotherthantheshipsChiefStrategicOfficerSi"
132            + "nceeverybodyontheshiphadlosttheirmindsnooneknewwhotheChiefStrategicOfficerwasorevenifhecouldhave"
133            + "beenidentifiedhowhewassupposedtogoaboutgainsayingtheshipsStrateejOMatAsfarasfindingsomethingt"
134            + "omonitorwasconcernedthoughtheyhitsolidgold");
135    static List<String> usedStrings = new Vector<String>();
136    private int         length      = 5;
137    private String      string;
138
139    /**
140     * Constructs a random text generator with the default length (5)
141     */
142    public RandomText() {}
143
144    /**
145     * Constructs a random text generator with the given length
146     * @param length
147     */
148    public RandomText(int length) {
149        this.length = length;
150    }
151
152    /**
153     * Constructs a random text generator
154     * with the given length and source text
155     *
156     * @param source
157     * @param length
158     */
159    public RandomText(String source, int length) {
160        this.length       = length;
161        RandomText.source = source;
162    }
163
164    /**
165     * Generates a 8 digit integer value
166     * @return
167     */
168    public synchronized static Integer getInteger() {
169        return Integer.valueOf(getNumberText());
170    }
171
172    /**
173     * @return The random text
174     */
175    public synchronized String getString() {
176        string = RandomStringUtils.random(length, source);
177
178        if (!usedStrings.contains(string)) {
179            usedStrings.add(string);
180
181            return string;
182        } else {
183            return getString();
184        }
185    }
186
187    /**
188     * Equal to new RandomText(8).getString()
189     * @return A random 8- char text
190     */
191    public static String getText() {
192        return new RandomText(8).getString();
193    }
194
195    /**
196     * Generates a random text containing only numbers
197     * @return A random 8- char text
198     */
199    public synchronized static String getNumberText() {
200        return RandomStringUtils.randomNumeric(8);
201    }
202}
203
204
205//~ Formatted by Jindent --- http://www.jindent.com