Skip to content

Commit

Permalink
Fixed checkstyle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Family authored and Family committed Oct 5, 2020
1 parent 4bafd94 commit 4ab7d29
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 53 deletions.
71 changes: 36 additions & 35 deletions src/main/java/org/apache/commons/collections4/MapBuilder.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.collections4;

import org.apache.commons.collections4.map.HashedMap;

import java.util.*;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.Collections;

/**
* Defines an Helper Builder that generates a {@code Map}
Expand All @@ -36,13 +38,13 @@ Licensed to the Apache Software Foundation (ASF) under one
* }</pre>
*
*/
public class MapBuilder<K,V> {
public class MapBuilder<K, V> {

private Comparator<? super K> comparator;
private KeyOrder iterationOrder;
private boolean synchronizedMap;
private boolean immutable;
private Map<K,V> data;
private Map<K, V> data;

public MapBuilder() {
comparator = null;
Expand Down Expand Up @@ -96,37 +98,36 @@ public MapBuilder setData(Map data) {
Builder Method which takes care of all the conditions and returns the required Map.
*/
public Map build() {
Map<K,V> map;
Map<K, V> map;
switch (iterationOrder) {
case NATURAL_ORDER :
case COMPARATOR_ORDER:
map = new TreeMap(comparator);
break;
case INSERTION_ORDER :
map = new LinkedHashMap();
break;
default:
map = new HashedMap();
break;
case NATURAL_ORDER :
case COMPARATOR_ORDER:
map = new TreeMap(comparator);
break;
case INSERTION_ORDER :
map = new LinkedHashMap();
break;
default:
map = new HashedMap();
break;
}

if(MapUtils.isNotEmpty(data)) {
if (MapUtils.isNotEmpty(data)) {
map.putAll(data);
}

if(synchronizedMap) {
if (synchronizedMap) {
map = Collections.synchronizedMap(map);
}

if(immutable) {
if (immutable) {
map = Collections.unmodifiableMap(map);
}

return map;
}

enum KeyOrder
{
enum KeyOrder {
UNORDERED, NATURAL_ORDER, INSERTION_ORDER, COMPARATOR_ORDER;
}
}
34 changes: 16 additions & 18 deletions src/test/java/org/apache/commons/collections4/MapBuilderTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.collections4;

Expand All @@ -28,7 +26,7 @@ Licensed to the Apache Software Foundation (ASF) under one
/**
* Test Cases for Map Builder
*/
class MapBuilderTest {
public class MapBuilderTest {

@Test
void setComparator() {
Expand Down Expand Up @@ -135,4 +133,4 @@ void build() {
Map<String, Integer> builderMap = new MapBuilder().build();
Assert.assertTrue(builderMap.size() == 0);
}
}
}

0 comments on commit 4ab7d29

Please sign in to comment.