Mercurial > projects > ldc
comparison tango/tango/util/collection/impl/BagCollection.d @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:5825d48b27d1 | 132:1700239cab2e |
---|---|
1 /* | |
2 File: BagCollection.d | |
3 | |
4 Originally written by Doug Lea and released into the public domain. | |
5 Thanks for the assistance and support of Sun Microsystems Labs, Agorics | |
6 Inc, Loral, and everyone contributing, testing, and using this code. | |
7 | |
8 History: | |
9 Date Who What | |
10 13Oct95 dl Create | |
11 22Oct95 dl add addElements | |
12 28jan97 dl make class public | |
13 */ | |
14 | |
15 | |
16 module tango.util.collection.impl.BagCollection; | |
17 | |
18 private import tango.util.collection.model.Bag, | |
19 tango.util.collection.model.Iterator; | |
20 | |
21 private import tango.util.collection.impl.Collection; | |
22 | |
23 /** | |
24 * | |
25 * MutableBagImpl extends MutableImpl to provide | |
26 * default implementations of some Bag operations. | |
27 * | |
28 author: Doug Lea | |
29 * @version 0.93 | |
30 * | |
31 * <P> For an introduction to this package see <A HREF="index.html"> Overview </A>. | |
32 * | |
33 **/ | |
34 | |
35 public abstract class BagCollection(V) : Collection!(V), Bag!(V) | |
36 { | |
37 alias Bag!(V).add add; | |
38 alias Collection!(V).remove remove; | |
39 alias Collection!(V).removeAll removeAll; | |
40 | |
41 | |
42 /** | |
43 * Initialize at version 0, an empty count, and null screener | |
44 **/ | |
45 | |
46 protected this () | |
47 { | |
48 super(); | |
49 } | |
50 | |
51 /** | |
52 * Initialize at version 0, an empty count, and supplied screener | |
53 **/ | |
54 protected this (Predicate screener) | |
55 { | |
56 super(screener); | |
57 } | |
58 | |
59 /** | |
60 * Implements tango.util.collection.MutableBag.addElements | |
61 * See_Also: tango.util.collection.MutableBag.addElements | |
62 **/ | |
63 | |
64 public final void add(Iterator!(V) e) | |
65 { | |
66 foreach (value; e) | |
67 add (value); | |
68 } | |
69 | |
70 | |
71 // Default implementations of Bag methods | |
72 | |
73 version (VERBOSE) | |
74 { | |
75 /** | |
76 * Implements tango.util.collection.Bag.addingIfAbsent | |
77 * See_Also: tango.util.collection.Bag.addingIfAbsent | |
78 **/ | |
79 public final Bag addingIf(V element) | |
80 { | |
81 Bag c = duplicate(); | |
82 c.addIf(element); | |
83 return c; | |
84 } | |
85 | |
86 | |
87 /** | |
88 * Implements tango.util.collection.Bag.adding | |
89 * See_Also: tango.util.collection.Bag.adding | |
90 **/ | |
91 | |
92 public final Bag adding(V element) | |
93 { | |
94 Bag c = duplicate(); | |
95 c.add(element); | |
96 return c; | |
97 } | |
98 } // version | |
99 | |
100 | |
101 /*********************************************************************** | |
102 | |
103 Implements tango.util.collection.impl.Collection.Collection.removeAll | |
104 See_Also: tango.util.collection.impl.Collection.Collection.removeAll | |
105 | |
106 Has to be here rather than in the superclass to satisfy | |
107 D interface idioms | |
108 | |
109 ************************************************************************/ | |
110 | |
111 public void removeAll (Iterator!(V) e) | |
112 { | |
113 while (e.more) | |
114 removeAll (e.get); | |
115 } | |
116 | |
117 /*********************************************************************** | |
118 | |
119 Implements tango.util.collection.impl.Collection.Collection.removeElements | |
120 See_Also: tango.util.collection.impl.Collection.Collection.removeElements | |
121 | |
122 Has to be here rather than in the superclass to satisfy | |
123 D interface idioms | |
124 | |
125 ************************************************************************/ | |
126 | |
127 public void remove (Iterator!(V) e) | |
128 { | |
129 while (e.more) | |
130 remove (e.get); | |
131 } | |
132 } | |
133 |