Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ac
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OATS-CADC
ac
Commits
af2e548f
Commit
af2e548f
authored
9 years ago
by
Brian Major
Browse files
Options
Downloads
Patches
Plain Diff
s1885 - custom set for users with underlying array
parent
e30b8c55
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cadcAccessControl/src/ca/nrc/cadc/ac/UserSet.java
+163
-0
163 additions, 0 deletions
cadcAccessControl/src/ca/nrc/cadc/ac/UserSet.java
with
163 additions
and
0 deletions
cadcAccessControl/src/ca/nrc/cadc/ac/UserSet.java
0 → 100644
+
163
−
0
View file @
af2e548f
package
ca.nrc.cadc.ac
;
import
java.security.Principal
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Set
;
/**
* A custom set built on a list implementation.
*
* Ordering will not be deterministic as per the Set specification.
*/
public
class
UserSet
implements
Set
<
User
>
{
private
List
<
User
>
users
;
public
UserSet
()
{
users
=
new
ArrayList
<
User
>();
}
public
User
getUser
(
Principal
identity
)
{
User
test
=
null
;
for
(
User
u
:
users
)
{
test
=
new
User
();
test
.
getIdentities
().
add
(
identity
);
if
(
test
.
isConsistent
(
u
))
{
return
u
;
}
}
return
null
;
}
public
List
<
User
>
getUserList
()
{
return
users
;
}
@Override
public
boolean
add
(
User
e
)
{
if
(!
users
.
contains
(
e
))
{
users
.
add
(
e
);
return
true
;
}
return
false
;
}
@Override
public
boolean
addAll
(
Collection
<?
extends
User
>
c
)
{
Iterator
<?
extends
User
>
i
=
c
.
iterator
();
boolean
modified
=
false
;
while
(
i
.
hasNext
())
{
if
(
this
.
add
(
i
.
next
()))
{
modified
=
true
;
}
}
return
modified
;
}
@Override
public
void
clear
()
{
users
.
clear
();
}
@Override
public
boolean
contains
(
Object
o
)
{
return
users
.
contains
(
o
);
}
@Override
public
boolean
containsAll
(
Collection
<?>
c
)
{
return
users
.
containsAll
(
c
);
}
@Override
public
boolean
isEmpty
()
{
return
users
.
isEmpty
();
}
@Override
public
Iterator
<
User
>
iterator
()
{
return
users
.
iterator
();
}
@Override
public
boolean
remove
(
Object
o
)
{
if
(
users
.
contains
(
o
))
{
users
.
remove
(
o
);
return
true
;
}
return
false
;
}
@Override
public
boolean
removeAll
(
Collection
<?>
c
)
{
Iterator
<?>
i
=
c
.
iterator
();
boolean
modified
=
false
;
while
(
i
.
hasNext
())
{
if
(
this
.
remove
(
i
.
next
()))
{
modified
=
true
;
}
}
return
modified
;
}
@Override
public
boolean
retainAll
(
Collection
<?>
c
)
{
Iterator
<
User
>
i
=
users
.
listIterator
();
boolean
modified
=
false
;
User
next
=
null
;
while
(
i
.
hasNext
())
{
next
=
i
.
next
();
if
(!
c
.
contains
(
next
))
{
i
.
remove
();
modified
=
true
;
}
}
return
modified
;
}
@Override
public
int
size
()
{
return
users
.
size
();
}
@Override
public
Object
[]
toArray
()
{
return
users
.
toArray
();
}
@Override
public
<
T
>
T
[]
toArray
(
T
[]
a
)
{
return
users
.
toArray
(
a
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment