Mercurial > hg > pub > prymula > com
diff kopieckreta/src/MyResource.java @ 0:2787f5e749ae
INIT
author | prymula <prymula76@outlook.com> |
---|---|
date | Thu, 21 Sep 2023 22:33:57 +0200 |
parents | |
children | 489244127359 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kopieckreta/src/MyResource.java Thu Sep 21 22:33:57 2023 +0200 @@ -0,0 +1,132 @@ +/* + Nie mieszać z java.awt.* (!!!) +*/ +package src; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.io.BufferedReader; +import java.io.InputStreamReader; + +import java.util.*; +import java.lang.*; + + +class MyResource { + final int MAX_WORDS=67656; + + public void MyResource() + { + } + private static final String absName = "/slownik.txt"; + // TODO - to jest mniej eleganckie; + static ArrayList<String> directory3 = new ArrayList<String>(); + static ArrayList<String> directory4 = new ArrayList<String>(); + static ArrayList<String> directory5 = new ArrayList<String>(); + static ArrayList<String> directory6 = new ArrayList<String>(); + static ArrayList<String> directory7 = new ArrayList<String>(); + static ArrayList<String> directory8 = new ArrayList<String>(); + static ArrayList<String> directory9 = new ArrayList<String>(); + static ArrayList<String> directory10 = new ArrayList<String>(); + static ArrayList<String> directory11 = new ArrayList<String>(); + static ArrayList<String> directory12 = new ArrayList<String>(); + static ArrayList<String> directory13 = new ArrayList<String>(); + static ArrayList<String> directory14 = new ArrayList<String>(); + //static int mem=0; + + public void read() throws Exception{ + String list; + + try { + InputStream is = this.getClass().getResourceAsStream(absName); + BufferedReader br=new BufferedReader(new InputStreamReader(is, "utf-8")); + for (int i=0; i<MAX_WORDS; i++){ + list = br.readLine(); + + if (list.length()==3){ + directory3.add(list); + } + else if (list.length()==4){ + directory4.add(list); + } + else if (list.length()==5){ + directory5.add(list); + } + else if (list.length()==6){ + directory6.add(list); + } + else if (list.length()==7){ + directory7.add(list); + } + else if (list.length()==8){ + directory8.add(list); + } + else if (list.length()==9){ + directory9.add(list); + } + else if (list.length()==10){ + directory10.add(list); + } + else if (list.length()==11){ + directory11.add(list); + } + else if (list.length()==12){ + directory12.add(list); + } + else if (list.length()==13){ + directory13.add(list); + } + else if (list.length()==14){ + directory14.add(list); + } + } + + } + catch (Exception e){ + e.printStackTrace(); + } + } + static public String getDirectory(int n_dir){ + Random generator = new Random(); + //mem++; + if (n_dir==3){ + return (directory3.get(generator.nextInt(directory3.size()))); + } + if (n_dir==4){ + return (directory4.get(generator.nextInt(directory4.size()))); + } + if (n_dir==5){ + return (directory5.get(generator.nextInt(directory5.size()))); + } + if (n_dir==6){ + return (directory6.get(generator.nextInt(directory6.size()))); + } + if (n_dir==7){ + return (directory7.get(generator.nextInt(directory7.size()))); + } + if (n_dir==8){ + return (directory8.get(generator.nextInt(directory8.size()))); + } + if (n_dir==9){ + return (directory9.get(generator.nextInt(directory9.size()))); + } + if (n_dir==10){ + return (directory10.get(generator.nextInt(directory10.size()))); + } + if (n_dir==11){ + return (directory11.get(generator.nextInt(directory11.size()))); + } + if (n_dir==12){ + return (directory12.get(generator.nextInt(directory12.size()))); + } + if (n_dir==13){ + return (directory13.get(generator.nextInt(directory13.size()))); + } + if (n_dir==14){ + return (directory14.get(generator.nextInt(directory14.size()))); + } + // Na sztukę + return ""; + } +} \ No newline at end of file