• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ExpediaGroup / bull / #865

09 Jan 2024 03:40PM CUT coverage: 100.0%. Remained the same
#865

Pull #461

Fabio Borriello
Trigger notification
Pull Request #461: Bump org.slf4j:slf4j-api from 2.0.10 to 2.0.11

1198 of 1198 relevant lines covered (100.0%)

1.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/bull-bean-transformer/src/main/java/com/expediagroup/beans/populator/CollectionPopulator.java
1
/**
2
 * Copyright (C) 2019-2023 Expedia, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.expediagroup.beans.populator;
17

18
import static java.util.Objects.isNull;
19
import static java.util.stream.Collectors.toList;
20
import static java.util.stream.Collectors.toSet;
21

22
import java.lang.reflect.Field;
23
import java.util.Collection;
24
import java.util.Set;
25
import java.util.stream.Collector;
26

27
import com.expediagroup.beans.transformer.BeanTransformer;
28

29
/**
30
 * Populator for Collections types object {@link java.util.Collections}.
31
 * @param <K> the class of the collection elements.
32
 */
33
class CollectionPopulator<K> extends Populator<Collection> implements ICollectionPopulator<Collection> {
34

35
    /**
36
     * Default constructor.
37
     * @param beanTransformer the bean transformer containing the field name mapping and transformation functions
38
     */
39
    CollectionPopulator(final BeanTransformer beanTransformer) {
40
        super(beanTransformer);
2✔
41
    }
2✔
42

43
    /**
44
     * {@inheritDoc}
45
     */
46
    @Override
47
    public Collection<K> getPopulatedObject(final Field field, final Collection fieldValue) {
48
        final Class<?> genericClass = reflectionUtils.getArgumentTypeClass(fieldValue, field.getDeclaringClass().getName(), field.getName(), true);
2✔
49
        return getPopulatedObject(field.getType(), reflectionUtils.getGenericFieldType(field), fieldValue, genericClass);
2✔
50
    }
51

52
    /**
53
     * {@inheritDoc}
54
     */
55
    @SuppressWarnings("unchecked")
56
    @Override
57
    public Collection<K> getPopulatedObject(final Class<?> fieldType, final Class<?> genericFieldType, final Object fieldValue, final Class<?> nestedGenericClass) {
58
        final Collection res;
59
        if (classUtils.isPrimitiveOrSpecialType(isNull(nestedGenericClass) ? genericFieldType : nestedGenericClass)) {
2✔
60
            res = (Collection) fieldValue;
2✔
61
        } else {
62
            Collector<Object, ?, ? extends Collection<Object>> collector = Set.class.isAssignableFrom(fieldType) ? toSet() : toList();
2✔
63
            res = ((Collection<K>) fieldValue)
2✔
64
                    .stream()
2✔
65
//                    .parallelStream()
66
                    .map(elem -> transform(elem, (Class<K>) genericFieldType))
2✔
67
                    .collect(collector);
2✔
68
        }
69
        return res;
2✔
70
    }
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc