Skip to content

Commit ea568d1

Browse files
committed
Migrate guava logic to java 8
1 parent c0af9de commit ea568d1

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

modules/swagger-codegen/src/main/java/config/Config.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config;
22

3-
import com.google.common.collect.ImmutableMap;
4-
3+
import java.util.Collections;
54
import java.util.HashMap;
65
import java.util.Map;
76

@@ -17,7 +16,7 @@ public Config(Map<String, String> properties) {
1716
}
1817

1918
public Map<String, String> getOptions() {
20-
return ImmutableMap.copyOf(options);
19+
return Collections.unmodifiableMap(options);
2120
}
2221

2322
public boolean hasOption(String opt) {

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.swagger.codegen;
22

33
import com.github.jknack.handlebars.Handlebars;
4-
import com.google.common.base.Function;
5-
import com.google.common.collect.Lists;
64
import com.samskivert.mustache.Mustache.Compiler;
75
import io.swagger.codegen.languages.helpers.HasHelper;
86
import io.swagger.codegen.languages.helpers.HasNotHelper;
@@ -41,14 +39,11 @@
4139
import io.swagger.v3.oas.models.security.OAuthFlows;
4240
import io.swagger.v3.oas.models.security.SecurityScheme;
4341
import io.swagger.v3.parser.util.SchemaTypeUtil;
44-
import org.apache.commons.lang3.ArrayUtils;
4542
import org.apache.commons.lang3.ObjectUtils;
4643
import org.apache.commons.lang3.StringEscapeUtils;
4744
import org.apache.commons.lang3.StringUtils;
4845
import org.slf4j.Logger;
4946
import org.slf4j.LoggerFactory;
50-
51-
import javax.annotation.Nullable;
5247
import java.io.File;
5348
import java.util.ArrayList;
5449
import java.util.Arrays;
@@ -66,15 +61,15 @@
6661
import java.util.regex.Pattern;
6762
import java.util.stream.Collectors;
6863

69-
import static io.swagger.codegen.CodegenHelper.getDefaultIncludes;
70-
import static io.swagger.codegen.CodegenHelper.getImportMappings;
71-
import static io.swagger.codegen.CodegenHelper.getTypeMappings;
72-
import static io.swagger.codegen.CodegenHelper.initalizeSpecialCharacterMapping;
7364
import static io.swagger.codegen.CodegenConstants.HAS_ONLY_READ_ONLY_EXT_NAME;
7465
import static io.swagger.codegen.CodegenConstants.HAS_OPTIONAL_EXT_NAME;
7566
import static io.swagger.codegen.CodegenConstants.HAS_REQUIRED_EXT_NAME;
7667
import static io.swagger.codegen.CodegenConstants.IS_ARRAY_MODEL_EXT_NAME;
7768
import static io.swagger.codegen.CodegenConstants.IS_ENUM_EXT_NAME;
69+
import static io.swagger.codegen.CodegenHelper.getDefaultIncludes;
70+
import static io.swagger.codegen.CodegenHelper.getImportMappings;
71+
import static io.swagger.codegen.CodegenHelper.getTypeMappings;
72+
import static io.swagger.codegen.CodegenHelper.initalizeSpecialCharacterMapping;
7873
import static io.swagger.codegen.languages.helpers.ExtensionHelper.getBooleanValue;
7974
import static io.swagger.codegen.utils.ModelUtils.processCodegenModels;
8075
import static io.swagger.codegen.utils.ModelUtils.processModelEnums;
@@ -2818,13 +2813,9 @@ public String removeNonNameElementToCamelCase(String name) {
28182813
* @return camelized string
28192814
*/
28202815
protected String removeNonNameElementToCamelCase(final String name, final String nonNameElementPattern) {
2821-
String result = StringUtils.join(Lists.transform(Lists.newArrayList(name.split(nonNameElementPattern)), new Function<String, String>() {
2822-
@Nullable
2823-
@Override
2824-
public String apply(String input) {
2825-
return StringUtils.capitalize(input);
2826-
}
2827-
}), "");
2816+
String result = Arrays.stream(name.split(nonNameElementPattern))
2817+
.map(StringUtils::capitalize)
2818+
.collect(Collectors.joining(""));
28282819
if (result.length() > 0) {
28292820
result = result.substring(0, 1).toLowerCase() + result.substring(1);
28302821
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/ignore/CodegenIgnoreProcessor.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package io.swagger.codegen.ignore;
22

3-
import com.google.common.collect.ImmutableList;
43
import io.swagger.codegen.ignore.rules.DirectoryRule;
54
import io.swagger.codegen.ignore.rules.Rule;
65
import org.slf4j.Logger;
76
import org.slf4j.LoggerFactory;
87

9-
import java.io.*;
8+
import java.io.BufferedReader;
9+
import java.io.File;
10+
import java.io.FileReader;
11+
import java.io.IOException;
1012
import java.util.ArrayList;
11-
import java.util.Collection;
13+
import java.util.Collections;
1214
import java.util.List;
1315

1416
/**
@@ -173,10 +175,10 @@ public boolean allowsFile(final File targetFile) {
173175
/**
174176
* Allows a consumer to manually inspect explicit "inclusion rules". That is, patterns in the ignore file which have been negated.
175177
*
176-
* @return A {@link ImmutableList#copyOf(Collection)} of rules which possibly negate exclusion rules in the ignore file.
178+
* @return A unmodifiable {@link java.util.List} of rules which possibly negate exclusion rules in the ignore file.
177179
*/
178180
public List<Rule> getInclusionRules() {
179-
return ImmutableList.copyOf(inclusionRules);
181+
return Collections.unmodifiableList(inclusionRules);
180182
}
181183

182184
/**
@@ -185,9 +187,9 @@ public List<Rule> getInclusionRules() {
185187
*
186188
* NOTE: Existence in this list doesn't mean a file is excluded. The rule can be overridden by {@link CodegenIgnoreProcessor#getInclusionRules()} rules.
187189
*
188-
* @return A {@link ImmutableList#copyOf(Collection)} of rules which define exclusions by patterns in the ignore file.
190+
* @return A unmodifiable {@link java.util.List} of rules which define exclusions by patterns in the ignore file.
189191
*/
190192
public List<Rule> getExclusionRules() {
191-
return ImmutableList.copyOf(exclusionRules);
193+
return Collections.unmodifiableList(exclusionRules);
192194
}
193195
}

0 commit comments

Comments
 (0)