TheQuack45

Check if sender is on allowedList

Sep 27th, 2014
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. package testet.main;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.io.File;
  7. import java.io.FileNotFoundException;
  8. import java.util.Scanner;
  9.  
  10. public class UtilFuncs {
  11.    
  12.     public static void main(String[] args) {
  13.         System.out.println(checkSender("user1"));
  14.     }
  15.    
  16.     public static boolean checkSender(String sender) {
  17.         String fileName = "nameList.txt";
  18.         File file = new File(fileName);
  19.         List<String> allowedList = new ArrayList<String>();
  20.         Iterator iter = allowedList.iterator();
  21.         String current;
  22.         int lineCount = 0;
  23.         String[] allowedArray = null;
  24.         boolean isAllowed = false;
  25.        
  26.         Scanner fileIn;
  27.         Scanner fileIn2;
  28.         try {
  29.             fileIn = new Scanner(file);
  30.             fileIn2 = new Scanner(file);
  31.            
  32.             while (fileIn.hasNextLine()) {
  33.                 System.out.println(fileIn.hasNextLine());
  34.                 lineCount++;
  35.                 System.out.println(lineCount);
  36.                 System.out.println(fileIn.next());
  37.             }
  38.            
  39.             allowedArray = new String[lineCount];
  40.            
  41.             for (int i = 0; i < allowedArray.length; i++) {
  42.                 current = fileIn2.next();
  43.                 allowedArray[i] = current;
  44.                 System.out.println(current);
  45.             }
  46.         } catch (FileNotFoundException e) {
  47.             e.printStackTrace();
  48.         }
  49.        
  50.        
  51.        
  52.        
  53.         System.out.println("allowedArray.length is " + allowedArray.length);
  54.        
  55.         for (int i = 0; i < allowedArray.length; i++) {
  56.             System.out.println("allowedArray[" + i + "] is " + allowedArray[i]);
  57.            
  58.             System.out.println("Sender is " + sender);
  59.             System.out.println("Current check is " + allowedArray[i]);
  60.             System.out.println(sender.toString() == allowedArray[i].toString());
  61.             if (allowedArray[i] == sender) {
  62.                 isAllowed = true;
  63.                 System.out.println("Current check is " + sender + " vs " + allowedArray[i]);
  64.             }
  65.         }
  66.        
  67.         if (isAllowed == true) {
  68.             return true;
  69.         } else {
  70.             return false;
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment