Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Side by Side Diff: tools/dom/src/CssClassSet.dart

Issue 11931034: Add methods to Collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of html; 5 part of html;
6 6
7 abstract class CssClassSet implements Set<String> { 7 abstract class CssClassSet implements Set<String> {
8 8
9 String toString() { 9 String toString() {
10 return Strings.join(new List.from(readClasses()), ' '); 10 return Strings.join(new List.from(readClasses()), ' ');
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 dynamic combine(dynamic previousValue, String element)) { 60 dynamic combine(dynamic previousValue, String element)) {
61 return readClasses().reduce(initialValue, combine); 61 return readClasses().reduce(initialValue, combine);
62 } 62 }
63 // interface Collection - END 63 // interface Collection - END
64 64
65 // interface Set - BEGIN 65 // interface Set - BEGIN
66 bool contains(String value) => readClasses().contains(value); 66 bool contains(String value) => readClasses().contains(value);
67 67
68 void add(String value) { 68 void add(String value) {
69 // TODO - figure out if we need to do any validation here 69 // TODO - figure out if we need to do any validation here
70 // or if the browser natively does enough 70 // or if the browser natively does enough.
71 _modify((s) => s.add(value)); 71 _modify((s) => s.add(value));
72 } 72 }
73 73
74 bool remove(String value) { 74 bool remove(Object value) {
75 if (value is! String) return false;
75 Set<String> s = readClasses(); 76 Set<String> s = readClasses();
76 bool result = s.remove(value); 77 bool result = s.remove(value);
77 writeClasses(s); 78 writeClasses(s);
78 return result; 79 return result;
79 } 80 }
80 81
81 void addAll(Iterable<String> iterable) { 82 void addAll(Iterable<String> iterable) {
82 // TODO - see comment above about validation 83 // TODO - see comment above about validation.
83 _modify((s) => s.addAll(iterable)); 84 _modify((s) => s.addAll(iterable));
84 } 85 }
85 86
86 void removeAll(Iterable<String> iterable) { 87 void removeAll(Iterable<String> iterable) {
87 _modify((s) => s.removeAll(iterable)); 88 _modify((s) => s.removeAll(iterable));
88 } 89 }
89 90
91 void retainAll(Iterable<String> iterable) {
92 _modify((s) => s.retainAll(iterable));
93 }
94
95 void removeMatching(bool test(String name)) {
96 _modify((s) => s.removeMatching(test));
97 }
98
99 void retainMatching(bool test(String name)) {
100 _modify((s) => s.retainMatching(test));
101 }
102
90 bool isSubsetOf(Collection<String> collection) => 103 bool isSubsetOf(Collection<String> collection) =>
91 readClasses().isSubsetOf(collection); 104 readClasses().isSubsetOf(collection);
92 105
93 bool containsAll(Collection<String> collection) => 106 bool containsAll(Collection<String> collection) =>
94 readClasses().containsAll(collection); 107 readClasses().containsAll(collection);
95 108
96 Set<String> intersection(Collection<String> other) => 109 Set<String> intersection(Collection<String> other) =>
97 readClasses().intersection(other); 110 readClasses().intersection(other);
98 111
99 String get first => readClasses().first; 112 String get first => readClasses().first;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 */ 159 */
147 Set<String> readClasses(); 160 Set<String> readClasses();
148 161
149 /** 162 /**
150 * Join all the elements of a set into one string and write 163 * Join all the elements of a set into one string and write
151 * back to the element. 164 * back to the element.
152 * This is intended to be overridden by specific implementations. 165 * This is intended to be overridden by specific implementations.
153 */ 166 */
154 void writeClasses(Set<String> s); 167 void writeClasses(Set<String> s);
155 } 168 }
OLDNEW
« no previous file with comments | « sdk/lib/svg/dartium/svg_dartium.dart ('k') | tools/dom/templates/html/impl/impl_Element.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698