Skip to content

Commit

Permalink
remove detected code smells camel-tooling#34
Browse files Browse the repository at this point in the history
Signed-off-by: Lars Heinemann <lhein.smx@gmail.com>
  • Loading branch information
lhein committed Nov 12, 2018
1 parent e3ce4d6 commit e6378f8
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 147 deletions.
78 changes: 78 additions & 0 deletions src/main/java/com/github/cameltooling/model/BaseOptionModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* 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 com.github.cameltooling.model;

/**
* @author lheinema
*/
public class BaseOptionModel {

private String name;
private String kind;
private String group;
private String required;
private String type;
private String javaType;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getKind() {
return kind;
}

public void setKind(String kind) {
this.kind = kind;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}

public String getRequired() {
return required;
}

public void setRequired(String required) {
this.required = required;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getJavaType() {
return javaType;
}

public void setJavaType(String javaType) {
this.javaType = javaType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,68 +16,14 @@
*/
package com.github.cameltooling.model;

public class ComponentOptionModel {
public class ComponentOptionModel extends BaseOptionModel{

private String name;
private String kind;
private String group;
private String required;
private String type;
private String javaType;
private String deprecated;
private String secret;
private String description;
private String defaultValue;
private String enums;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getKind() {
return kind;
}

public void setKind(String kind) {
this.kind = kind;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}

public String getRequired() {
return required;
}

public void setRequired(String required) {
this.required = required;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getJavaType() {
return javaType;
}

public void setJavaType(String javaType) {
this.javaType = javaType;
}

public String getDeprecated() {
return deprecated;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@
*/
package com.github.cameltooling.model;

public class EndpointOptionModel {
public class EndpointOptionModel extends BaseOptionModel {

private String name;
private String kind;
private String group;
private String label;
private String required;
private String type;
private String javaType;
private String enums;
private String prefix;
private String multiValue;
Expand All @@ -34,29 +28,6 @@ public class EndpointOptionModel {
private String description;
private String enumValues;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getKind() {
return kind;
}

public void setKind(String kind) {
this.kind = kind;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}

public String getLabel() {
return label;
Expand All @@ -66,30 +37,6 @@ public void setLabel(String label) {
this.label = label;
}

public String getRequired() {
return required;
}

public void setRequired(String required) {
this.required = required;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getJavaType() {
return javaType;
}

public void setJavaType(String javaType) {
this.javaType = javaType;
}

public String getEnums() {
return enums;
}
Expand Down Expand Up @@ -153,5 +100,4 @@ public String getEnumValues() {
public void setEnumValues(String enumValues) {
this.enumValues = enumValues;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public interface CamelDiagnosticEndpointMessage<T> {
*
* @param endpointValidationResult - The validation result return from the {@link org.apache.camel.catalog.CamelCatalog} validator
* @param valueObj - The key and value object validated.
* @return the error message
*/
String getErrorMessage(EndpointValidationResult endpointValidationResult, T valueObj);

Expand Down
22 changes: 13 additions & 9 deletions src/main/java/com/github/cameltooling/model/util/ModelHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

public final class ModelHelper {

private static final String DESCRIPTION = "description";
private static final String DEPRECATED = "deprecated";
private static final String JAVA_TYPE = "javaType";

private ModelHelper() {
// utility class
}
Expand All @@ -42,12 +46,12 @@ public static ComponentModel generateComponentModel(String json, boolean include
component.setAlternativeSyntax(getSafeValue("alternativeSyntax", rows));
component.setAlternativeSchemes(getSafeValue("alternativeSchemes", rows));
component.setTitle(getSafeValue("title", rows));
component.setDescription(getSafeValue("description", rows));
component.setDescription(getSafeValue(DESCRIPTION, rows));
component.setLabel(getSafeValue("label", rows));
component.setDeprecated(getSafeValue("deprecated", rows));
component.setDeprecated(getSafeValue(DEPRECATED, rows));
component.setConsumerOnly(getSafeValue("consumerOnly", rows));
component.setProducerOnly(getSafeValue("producerOnly", rows));
component.setJavaType(getSafeValue("javaType", rows));
component.setJavaType(getSafeValue(JAVA_TYPE, rows));
component.setGroupId(getSafeValue("groupId", rows));
component.setArtifactId(getSafeValue("artifactId", rows));
component.setVersion(getSafeValue("version", rows));
Expand All @@ -61,12 +65,12 @@ public static ComponentModel generateComponentModel(String json, boolean include
option.setGroup(getSafeValue("group", row));
option.setRequired(getSafeValue("required", row));
option.setType(getSafeValue("type", row));
option.setJavaType(getSafeValue("javaType", row));
option.setJavaType(getSafeValue(JAVA_TYPE, row));
option.setEnums(getSafeValue("enum", row));
option.setDeprecated(getSafeValue("deprecated", row));
option.setDeprecated(getSafeValue(DEPRECATED, row));
option.setSecret(getSafeValue("secret", row));
option.setDefaultValue(getSafeValue("defaultValue", row));
option.setDescription(getSafeValue("description", row));
option.setDescription(getSafeValue(DESCRIPTION, row));
component.addComponentOption(option);
}

Expand All @@ -79,14 +83,14 @@ public static ComponentModel generateComponentModel(String json, boolean include
option.setLabel(getSafeValue("label", row));
option.setRequired(getSafeValue("required", row));
option.setType(getSafeValue("type", row));
option.setJavaType(getSafeValue("javaType", row));
option.setJavaType(getSafeValue(JAVA_TYPE, row));
option.setEnums(getSafeValue("enum", row));
option.setPrefix(getSafeValue("prefix", row));
option.setMultiValue(getSafeValue("multiValue", row));
option.setDeprecated(getSafeValue("deprecated", row));
option.setDeprecated(getSafeValue(DEPRECATED, row));
option.setSecret(getSafeValue("secret", row));
option.setDefaultValue(getSafeValue("defaultValue", row));
option.setDescription(getSafeValue("description", row));
option.setDescription(getSafeValue(DESCRIPTION, row));
component.addEndpointOption(option);
}
}
Expand Down
59 changes: 31 additions & 28 deletions src/main/java/com/github/cameltooling/model/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ public static String wrapSeparator(String line, String separator, String newLine
* @return wrapped line
*/
public static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords) {
if (line == null) {
return null;
} else {
if (line != null) {
if (newLine == null) {
newLine = System.lineSeparator();
}
Expand All @@ -170,40 +168,45 @@ public static String wrapWords(String line, String newLine, int watermark, boole
watermark = 1;
}

int inputLineLength = line.length();
int offset = 0;
StringBuilder sb = new StringBuilder(inputLineLength + 32);

while (inputLineLength - offset > watermark) {
if (line.charAt(offset) == 32) {
++offset;
return doWordWrap(line, newLine, watermark, wrapLongWords);
}
return null;
}

private static String doWordWrap(String line, String newLine, int watermark, boolean wrapLongWords) {
int inputLineLength = line.length();
int offset = 0;
StringBuilder sb = new StringBuilder(inputLineLength + 32);

while (inputLineLength - offset > watermark) {
if (line.charAt(offset) == 32) {
++offset;
} else {
int spaceToWrapAt = line.lastIndexOf(32, watermark + offset);
if (spaceToWrapAt >= offset) {
sb.append(line.substring(offset, spaceToWrapAt));
sb.append(newLine);
offset = spaceToWrapAt + 1;
} else if (wrapLongWords) {
sb.append(line.substring(offset, watermark + offset));
sb.append(newLine);
offset += watermark;
} else {
int spaceToWrapAt = line.lastIndexOf(32, watermark + offset);
if (spaceToWrapAt >= offset) {
spaceToWrapAt = line.indexOf(32, watermark + offset);
if (spaceToWrapAt >= 0) {
sb.append(line.substring(offset, spaceToWrapAt));
sb.append(newLine);
offset = spaceToWrapAt + 1;
} else if (wrapLongWords) {
sb.append(line.substring(offset, watermark + offset));
sb.append(newLine);
offset += watermark;
} else {
spaceToWrapAt = line.indexOf(32, watermark + offset);
if (spaceToWrapAt >= 0) {
sb.append(line.substring(offset, spaceToWrapAt));
sb.append(newLine);
offset = spaceToWrapAt + 1;
} else {
sb.append(line.substring(offset));
offset = inputLineLength;
}
sb.append(line.substring(offset));
offset = inputLineLength;
}
}
}

sb.append(line.substring(offset));
return sb.toString();
}

sb.append(line.substring(offset));
return sb.toString();
}

/**
Expand Down

0 comments on commit e6378f8

Please sign in to comment.