Advertisement
Guest User

ExampleCode

a guest
May 11th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. /**
  2.  *
  3.  * @author Pudding
  4.  */
  5. public class Test {
  6.  
  7.     static class BeanUsers {
  8.  
  9.         private String userID;
  10.  
  11.         public BeanUsers() {
  12.             this("");
  13.         }
  14.  
  15.         public BeanUsers(String userID) {
  16.             this.userID = userID;
  17.         }
  18.  
  19.         public String getUserID() {
  20.             return userID;
  21.         }
  22.     }
  23.  
  24.     public static class FileHandler {
  25.  
  26.         private FileHandler() {
  27.         } //Konstruktor
  28.         private ArrayList<BeanUsers> allUser = new ArrayList<>();
  29.         private static FileHandler instance = null;
  30.         private BeanUsers currentUser = new BeanUsers();
  31.  
  32.         public static synchronized FileHandler getInstance() {
  33.             if (instance == null) {
  34.                 instance = new FileHandler();
  35.             }
  36.             return instance;
  37.         }
  38.  
  39.         public int addNewUser(BeanUsers neuer) {
  40.             this.allUser.add(neuer); //hier soll es eigentlich nur ANGEHANGEN werden
  41.             return this.allUser.indexOf(neuer); //gibt index, des neuen Elementes zurück
  42.         }
  43.  
  44.         public ArrayList<BeanUsers> getAllUser() {
  45.             return allUser;
  46.         }
  47.  
  48.     }
  49.  
  50.     public static void main(String[] args) {
  51.         FileHandler handler = FileHandler.getInstance();
  52.         System.out.println(handler.addNewUser(new BeanUsers("Pudding")));
  53.         System.out.println(handler.addNewUser(new BeanUsers("Pudding2")));
  54.         for (BeanUsers user : handler.getAllUser()) {
  55.             System.out.println(user.getUserID());
  56.         }
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement