BrightSide Workbench Full Report + Source Code
SecSet.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.security;
20 
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.TreeSet;
24 import java.util.stream.Collectors;
25 import org.turro.marker.MarkerHelper;
26 
31 public class SecSet extends TreeSet<SecItem> {
32 
33  public SecSet(Collection<? extends SecItem> c) {
34  super(c);
35  }
36 
37  public void select(String secName) {
38  for(SecItem t : this) {
39  if(t.getSecName().equals(secName)) {
40  t.setSelected(true);
41  }
42  }
43  }
44 
45  public void unselect(String secName) {
46  for(SecItem t : this) {
47  if(t.getSecName().equals(secName)) {
48  t.setSelected(false);
49  }
50  }
51  }
52 
53  public void toggle(String secName) {
54  for(SecItem t : this) {
55  if(t.getSecName().equals(secName)) {
56  if(t.isSelected()) {
57  t.setSelected(false);
58  } else if(t.isSibling()) {
59  t.setSelected(true);
60  } else {
61  unselectAll();
62  t.setSelected(true);
63  }
64  }
65  }
66  }
67 
68  public void selectAll() {
69  for(SecItem t : this) {
70  t.setSelected(true);
71  }
72  }
73 
74  public void unselectAll() {
75  for(SecItem t : this) {
76  t.setSelected(false);
77  }
78  }
79 
80  public void toggle() {
81  for(SecItem t : this) {
82  t.setSelected(!t.isSelected());
83  }
84  }
85 
86  public String secUrl(SecItem sec) {
87  return MarkerHelper.setObfuscatedRightNowPars("sec=" + sec.getSecName());
88  }
89 
90  public TreeSet<String> getSecNames() {
91  return new TreeSet(stream().map(t -> t.getSecName()).collect(Collectors.toSet()));
92  }
93 
94  public TreeSet<SecItem> getSelected() {
95  return new TreeSet(stream().filter(t -> t.isSelected()).collect(Collectors.toSet()));
96  }
97 
98  public TreeSet<SecItem> getUnselected() {
99  return new TreeSet(stream().filter(t -> !t.isSelected()).collect(Collectors.toSet()));
100  }
101 
102  public TreeSet<String> getSelectedSecNames() {
103  return new TreeSet(stream().filter(t -> t.isSelected()).map(t -> t.getSecName()).collect(Collectors.toSet()));
104  }
105 
106  public TreeSet<String> getUnselectedSecNames() {
107  return new TreeSet(stream().filter(t -> !t.isSelected()).map(t -> t.getSecName()).collect(Collectors.toSet()));
108  }
109 
110  public long getMaxUsage() {
111  return stream().mapToLong(t -> t.getUsage()).max().orElse(0);
112  }
113 
116  for(SecItem sec : getUnselected()) {
117  sec.setSibling(siblings.contains(sec));
118  }
119  }
120 
121  public static SecSet empty() {
122  return new SecSet(Collections.EMPTY_SET);
123  }
124 
125 }
static String setObfuscatedRightNowPars(String parameters)
void setSelected(boolean selected)
Definition: SecItem.java:58
void toggle(String secName)
Definition: SecSet.java:53
void unselect(String secName)
Definition: SecSet.java:45
TreeSet< SecItem > getUnselected()
Definition: SecSet.java:98
TreeSet< String > getUnselectedSecNames()
Definition: SecSet.java:106
void markSiblingsFromSelection()
Definition: SecSet.java:114
String secUrl(SecItem sec)
Definition: SecSet.java:86
TreeSet< String > getSecNames()
Definition: SecSet.java:90
void select(String secName)
Definition: SecSet.java:37
SecSet(Collection<? extends SecItem > c)
Definition: SecSet.java:33
static SecSet empty()
Definition: SecSet.java:121
TreeSet< String > getSelectedSecNames()
Definition: SecSet.java:102
TreeSet< SecItem > getSelected()
Definition: SecSet.java:94
static SecSet getSiblings(Set< String > secNames)
Definition: Secs.java:59