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