OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 14... Line 14...
14
 package org.openconcerto.erp.core.sales.pos.model;
14
 package org.openconcerto.erp.core.sales.pos.model;
15
 
15
 
16
import java.util.ArrayList;
16
import java.util.ArrayList;
17
import java.util.Collections;
17
import java.util.Collections;
18
import java.util.Comparator;
18
import java.util.Comparator;
-
 
19
import java.util.HashSet;
19
import java.util.List;
20
import java.util.List;
-
 
21
import java.util.Set;
20
 
22
 
21
public class Categorie {
23
public class Categorie {
22
    private static List<Categorie> topLevelCategories = new ArrayList<>();
24
    private static List<Categorie> topLevelCategories = new ArrayList<>();
23
    private static List<Categorie> allCategories = new ArrayList<>();
25
    private static List<Categorie> allCategories = new ArrayList<>();
24
    private static List<Article> favoriteProducts = new ArrayList<>();
26
    private static List<Article> favoriteProducts = new ArrayList<>();
25
    private String name;
27
    private String name;
26
    // Sous catégories
28
    // Sous catégories
27
    private List<Categorie> l = new ArrayList<>();
29
    private List<Categorie> l = new ArrayList<>();
28
    // Articles dans cette categorie
30
    // Articles dans cette categorie
29
    private List<Article> articles = new ArrayList<>();
31
    private Set<Article> articles = new HashSet<>();
30
    private Categorie parent;
32
    private Categorie parent;
31
    private boolean isUnknown = false;
33
    private boolean isUnknown = false;
32
 
34
 
33
    public Categorie(String string) {
35
    public Categorie(String string) {
34
        this(string, false);
36
        this(string, false);
Line 67... Line 69...
67
    public Categorie getParent() {
69
    public Categorie getParent() {
68
        return parent;
70
        return parent;
69
    }
71
    }
70
 
72
 
71
    void addArticle(Article a) {
73
    void addArticle(Article a) {
72
        if (!this.articles.contains(a)) {
-
 
73
            this.articles.add(a);
74
        this.articles.add(a);
74
        }
75
    }
75
    }
-
 
76
 
76
 
77
    public static List<Categorie> getTopLevelCategories() {
77
    public static List<Categorie> getTopLevelCategories() {
78
        return topLevelCategories;
78
        return topLevelCategories;
79
    }
79
    }
80
 
80
 
Line 89... Line 89...
89
    public String getName() {
89
    public String getName() {
90
        return name;
90
        return name;
91
    }
91
    }
92
 
92
 
93
    public List<Article> getArticles() {
93
    public List<Article> getArticles() {
-
 
94
        int size = articles.size();
-
 
95
        for (Categorie c : l) {
-
 
96
            size += c.getArticles().size();
-
 
97
        }
94
        final List<Article> result = new ArrayList<>();
98
        final List<Article> result = new ArrayList<>(size);
95
        result.addAll(articles);
99
        result.addAll(articles);
96
        for (Categorie c : l) {
100
        for (Categorie c : l) {
97
            result.addAll(c.getArticles());
101
            result.addAll(c.getArticles());
98
        }
102
        }
99
        Collections.sort(result, new Comparator<Article>() {
103
        Collections.sort(result, new Comparator<Article>() {