Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
60d525e7
Commit
60d525e7
authored
Feb 02, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish IndexedElementsBinder
parent
69234f8c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
17 deletions
+24
-17
ArrayBinder.java
...ngframework/boot/context/properties/bind/ArrayBinder.java
+5
-5
CollectionBinder.java
...mework/boot/context/properties/bind/CollectionBinder.java
+6
-6
IndexedElementsBinder.java
...k/boot/context/properties/bind/IndexedElementsBinder.java
+13
-6
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ArrayBinder.java
View file @
60d525e7
...
...
@@ -38,12 +38,12 @@ class ArrayBinder extends IndexedElementsBinder<Object> {
@Override
protected
Object
bindAggregate
(
ConfigurationPropertyName
name
,
Bindable
<?>
target
,
AggregateElementBinder
elementBinder
)
{
IndexedCollectionSupplier
collection
=
new
IndexedCollectionSupplier
(
ArrayList:
:
new
);
IndexedCollectionSupplier
result
=
new
IndexedCollectionSupplier
(
ArrayList:
:
new
);
ResolvableType
aggregateType
=
target
.
getType
(
);
ResolvableType
elementType
=
target
.
getType
().
getComponentType
();
bindIndexed
(
name
,
elementBinder
,
collection
,
target
.
getType
(),
elementType
);
if
(
collection
.
wasSupplied
())
{
List
<
Object
>
list
=
(
List
<
Object
>)
collection
.
get
();
bindIndexed
(
name
,
elementBinder
,
aggregateType
,
elementType
,
result
);
if
(
result
.
wasSupplied
())
{
List
<
Object
>
list
=
(
List
<
Object
>)
result
.
get
();
Object
array
=
Array
.
newInstance
(
elementType
.
resolve
(),
list
.
size
());
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Array
.
set
(
array
,
i
,
list
.
get
(
i
));
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/CollectionBinder.java
View file @
60d525e7
...
...
@@ -40,14 +40,14 @@ class CollectionBinder extends IndexedElementsBinder<Collection<Object>> {
AggregateElementBinder
elementBinder
)
{
Class
<?>
collectionType
=
(
target
.
getValue
()
==
null
?
target
.
getType
().
resolve
()
:
List
.
class
);
IndexedCollectionSupplier
collection
=
new
IndexedCollectionSupplier
(
()
->
CollectionFactory
.
createCollection
(
collectionType
,
0
));
ResolvableType
elementType
=
target
.
getType
().
asCollection
().
getGeneric
();
ResolvableType
aggregateType
=
ResolvableType
.
forClassWithGenerics
(
List
.
class
,
target
.
getType
().
asCollection
().
getGenerics
());
bindIndexed
(
name
,
elementBinder
,
collection
,
aggregateType
,
elementType
);
if
(
collection
.
wasSupplied
())
{
return
collection
.
get
();
ResolvableType
elementType
=
target
.
getType
().
asCollection
().
getGeneric
();
IndexedCollectionSupplier
result
=
new
IndexedCollectionSupplier
(
()
->
CollectionFactory
.
createCollection
(
collectionType
,
0
));
bindIndexed
(
name
,
elementBinder
,
aggregateType
,
elementType
,
result
);
if
(
result
.
wasSupplied
())
{
return
result
.
get
();
}
return
null
;
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java
View file @
60d525e7
...
...
@@ -53,13 +53,20 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
return
source
==
null
||
source
instanceof
IterableConfigurationPropertySource
;
}
/**
* Bind indexed elements to the supplied collection.
* @param name The name of the property to bind
* @param elementBinder the binder to use for elements
* @param aggregateType the aggregate type, may be a collection or an array
* @param elementType the element type
* @param result the destination for results
*/
protected
final
void
bindIndexed
(
ConfigurationPropertyName
name
,
AggregateElementBinder
elementBinder
,
IndexedCollectionSupplier
collection
,
ResolvableType
aggregateType
,
ResolvableType
elementType
)
{
AggregateElementBinder
elementBinder
,
ResolvableType
aggregateType
,
ResolvableType
elementType
,
IndexedCollectionSupplier
result
)
{
for
(
ConfigurationPropertySource
source
:
getContext
().
getSources
())
{
bindIndexed
(
source
,
name
,
elementBinder
,
collection
,
aggregateType
,
elementType
);
if
(
collection
.
wasSupplied
()
&&
collection
.
get
()
!=
null
)
{
bindIndexed
(
source
,
name
,
elementBinder
,
result
,
aggregateType
,
elementType
);
if
(
result
.
wasSupplied
()
&&
result
.
get
()
!=
null
)
{
return
;
}
}
...
...
@@ -134,7 +141,7 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
}
/**
* {@link AggregateBinder.AggregateSupplier AggregateSupplier} for an index
* {@link AggregateBinder.AggregateSupplier AggregateSupplier} for an index
ed
* collection.
*/
protected
static
class
IndexedCollectionSupplier
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment