1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.script.internal.safe

File CollectionScriptSafeProvider.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
9
1
1
71
35
3
0.33
9
1
3

Classes

Class Line # Actions
CollectionScriptSafeProvider 42 9 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.script.internal.safe;
21   
22    import java.util.ArrayList;
23    import java.util.Collection;
24    import java.util.HashSet;
25    import java.util.LinkedHashSet;
26    import java.util.Set;
27   
28    import javax.inject.Inject;
29    import javax.inject.Singleton;
30   
31    import org.xwiki.component.annotation.Component;
32   
33    /**
34    * Provide safe Collection.
35    *
36    * @version $Id: 5297f6ae672a4b389ab0e9f8342475cbe404f1ec $
37    * @since 4.0M2
38    */
39    @Component
40    @Singleton
41    @SuppressWarnings("rawtypes")
 
42    public class CollectionScriptSafeProvider implements ScriptSafeProvider<Collection>
43    {
44    /**
45    * Used to provide collection elements safe versions.
46    */
47    @Inject
48    private ScriptSafeProvider safeProvider;
49   
 
50  37359 toggle @Override
51    public <S> S get(Collection unsafe)
52    {
53  37359 Collection safe;
54   
55  37358 if (unsafe instanceof Set) {
56  70 if (unsafe instanceof LinkedHashSet) {
57  1 safe = new LinkedHashSet(unsafe.size());
58    } else {
59  69 safe = new HashSet(unsafe.size());
60    }
61    } else {
62  37288 safe = new ArrayList(unsafe.size());
63    }
64   
65  37359 for (Object unsafeElement : unsafe) {
66  42720 safe.add(this.safeProvider.get(unsafeElement));
67    }
68   
69  37359 return (S) safe;
70    }
71    }