24
24
import java .util .Collection ;
25
25
import java .util .Collections ;
26
26
import java .util .HashMap ;
27
+ import java .util .Iterator ;
27
28
import java .util .LinkedHashMap ;
28
29
import java .util .LinkedHashSet ;
29
30
import java .util .List ;
31
+ import java .util .ListIterator ;
30
32
import java .util .Map ;
31
33
import java .util .Properties ;
32
34
import java .util .concurrent .atomic .AtomicInteger ;
@@ -1854,6 +1856,28 @@ public void SPR11609() {
1854
1856
assertEquals (1 , exp .getValue (sec ));
1855
1857
}
1856
1858
1859
+ @ Test
1860
+ public void SPR9735 () {
1861
+ Item item = new Item ();
1862
+ item .setName ("parent" );
1863
+
1864
+ Item item1 = new Item ();
1865
+ item1 .setName ("child1" );
1866
+
1867
+ Item item2 = new Item ();
1868
+ item2 .setName ("child2" );
1869
+
1870
+ item .add (item1 );
1871
+ item .add (item2 );
1872
+
1873
+ ExpressionParser parser = new SpelExpressionParser ();
1874
+ EvaluationContext context = new StandardEvaluationContext ();
1875
+ Expression exp = parser .parseExpression ("#item[0].name" );
1876
+ context .setVariable ("item" , item );
1877
+
1878
+ assertEquals ("child1" , exp .getValue (context ));
1879
+ }
1880
+
1857
1881
1858
1882
private static enum ABC { A , B , C }
1859
1883
@@ -1866,21 +1890,21 @@ public static class BooleanHolder {
1866
1890
1867
1891
private boolean primitiveProperty = true ;
1868
1892
1869
- public Boolean isSimpleProperty () {
1870
- return simpleProperty ;
1871
- }
1872
-
1873
1893
public void setSimpleProperty (Boolean simpleProperty ) {
1874
1894
this .simpleProperty = simpleProperty ;
1875
1895
}
1876
1896
1877
- public boolean isPrimitiveProperty () {
1878
- return primitiveProperty ;
1897
+ public Boolean isSimpleProperty () {
1898
+ return this . simpleProperty ;
1879
1899
}
1880
1900
1881
1901
public void setPrimitiveProperty (boolean primitiveProperty ) {
1882
1902
this .primitiveProperty = primitiveProperty ;
1883
1903
}
1904
+
1905
+ public boolean isPrimitiveProperty () {
1906
+ return this .primitiveProperty ;
1907
+ }
1884
1908
}
1885
1909
1886
1910
@@ -1933,13 +1957,13 @@ public static class Spr10486 {
1933
1957
1934
1958
private String name = "name" ;
1935
1959
1936
- public String getName () {
1937
- return name ;
1938
- }
1939
-
1940
1960
public void setName (String name ) {
1941
1961
this .name = name ;
1942
1962
}
1963
+
1964
+ public String getName () {
1965
+ return this .name ;
1966
+ }
1943
1967
}
1944
1968
1945
1969
@@ -1951,25 +1975,22 @@ public String isSomething() {
1951
1975
}
1952
1976
1953
1977
1954
- static class TestClass2 { // SPR-9194
1978
+ static class TestClass2 { // SPR-9194
1955
1979
1956
1980
String string ;
1957
1981
1958
-
1959
1982
public TestClass2 (String string ) {
1960
1983
this .string = string ;
1961
1984
}
1962
1985
1963
- @ Override
1964
- public int hashCode () {
1965
- return 0 ;
1986
+ public boolean equals ( Object other ) {
1987
+ return ( this == other || ( other instanceof TestClass2 &&
1988
+ this . string . equals ((( TestClass2 ) other ). string ))) ;
1966
1989
}
1967
1990
1968
- public boolean equals (Object o ) {
1969
- if (o instanceof TestClass2 ) {
1970
- return string .equals (((TestClass2 ) o ).string );
1971
- }
1972
- return false ;
1991
+ @ Override
1992
+ public int hashCode () {
1993
+ return this .string .hashCode ();
1973
1994
}
1974
1995
}
1975
1996
@@ -1983,12 +2004,12 @@ public int echo(int invocation) {
1983
2004
}
1984
2005
1985
2006
public int parameter () {
1986
- return counter .incrementAndGet ();
2007
+ return this . counter .incrementAndGet ();
1987
2008
}
1988
2009
1989
2010
@ Override
1990
2011
public Object resolve (EvaluationContext context , String beanName ) throws AccessException {
1991
- return beanName .equals ("bean" ) ? this : null ;
2012
+ return ( beanName .equals ("bean" ) ? this : null ) ;
1992
2013
}
1993
2014
}
1994
2015
@@ -1999,4 +2020,135 @@ public static class MapWithConstant extends HashMap {
1999
2020
public static final int X = 1 ;
2000
2021
}
2001
2022
2023
+
2024
+ public class Item implements List <Item > {
2025
+
2026
+ private String name ;
2027
+
2028
+ private List <Item > children = new ArrayList <Item >();
2029
+
2030
+ public void setName (String name ) {
2031
+ this .name = name ;
2032
+ }
2033
+
2034
+ public String getName () {
2035
+ return this .name ;
2036
+ }
2037
+
2038
+ @ Override
2039
+ public int size () {
2040
+ return this .children .size ();
2041
+ }
2042
+
2043
+ @ Override
2044
+ public boolean isEmpty () {
2045
+ return this .children .isEmpty ();
2046
+ }
2047
+
2048
+ @ Override
2049
+ public boolean contains (Object o ) {
2050
+ return this .children .contains (o );
2051
+ }
2052
+
2053
+ @ Override
2054
+ public Iterator <Item > iterator () {
2055
+ return this .children .iterator ();
2056
+ }
2057
+
2058
+ @ Override
2059
+ public Object [] toArray () {
2060
+ return this .children .toArray ();
2061
+ }
2062
+
2063
+ @ Override
2064
+ public <T > T [] toArray (T [] a ) {
2065
+ return this .children .toArray (a );
2066
+ }
2067
+
2068
+ @ Override
2069
+ public boolean add (Item e ) {
2070
+ return this .children .add (e );
2071
+ }
2072
+
2073
+ @ Override
2074
+ public boolean remove (Object o ) {
2075
+ return this .children .remove (o );
2076
+ }
2077
+
2078
+ @ Override
2079
+ public boolean containsAll (Collection <?> c ) {
2080
+ return this .children .containsAll (c );
2081
+ }
2082
+
2083
+ @ Override
2084
+ public boolean addAll (Collection <? extends Item > c ) {
2085
+ return this .children .addAll (c );
2086
+ }
2087
+
2088
+ @ Override
2089
+ public boolean addAll (int index , Collection <? extends Item > c ) {
2090
+ return this .children .addAll (index , c );
2091
+ }
2092
+
2093
+ @ Override
2094
+ public boolean removeAll (Collection <?> c ) {
2095
+ return this .children .removeAll (c );
2096
+ }
2097
+
2098
+ @ Override
2099
+ public boolean retainAll (Collection <?> c ) {
2100
+ return this .children .retainAll (c );
2101
+ }
2102
+
2103
+ @ Override
2104
+ public void clear () {
2105
+ this .children .clear ();
2106
+ }
2107
+
2108
+ @ Override
2109
+ public Item get (int index ) {
2110
+ return this .children .get (index );
2111
+ }
2112
+
2113
+ @ Override
2114
+ public Item set (int index , Item element ) {
2115
+ return this .children .set (index , element );
2116
+ }
2117
+
2118
+ @ Override
2119
+ public void add (int index , Item element ) {
2120
+ this .children .add (index , element );
2121
+ }
2122
+
2123
+ @ Override
2124
+ public Item remove (int index ) {
2125
+ return this .children .remove (index );
2126
+ }
2127
+
2128
+ @ Override
2129
+ public int indexOf (Object o ) {
2130
+ return this .children .indexOf (o );
2131
+ }
2132
+
2133
+ @ Override
2134
+ public int lastIndexOf (Object o ) {
2135
+ return this .children .lastIndexOf (o );
2136
+ }
2137
+
2138
+ @ Override
2139
+ public ListIterator <Item > listIterator () {
2140
+ return this .children .listIterator ();
2141
+ }
2142
+
2143
+ @ Override
2144
+ public ListIterator <Item > listIterator (int index ) {
2145
+ return this .children .listIterator (index );
2146
+ }
2147
+
2148
+ @ Override
2149
+ public List <Item > subList (int fromIndex , int toIndex ) {
2150
+ return this .children .subList (fromIndex , toIndex );
2151
+ }
2152
+ }
2153
+
2002
2154
}
0 commit comments