Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. public static Hashtable<Character, List<String>> DictMap_Products = new Hashtable<Character, List<String>>();
  2. public static StorEntry[] Products = new StorEntry[]{};
  3. public static StorEntry[] Cities = new StorEntry[]{};
  4.  
  5. @Override
  6. public void run()
  7. {
  8. while( true ) {
  9. try {
  10. long now = System.currentTimeMillis();
  11. try {
  12. Class.forName( "com.mysql.jdbc.Driver" );
  13. Connection myconn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/redeeman", "redeeman", "redeeman" );
  14. PreparedStatement stmt = myconn.prepareStatement( "SELECT String, Type, (LENGTH(`String`)-LENGTH(REPLACE(`String`,' ', ''))) AS NumSpaces FROM `stringsforlinks` ORDER BY NumSpaces DESC" );
  15. ResultSet resset = stmt.executeQuery();
  16.  
  17. // TODO: consider changing to a SELECT COUNT(String) FROM stringsforlinks GROUP BY Type..
  18. resset.last();
  19. int numrows = resset.getRow();
  20. resset.beforeFirst();
  21. ArrayList<StorEntry> prodpattarr = new ArrayList<StorEntry>( numrows+1 );
  22. ArrayList<StorEntry> citypattarr = new ArrayList<StorEntry>( numrows+1 );
  23.  
  24. DictMap_Products.clear();
  25.  
  26. while( resset.next() ) {
  27. String str = resset.getString( "String" );
  28. String type = resset.getString( "Type" );
  29. Pattern p = Pattern.compile( "\\s(" + Pattern.quote( str ) + ").?\\s", Pattern.CASE_INSENSITIVE );
  30. if( type.equals( "product" ) ) {
  31. prodpattarr.add( new StorEntry( p.matcher( "" ), str ) );
  32. List<String> d = DictMap_Products.get( Character.toLowerCase( str.charAt( 0 ) ) );
  33. if( null == d )
  34. d = new ArrayList<String>();
  35. d.add( str );
  36. DictMap_Products.put( Character.toLowerCase( str.charAt( 0 ) ), d );
  37. } else if( type.equals( "city" ) )
  38. citypattarr.add( new StorEntry( p.matcher( "" ), str ) );
  39. }
  40.  
  41. Products = prodpattarr.toArray( Products );
  42. Cities = citypattarr.toArray( Cities );
  43.  
  44. stmt.close();
  45. myconn.close();
  46.  
  47. } catch( Exception e ) {
  48. e.printStackTrace();
  49. }
  50.  
  51. System.out.println( "Refreshing data, time: " + (System.currentTimeMillis()-now) + "ms" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement