Class SecuritySet<K,T extends SecurityEntity<K>>

java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractSet<T>
com.easydesk.security.util.SecuritySet<K,T>
Type Parameters:
K - entity 의 id type (Comparable 이어야 한다)
T - SecurityEntity type
All Implemented Interfaces:
Serializable, Iterable<T>, Collection<T>, Set<T>
Direct Known Subclasses:
GroupSet, PermissionSet, RoleSet, UserSet

public abstract class SecuritySet<K,T extends SecurityEntity<K>> extends AbstractSet<T> implements Serializable
SecurityEntity 를 id 와 name 으로 관리하는 Set.

id 와 name(대소문자 구분 없음) 두 개의 map 을 동기화하여 유지하며, id 가 없거나 id 또는 name 이 이미 존재하는 entity 는 추가하지 않는다. 순회 순서는 id 순서이다.

Author:
Youngho Cho
See Also:
  • Field Details

    • nameMap

      protected final Map<String,T extends SecurityEntity<K>> nameMap
      Map for "name" -> "security object"
    • idMap

      protected final Map<K,T extends SecurityEntity<K>> idMap
      Map for "id" -> "security object" Key 는 comparable 을 구현해야 한다.
  • Constructor Details

    • SecuritySet

      protected SecuritySet()
      하위 클래스에서 사용하는 기본 생성자.
  • Method Details

    • getSet

      public Set<T> getSet()
      Returns an unmodifiable snapshot of the entities in this set.
      Returns:
      entity 들의 변경 불가능한 복사본
    • getNames

      public Set<String> getNames()
      Returns an unmodifiable view of the names in this set.
      Returns:
      name 들의 변경 불가능한 view
    • getIds

      public Set<K> getIds()
      Returns an unmodifiable view of the ids in this set.
      Returns:
      id 들의 변경 불가능한 view
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<K>
      Specified by:
      clear in interface Set<K>
      Overrides:
      clear in class AbstractCollection<T extends SecurityEntity<K>>
    • containsName

      public boolean containsName(String name)
      이름(대소문자 구분 없음)에 해당하는 entity 가 있는지 확인한다.
      Parameters:
      name - 확인할 이름
      Returns:
      있으면 true, 이름이 비어 있으면 false
    • containsId

      public boolean containsId(K id)
      id 에 해당하는 entity 가 있는지 확인한다.
      Parameters:
      id - 확인할 id
      Returns:
      있으면 true
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<K>
      Specified by:
      iterator in interface Iterable<K>
      Specified by:
      iterator in interface Set<K>
      Specified by:
      iterator in class AbstractCollection<T extends SecurityEntity<K>>
    • size

      public int size()
      Specified by:
      size in interface Collection<K>
      Specified by:
      size in interface Set<K>
      Specified by:
      size in class AbstractCollection<T extends SecurityEntity<K>>
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<T extends SecurityEntity<K>>
    • add

      public boolean add(T o)
      entity 를 추가한다. id 가 없거나 id 또는 name 이 이미 존재하면 추가하지 않는다.
      Specified by:
      add in interface Collection<K>
      Specified by:
      add in interface Set<K>
      Overrides:
      add in class AbstractCollection<T extends SecurityEntity<K>>
      Parameters:
      o - 추가할 entity
      Returns:
      추가되었으면 true
    • contains

      public boolean contains(Object o)
      id 가 같은 entity 가 있는지 확인한다.
      Specified by:
      contains in interface Collection<K>
      Specified by:
      contains in interface Set<K>
      Overrides:
      contains in class AbstractCollection<T extends SecurityEntity<K>>
      Parameters:
      o - 확인할 object
      Returns:
      같은 id 의 entity 가 있으면 true
    • remove

      public boolean remove(Object o)
      id 가 같은 entity 를 제거한다.
      Specified by:
      remove in interface Collection<K>
      Specified by:
      remove in interface Set<K>
      Overrides:
      remove in class AbstractCollection<T extends SecurityEntity<K>>
      Parameters:
      o - 제거할 object
      Returns:
      제거되었으면 true
    • getByName

      public Optional<T> getByName(String name)
      이름(대소문자 구분 없음)에 해당하는 entity 를 구한다.
      Parameters:
      name - 찾을 이름
      Returns:
      이름에 해당하는 entity, 없으면 빈 Optional
    • getById

      public Optional<T> getById(Object id)
      id 에 해당하는 entity 를 구한다.
      Parameters:
      id - 찾을 id
      Returns:
      id 에 해당하는 entity, 없으면 빈 Optional
    • contains

      @SafeVarargs public final boolean contains(T... tArray)
      전달된 모든 요소가 Set에 포함되어 있는지 확인합니다. (AND Stratage)
      Parameters:
      tArray - 확인하려는 요소 목록 (가변인자 또는 배열)
      Returns:
      모든 요소가 존재하면 true, 배열이 비어있으면 false, 전달된 요소 중 하나라도 없으면 false (AND Stratage)
    • containsAll

      @SafeVarargs public final boolean containsAll(T... tArray)
      전달된 모든 요소가 Set 에 포함되어 있는지 확인합니다. (AND Stratage)
      Parameters:
      tArray - 확인하려는 요소 목록 (가변인자 또는 배열)
      Returns:
      모든 요소가 존재하면 true, 배열이 비어있으면 false, 전달된 요소 중 하나라도 없으면 false