BrightSide Workbench Full Report + Source Code
SkillSet.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.skills.tags;
20 
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Set;
25 import java.util.TreeSet;
26 import java.util.stream.Collectors;
27 import org.turro.marker.MarkerHelper;
28 
33 public class SkillSet extends TreeSet<SkillItem> {
34 
35  public SkillSet(Collection<? extends SkillItem> c) {
36  super(c);
37  }
38 
39  public void select(String skillName) {
40  for(SkillItem t : this) {
41  if(t.getSkillName().equals(skillName)) {
42  t.setSelected(true);
43  }
44  }
45  }
46 
47  public void unselect(String skillName) {
48  for(SkillItem t : this) {
49  if(t.getSkillName().equals(skillName)) {
50  t.setSelected(false);
51  }
52  }
53  }
54 
55  public void toggle(String skillName) {
56  for(SkillItem t : this) {
57  if(t.getSkillName().equals(skillName)) {
58  if(t.isSelected()) {
59  t.setSelected(false);
60  } else if(t.isSibling()) {
61  t.setSelected(true);
62  } else {
63  unselectAll();
64  t.setSelected(true);
65  }
66  }
67  }
68  }
69 
70  public void selectAll() {
71  for(SkillItem t : this) {
72  t.setSelected(true);
73  }
74  }
75 
76  public void unselectAll() {
77  for(SkillItem t : this) {
78  t.setSelected(false);
79  }
80  }
81 
82  public void toggle() {
83  for(SkillItem t : this) {
84  t.setSelected(!t.isSelected());
85  }
86  }
87 
88  public String skillUrl(SkillItem tag) {
89  return MarkerHelper.setObfuscatedRightNowPars("skill=" + tag.getSkillName());
90  }
91 
92  public TreeSet<String> getSkillNames() {
93  return new TreeSet(stream().map(t -> t.getSkillName()).collect(Collectors.toSet()));
94  }
95 
96  public TreeSet<SkillItem> getSelected() {
97  return new TreeSet(stream().filter(t -> t.isSelected()).collect(Collectors.toSet()));
98  }
99 
100  public TreeSet<SkillItem> getUnselected() {
101  return new TreeSet(stream().filter(t -> !t.isSelected()).collect(Collectors.toSet()));
102  }
103 
104  public TreeSet<String> getSelectedSkillNames() {
105  return new TreeSet(stream().filter(t -> t.isSelected()).map(t -> t.getSkillName()).collect(Collectors.toSet()));
106  }
107 
108  public TreeSet<String> getUnselectedSkillNames() {
109  return new TreeSet(stream().filter(t -> !t.isSelected()).map(t -> t.getSkillName()).collect(Collectors.toSet()));
110  }
111 
112  public long getMaxUsage() {
113  return stream().mapToLong(t -> t.getUsage()).max().orElse(0);
114  }
115 
116  public List<String> getIdentifiers(String root) {
117  Set<SkillItem> set = getSelected();
118  if(!(set == null && set.isEmpty())) {
119  return SkillTags.getIdentifiers(root, set);
120  }
121  return Collections.EMPTY_LIST;
122  }
123 
124  public void markSiblingsFromSelection(String root) {
126  for(SkillItem tag : getUnselected()) {
127  tag.setSibling(siblings.contains(tag));
128  }
129  }
130 
131  public static SkillSet empty() {
132  return new SkillSet(Collections.EMPTY_SET);
133  }
134 
135 }
static String setObfuscatedRightNowPars(String parameters)
void setSelected(boolean selected)
Definition: SkillItem.java:64
TreeSet< SkillItem > getSelected()
Definition: SkillSet.java:96
TreeSet< String > getSkillNames()
Definition: SkillSet.java:92
void unselect(String skillName)
Definition: SkillSet.java:47
void toggle(String skillName)
Definition: SkillSet.java:55
SkillSet(Collection<? extends SkillItem > c)
Definition: SkillSet.java:35
TreeSet< String > getSelectedSkillNames()
Definition: SkillSet.java:104
List< String > getIdentifiers(String root)
Definition: SkillSet.java:116
void markSiblingsFromSelection(String root)
Definition: SkillSet.java:124
TreeSet< SkillItem > getUnselected()
Definition: SkillSet.java:100
String skillUrl(SkillItem tag)
Definition: SkillSet.java:88
void select(String skillName)
Definition: SkillSet.java:39
TreeSet< String > getUnselectedSkillNames()
Definition: SkillSet.java:108
static List< String > getIdentifiers(String root, Set< SkillItem > set)
Definition: SkillTags.java:100
static SkillSet getSiblings(String root, Set< String > skillNames)
Definition: SkillTags.java:70