- #1
DottZakapa
- 239
- 17
- TL;DR Summary
- The TreeMap in a class, every time the class is accessed the tree map content gets deleted
here is the portion of code
[Code tags added by the Mentors]
[Code tags added by the Mentors]
Java:
public void addPosition(String name, String skillNames) throws ApplicationException {
Position ps=new Position (name); //creating object position
if(listaPosizioni.get(name)==null) { //checking if position already present in the list
listaPosizioni.put(name, ps); //adding position to the list
} else throw new ApplicationException();
for (String s : skillNames) {
if (elencoSkills.get(s)==null) {
throw new ApplicationException();
}
Skill skil= new Skill(s); // At first cycle of the for data is inserted properly , at second cycle the TreeMap in the corresponding classes are reset
ps.addSkill(skil);
skil.addPosition(ps);
}
...
class Position{
private String name;
private List<Skill> listSkills=new ArrayList<>(); //This list every time is accessed during the for cycle gets initialised again
public Position(String name) {
this.name=name;
}
public void addSkill(Skill skill) { //method to add skill required for the position
listSkills.add(skill);
}
public class Skill {
private String name;
private Map<String, Position> positions = new TreeMap<>();
//private List<Capability> capabilities = new ArrayList<>();
Skill(String name) {this.name = name;}
public String getName() {
return name;
}
public List<Position> getPositions() {
return new ArrayList<>(positions.values());}
void addPosition(Position position) {
positions.put(position.getName(), position);
}
Last edited by a moderator: