Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

LanguageUtils.java

By: Fhernd on Jun 8th, 2012  |  syntax: Java  |  size: 1.01 KB  |  views: 36  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package coreservlets.jsf.ss06;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import javax.faces.model.SelectItem;
  7.  
  8. public class LanguageUtils
  9. {
  10.         private static String[] languages = { "Java", "JavaScript", "C#", "C++", "PHP", "Python", "Perl", "Ruby", "Scala" };
  11.        
  12.         private static List<SelectItem> availableLanguages;
  13.        
  14.         static
  15.         {
  16.                 availableLanguages = new ArrayList<SelectItem>();
  17.                 for( String language: languages )
  18.                 {
  19.                         availableLanguages.add( new SelectItem( language ) );
  20.                 }
  21.         }
  22.        
  23.         public static List< SelectItem > languagesList()
  24.         {
  25.                 return( availableLanguages );
  26.         }
  27.        
  28.         public static List<String> randomLanguages( int numLanguagesToStudy )
  29.         {
  30.                 List< String > randomLanguages = new ArrayList<String>();
  31.                
  32.                 for (int i = 0; i < numLanguagesToStudy; i++ )
  33.                 {
  34.                         randomLanguages.add( languages[ new java.util.Random().nextInt(9 ) ] );
  35.                 }
  36.                
  37.                 return randomLanguages;
  38.         }
  39.        
  40.         public static String findMostPopularLanguage( int index )
  41.         {
  42.                 return( languages[ index ]);
  43.         }
  44. }
clone this paste RAW Paste Data