Skip to content

Commit 452edd3

Browse files
committed
simplify
1 parent 9aacb1c commit 452edd3

File tree

5 files changed

+23
-36
lines changed

5 files changed

+23
-36
lines changed

src/main/java/com/gargoylesoftware/css/dom/CSSStyleDeclarationImpl.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ public int getLength() {
158158
return properties_.size();
159159
}
160160

161-
public String item(final int index) {
162-
final Property p = properties_.get(index);
163-
return (p == null) ? "" : p.getName();
164-
}
165-
166161
public AbstractCSSRuleImpl getParentRule() {
167162
return parentRule_;
168163
}
@@ -211,8 +206,8 @@ private boolean equalsProperties(final CSSStyleDeclarationImpl csd) {
211206
if ((csd == null) || (getLength() != csd.getLength())) {
212207
return false;
213208
}
214-
for (int i = 0; i < getLength(); i++) {
215-
final String propertyName = item(i);
209+
for (Property property : properties_) {
210+
final String propertyName = property.getName();
216211
// CSSValue propertyCSSValue1 = getPropertyCSSValue(propertyName);
217212
// CSSValue propertyCSSValue2 = csd.getPropertyCSSValue(propertyName);
218213
final String propertyValue1 = getPropertyValue(propertyName);

src/test/java/com/gargoylesoftware/css/DomTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public void test() throws Exception {
5656
// Enumerate the properties and retrieve their values
5757
Assert.assertEquals(5, style.getLength());
5858

59-
String name = style.item(0);
59+
String name = style.getProperties().get(0).getName();
6060
Assert.assertEquals("foo : 1.5", name + " : " + style.getPropertyValue(name));
61-
name = style.item(1);
61+
name = style.getProperties().get(1).getName();
6262
Assert.assertEquals("bogus : 3, 2, 1", name + " : " + style.getPropertyValue(name));
63-
name = style.item(2);
63+
name = style.getProperties().get(2).getName();
6464
Assert.assertEquals("bar-color : rgb(15, 238, 208)", name + " : " + style.getPropertyValue(name));
65-
name = style.item(3);
65+
name = style.getProperties().get(3).getName();
6666
Assert.assertEquals("background : rgb(170, 187, 204)", name + " : " + style.getPropertyValue(name));
67-
name = style.item(4);
67+
name = style.getProperties().get(4).getName();
6868
Assert.assertEquals("foreground : rgb(10, 20, 30)", name + " : " + style.getPropertyValue(name));
6969

7070
// Get the style declaration as a single lump of text

src/test/java/com/gargoylesoftware/css/dom/CSSStyleDeclarationImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public void emptyUrl() throws Exception {
202202

203203
Assert.assertEquals("background: url()", style.getCssText());
204204
Assert.assertEquals(1, style.getLength());
205-
Assert.assertEquals("background", style.item(0));
205+
Assert.assertEquals("background", style.getProperties().get(0).getName());
206206
Assert.assertEquals("url()", style.getPropertyValue("background"));
207207
}
208208

src/test/java/com/gargoylesoftware/css/parser/CSS3ParserTest.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void selectorLang() throws Exception {
153153

154154
Assert.assertEquals(4, rules.getLength());
155155

156-
AbstractCSSRuleImpl rule = rules.item(0);
156+
AbstractCSSRuleImpl rule = rules.getRules().get(0);
157157
Assert.assertEquals("html:lang(fr-ca) { }", rule.getCssText());
158158
ElementSelector selector = (ElementSelector) ((CSSStyleRuleImpl) rule).getSelectors().get(0);
159159
Assert.assertEquals(ConditionType.LANG_CONDITION, selector.getConditions().get(0).getConditionType());
@@ -880,12 +880,10 @@ public void hexColor() throws Exception {
880880
// Enumerate the properties and retrieve their values
881881
Assert.assertEquals(2, style.getLength());
882882

883-
String name = style.item(0);
884-
name = style.item(0);
883+
String name = style.getProperties().get(0).getName();
885884
Assert.assertEquals("color : rgb(204, 204, 204)", name + " : " + style.getPropertyValue(name));
886885

887-
name = style.item(1);
888-
name = style.item(1);
886+
name = style.getProperties().get(1).getName();
889887
Assert.assertEquals("background : rgb(28, 29, 0)", name + " : " + style.getPropertyValue(name));
890888
}
891889

@@ -910,8 +908,7 @@ public void rgb() throws Exception {
910908
// Enumerate the properties and retrieve their values
911909
Assert.assertEquals(1, style.getLength());
912910

913-
String name = style.item(0);
914-
name = style.item(0);
911+
String name = style.getProperties().get(0).getName();
915912
Assert.assertEquals("foreground : rgb(10, 20, 30)", name + " : " + style.getPropertyValue(name));
916913
}
917914

@@ -936,8 +933,7 @@ public void rgbInsideFunction() throws Exception {
936933
// Enumerate the properties and retrieve their values
937934
Assert.assertEquals(1, style.getLength());
938935

939-
String name = style.item(0);
940-
name = style.item(0);
936+
String name = style.getProperties().get(0).getName();
941937
Assert.assertEquals("color: foo(rgb(204, 221, 68))", name + ": " + style.getPropertyValue(name));
942938
}
943939

@@ -962,8 +958,7 @@ public void funct() throws Exception {
962958
// Enumerate the properties and retrieve their values
963959
Assert.assertEquals(1, style.getLength());
964960

965-
String name = style.item(0);
966-
name = style.item(0);
961+
String name = style.getProperties().get(0).getName();
967962
Assert.assertEquals("clip : foo(rect(10px, 20em, 30px, max(40, blue(rgb(1, 2, 3)))))",
968963
name + " : " + style.getPropertyValue(name));
969964

@@ -1066,8 +1061,7 @@ public void beforeAfter() throws Exception {
10661061

10671062
Assert.assertEquals(1, style.getLength());
10681063

1069-
String name = style.item(0);
1070-
name = style.item(0);
1064+
String name = style.getProperties().get(0).getName();
10711065
Assert.assertEquals("content : attr(test) \"testData\"", name + " : " + style.getPropertyValue(name));
10721066
}
10731067

@@ -1092,8 +1086,7 @@ public void rect() throws Exception {
10921086
// Enumerate the properties and retrieve their values
10931087
Assert.assertEquals(1, style.getLength());
10941088

1095-
String name = style.item(0);
1096-
name = style.item(0);
1089+
String name = style.getProperties().get(0).getName();
10971090
Assert.assertEquals("clip : rect(10px, 20px, 30px, 40px)", name + " : " + style.getPropertyValue(name));
10981091
}
10991092

@@ -1118,8 +1111,7 @@ public void attr() throws Exception {
11181111
// Enumerate the properties and retrieve their values
11191112
Assert.assertEquals(1, style.getLength());
11201113

1121-
String name = style.item(0);
1122-
name = style.item(0);
1114+
String name = style.getProperties().get(0).getName();
11231115
Assert.assertEquals("content : attr(data-foo)", name + " : " + style.getPropertyValue(name));
11241116
}
11251117

src/test/java/com/gargoylesoftware/css/parser/CSSOMParserTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public void parseStyleSheet() throws Exception {
8181
Assert.assertEquals(testSelector_, sr.getSelectorText());
8282

8383
final CSSStyleDeclarationImpl style = sr.getStyle();
84-
Assert.assertEquals(testItem_, style.item(0));
84+
Assert.assertEquals(testItem_, style.getProperties().get(0).getName());
8585

86-
final CSSValueImpl value = style.getPropertyCSSValue(style.item(0));
86+
final CSSValueImpl value = style.getPropertyCSSValue(style.getProperties().get(0).getName());
8787
Assert.assertEquals(testValue_, value.getCssText());
8888
}
8989

@@ -526,16 +526,16 @@ public void overwriteProperties() throws Exception {
526526

527527
Assert.assertEquals(4, declImpl.getLength());
528528

529-
Assert.assertEquals("background", declImpl.item(0));
529+
Assert.assertEquals("background", declImpl.getProperties().get(0).getName());
530530
Assert.assertEquals("url(img/test.png) no-repeat", declImpl.getPropertyCSSValue("background").getCssText());
531531

532-
Assert.assertEquals("background-repeat", declImpl.item(1));
532+
Assert.assertEquals("background-repeat", declImpl.getProperties().get(1).getName());
533533
Assert.assertEquals("repeat-y", declImpl.getPropertyCSSValue("background-repeat").getCssText());
534534

535-
Assert.assertEquals("background", declImpl.item(2));
535+
Assert.assertEquals("background", declImpl.getProperties().get(2).getName());
536536
Assert.assertEquals("url(img/test.png) no-repeat", declImpl.getPropertyCSSValue("background").getCssText());
537537

538-
Assert.assertEquals("background-size", declImpl.item(3));
538+
Assert.assertEquals("background-size", declImpl.getProperties().get(3).getName());
539539
Assert.assertEquals("190px 48px", declImpl.getPropertyCSSValue("background-size").getCssText());
540540

541541
// now check the core results

0 commit comments

Comments
 (0)