Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

111
LINES

< > BotCompany Repo | #1031874 // IMultiSet - interface to MultiSet

JavaX fragment (include)

1  
sinterface IMultiSet<A> extends IntSize {
2  
  // returns new count
3  
  int add(A key);
4  
  
5  
  /*void addAll(Iterable<A> c) {
6  
    if (c != null) for (A a : c) add(a);
7  
  }
8  
9  
  void addAll(MultiSet<A> ms) {
10  
    for (A a : ms.keySet()) add(a, ms.get(a));
11  
  }*/
12  
  
13  
  //int add(A key, int count);
14  
15  
  //void put(A key, int count);
16  
17  
  int get(A key);
18  
  //bool contains(A key);
19  
20  
  //void remove(A key);
21  
22  
  /*List<A> topTen();
23  
  
24  
  synchronized List<A> getTopTen() { ret getTopTen(10); }
25  
  synchronized List<A> getTopTen(int maxSize) {
26  
    List<A> list = getSortedListDescending();
27  
    return list.size() > maxSize ? list.subList(0, maxSize) : list;
28  
  }
29  
  
30  
  synchronized L<A> highestFirst() {
31  
    ret getSortedListDescending();
32  
  }
33  
34  
  synchronized L<A> lowestFirst() {
35  
    ret reversedList(getSortedListDescending());
36  
  }
37  
38  
  synchronized L<A> getSortedListDescending() {
39  
    List<A> list = new ArrayList<A>(map.keySet());
40  
    Collections.sort(list, new Comparator<A>() {
41  
      public int compare(A a, A b) {
42  
        return map.get(b).compareTo(map.get(a));
43  
      }
44  
    });
45  
    ret list;
46  
  }
47  
48  
  synchronized int getNumberOfUniqueElements() {
49  
    return map.size();
50  
  }
51  
  
52  
  synchronized int uniqueSize() {
53  
    ret map.size();
54  
  }
55  
56  
  synchronized Set<A> asSet() {
57  
    return map.keySet();
58  
  }
59  
60  
  synchronized NavigableSet<A> navigableSet() {
61  
    return navigableKeys((NavigableMap) map);
62  
  }
63  
64  
  synchronized A getMostPopularEntry() {
65  
    int max = 0;
66  
    A a = null;
67  
    for (Map.Entry<A,Integer> entry : map.entrySet()) {
68  
      if (entry.getValue() > max) {
69  
        max = entry.getValue();
70  
        a = entry.getKey();
71  
      }
72  
    }
73  
    return a;
74  
  }
75  
76  
  synchronized void removeAll(A key) {
77  
    size -= get(key);
78  
    map.remove(key);
79  
  }
80  
81  
  synchronized int size() {
82  
    ret size;
83  
  }
84  
85  
  synchronized MultiSet<A> mergeWith(MultiSet<A> set) {
86  
    MultiSet<A> result = new MultiSet<A>();
87  
    for (A a : set.asSet()) {
88  
      result.add(a, set.get(a));
89  
    }
90  
    return result;
91  
  }
92  
  
93  
  synchronized boolean isEmpty() {
94  
    return map.isEmpty();
95  
  }
96  
  
97  
  synchronized public String toString() { // hmm. sync this?
98  
    return str(map);
99  
  }
100  
  
101  
  synchronized void clear() {
102  
    map.clear();
103  
    size = 0;
104  
  }
105  
  
106  
  synchronized Map<A, Int> asMap() {
107  
    ret cloneMap(map);
108  
  }*/
109  
  
110  
  Set<A> keySet();
111  
}

Author comment

Began life as a copy of #1000988

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx

No comments. add comment

Snippet ID: #1031874
Snippet name: IMultiSet - interface to MultiSet
Eternal ID of this version: #1031874/5
Text MD5: 1ee7087eaad7df0fb5fdf7db5655c391
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-02-13 23:20:16
Source code size: 2387 bytes / 111 lines
Pitched / IR pitched: No / No
Views / Downloads: 248 / 857
Version history: 4 change(s)
Referenced in: [show references]