This repository was archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 868
Expand file tree
/
Copy pathUserData.java
More file actions
106 lines (95 loc) · 3.4 KB
/
UserData.java
File metadata and controls
106 lines (95 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Copyright 2016 SmartBear Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.swagger.sample.data;
import io.swagger.sample.model.User;
import java.util.*;
public class UserData {
static List<User> users = Collections.synchronizedList( new ArrayList<User>() );
static {
users.add(createUser(1, "user1", "first name 1", "last name 1",
"email1@test.com", "123-456-7890", 1));
users.add(createUser(2, "user2", "first name 2", "last name 2",
"email2@test.com", "123-456-7890", 2));
users.add(createUser(3, "user3", "first name 3", "last name 3",
"email3@test.com", "123-456-7890", 3));
users.add(createUser(4, "user4", "first name 4", "last name 4",
"email4@test.com", "123-456-7890", 1));
users.add(createUser(5, "user5", "first name 5", "last name 5",
"email5@test.com", "123-456-7890", 2));
users.add(createUser(6, "user6", "first name 6", "last name 6",
"email6@test.com", "123-456-7890", 3));
users.add(createUser(7, "user7", "first name 7", "last name 7",
"email7@test.com", "123-456-7890", 1));
users.add(createUser(8, "user8", "first name 8", "last name 8",
"email8@test.com", "123-456-7890", 2));
users.add(createUser(9, "user9", "first name 9", "last name 9",
"email9@test.com", "123-456-7890", 3));
users.add(createUser(10, "user10", "first name 10", "last name 10",
"email10@test.com", "123-456-7890", 1));
users.add(createUser(11, "user?10", "first name ?10", "last name ?10",
"email101@test.com", "123-456-7890", 1));
}
public User findUserByName(String username) {
synchronized (users) {
for (User user : users) {
if (user.getUsername().equals(username)) {
return user;
}
}
}
return null;
}
public void addUser(User user) {
if(user.getUsername() == null)
return;
synchronized (users) {
if (users.size() > 0) {
for (int i = users.size() - 1; i >= 0; i--) {
if (users.get(i).getUsername().equals(user.getUsername())) {
users.remove(i);
}
}
}
users.add(user);
}
}
public boolean removeUser(String username) {
if (users.size() > 0) {
synchronized (users) {
for (int i = users.size() - 1; i >= 0; i--) {
if (users.get(i).getUsername().equals(username)) {
users.remove(i);
return true;
}
}
}
}
return false;
}
private static User createUser(long id, String username, String firstName,
String lastName, String email, String phone, int userStatus) {
User user = new User();
user.setId(id);
user.setUsername(username);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setEmail(email);
user.setPassword("XXXXXXXXXXX");
user.setPhone(phone);
user.setUserStatus(userStatus);
return user;
}
}