[OLINGO-575] Minor code clean up

This commit is contained in:
Michael Bolz 2015-03-10 09:47:57 +01:00
parent e1997e8e07
commit fadb6c861e
41 changed files with 108 additions and 128 deletions

View File

@ -196,33 +196,33 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<debug>true</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<postBuildHookScript>verify</postBuildHookScript>
<goals>
<goal>clean</goal>
<goal>test-compile</goal>
</goals>
</configuration>
<executions>
<execution>
<id>pojogen-integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-invoker-plugin</artifactId>-->
<!--<inherited>true</inherited>-->
<!--<configuration>-->
<!--<debug>true</debug>-->
<!--<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>-->
<!--<pomIncludes>-->
<!--<pomInclude>*/pom.xml</pomInclude>-->
<!--</pomIncludes>-->
<!--<postBuildHookScript>verify</postBuildHookScript>-->
<!--<goals>-->
<!--<goal>clean</goal>-->
<!--<goal>test-compile</goal>-->
<!--</goals>-->
<!--</configuration>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>pojogen-integration-test</id>-->
<!--<phase>integration-test</phase>-->
<!--<goals>-->
<!--<goal>integration-test</goal>-->
<!--<goal>verify</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@ -90,6 +90,32 @@ public class FunctionImportITCase extends AbstractBaseTestITCase {
}
// @Test
// public void entityCollection22() {
// final ODataInvokeRequest<ODataEntitySet> request = getClient().getInvokeRequestFactory()
// .getFunctionInvokeRequest(getClient().newURIBuilder(TecSvcConst.BASE_URI)
// .appendOperationCallSegment("FICRTCollESTwoKeyNavParam").build(), ODataEntitySet.class,
// Collections.<String, ODataValue> singletonMap("ParameterInt16",
// getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(2)));
// assertNotNull(request);
//
// final ODataInvokeResponse<ODataEntitySet> response = request.execute();
// assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
//
// final ODataEntitySet entitySet = response.getBody();
// assertNotNull(entitySet);
// final List<ODataEntity> entities = entitySet.getEntities();
// assertNotNull(entities);
// assertEquals(2, entities.size());
// final ODataEntity entity = entities.get(1);
// assertNotNull(entity);
// final ODataProperty property = entity.getProperty("PropertyString");
// assertNotNull(property);
// assertNotNull(property.getPrimitiveValue());
// assertEquals("2", property.getPrimitiveValue().toValue());
// }
@Test
public void countEntityCollection() throws Exception {
final ODataRawRequest request = getClient().getRetrieveRequestFactory()

View File

@ -23,6 +23,6 @@ public enum OnDeleteAction {
Cascade,
None,
SetNull,
SetDefault;
SetDefault
}

View File

@ -82,7 +82,7 @@ public class XMLMetadataRequestImpl
forInclusion.setAlias(schema.getAlias());
// process all edm:Annotations in each schema of the included document
for (Annotations annotationGroup : ((SchemaImpl) schema).getAnnotationGroups()) {
for (Annotations annotationGroup : schema.getAnnotationGroups()) {
// take into account only when (TargetNamespace was either not provided or matches) and
// (Qualifier was either not provided or matches)
if ((StringUtils.isBlank(include.getTargetNamespace())

View File

@ -44,7 +44,7 @@ public class JSONServiceDocumentDeserializer extends JsonDeserializer {
protected ResWrap<ServiceDocument> doDeserialize(final JsonParser parser) throws IOException {
final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
final ObjectNode tree = parser.getCodec().readTree(parser);
ServiceDocumentImpl serviceDocument = new ServiceDocumentImpl();

View File

@ -77,23 +77,11 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper {
@Override
public boolean isOpenType() {
boolean isOpen = false;
if (structuralType instanceof ComplexType) {
isOpen = ((ComplexType) structuralType).isOpenType();
} else if (structuralType instanceof EntityType) {
isOpen = ((EntityType) structuralType).isOpenType();
}
return isOpen;
return structuralType.isOpenType();
}
@Override
public boolean isAbstract() {
boolean isAbstract = false;
if (structuralType instanceof ComplexType) {
isAbstract = ((ComplexType) structuralType).isAbstractType();
} else if (structuralType instanceof EntityType) {
isAbstract = ((EntityType) structuralType).isAbstractType();
}
return isAbstract;
return structuralType.isAbstractType();
}
}

View File

@ -85,7 +85,7 @@ public class EnumTypeImpl extends AbstractEdmItem implements EnumType, Annotatab
public Member getMember(final Integer value) {
Member result = null;
for (Member member : getMembers()) {
if (value.equals(member.getValue())) {
if (String.valueOf(value).equals(member.getValue())) {
result = member;
}
}

View File

@ -327,12 +327,11 @@ public class ODataBinderImpl implements ODataBinder {
@Override
public Property getProperty(final ODataProperty property) {
final ODataProperty _property = property;
final Property propertyResource = new PropertyImpl();
propertyResource.setName(_property.getName());
updateValuable(propertyResource, _property);
annotations(_property, propertyResource);
propertyResource.setName(property.getName());
updateValuable(propertyResource, property);
annotations(property, propertyResource);
return propertyResource;
}

View File

@ -285,9 +285,8 @@ public class URIBuilderImpl implements URIBuilder {
}
try {
StringBuilder sb = segmentsBuilder;
if ((queryOptions.size() + parameters.size()) > 0) {
sb.append("?");
segmentsBuilder.append("?");
List<NameValuePair> list1 = new LinkedList<NameValuePair>();
for (Map.Entry<String, String> option : queryOptions.entrySet()) {
list1.add(new BasicNameValuePair("$" + option.getKey(), option.getValue()));
@ -301,10 +300,10 @@ public class URIBuilderImpl implements URIBuilder {
// which works in desktop java application, however, throws NoSuchMethodError in android OS,
// so here manually construct the URL by its overload URLEncodedUtils.format(List<>,String).
final String queryStr = encodeQueryParameter(list1);
sb.append(queryStr);
segmentsBuilder.append(queryStr);
}
return URI.create(sb.toString());
return URI.create(segmentsBuilder.toString());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not build valid URI", e);
}

View File

@ -194,7 +194,7 @@ public final class URIUtils {
if (obj == null) {
value = Constants.ATTR_NULL;
} else if (obj instanceof Collection) {
final StringBuffer buffer = new StringBuffer("[");
final StringBuilder buffer = new StringBuilder("[");
for (@SuppressWarnings("unchecked")
final Iterator<Object> itor = ((Collection<Object>) obj).iterator(); itor.hasNext();) {
buffer.append(escape(itor.next(), false));
@ -206,7 +206,7 @@ public final class URIUtils {
value = buffer.toString();
} else if (obj instanceof Map) {
final StringBuffer buffer = new StringBuffer("{");
final StringBuilder buffer = new StringBuilder("{");
for (@SuppressWarnings("unchecked")
final Iterator<Map.Entry<String, Object>> itor =
((Map<String, Object>) obj).entrySet().iterator(); itor.hasNext();) {

View File

@ -25,7 +25,7 @@ public interface DeletedEntity {
enum Reason {
deleted,
changed;
changed
}

View File

@ -25,7 +25,7 @@ public interface ODataDeletedEntity {
enum Reason {
deleted,
changed;
changed
}

View File

@ -102,8 +102,7 @@ public enum EdmPrimitiveTypeKind {
throw new IllegalArgumentException(fqn + " does not look like an Edm primitive type");
}
final EdmPrimitiveTypeKind kind = valueOf(fqn.substring(4));
return kind;
return valueOf(fqn.substring(4));
}
}

View File

@ -25,6 +25,6 @@ public enum EdmContentKind {
text,
html,
xhtml;
xhtml
}

View File

@ -20,6 +20,6 @@ package org.apache.olingo.commons.api.edm.constants;
public enum EdmOnDelete {
Cascade, None, SetNull, SetDefault;
Cascade, None, SetNull, SetDefault
}

View File

@ -23,6 +23,6 @@ package org.apache.olingo.commons.api.edm.constants;
*/
public enum EdmTypeKind {
UNDEFINED, PRIMITIVE, ENUM, DEFINITION, COMPLEX, ENTITY, NAVIGATION, ACTION, FUNCTION, SYSTEM;
UNDEFINED, PRIMITIVE, ENUM, DEFINITION, COMPLEX, ENTITY, NAVIGATION, ACTION, FUNCTION, SYSTEM
}

View File

@ -36,7 +36,7 @@ public abstract class Geospatial implements Serializable {
public enum Dimension {
GEOMETRY,
GEOGRAPHY;
GEOGRAPHY
}
@ -69,7 +69,7 @@ public abstract class Geospatial implements Serializable {
/**
* The OGIS geometry type number for feature collections.
*/
GEOSPATIALCOLLECTION;
GEOSPATIALCOLLECTION
}

View File

@ -28,6 +28,6 @@ public enum HttpMethod {
PUT,
PATCH,
MERGE,
DELETE;
DELETE
}

View File

@ -68,11 +68,10 @@ public final class EdmDecimal extends SingletonPrimitiveType {
}
private static boolean validateLiteral(final String value) {
boolean valid = PATTERN.matcher(value).matches();
return valid;
return PATTERN.matcher(value).matches();
}
private static final boolean validatePrecisionAndScale(final String value, final Integer precision,
private static boolean validatePrecisionAndScale(final String value, final Integer precision,
final Integer scale) {
final Matcher matcher = PATTERN.matcher(value);

View File

@ -133,7 +133,7 @@ public final class EdmDouble extends SingletonPrimitiveType {
} else if (value instanceof BigDecimal) {
final double doubleValue = ((BigDecimal) value).doubleValue();
if (!Double.isInfinite(doubleValue) && BigDecimal.valueOf(doubleValue).compareTo((BigDecimal) value) == 0) {
return ((BigDecimal) value).toString();
return value.toString();
} else {
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}

View File

@ -123,7 +123,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
return (Double) value == Double.NEGATIVE_INFINITY ? EdmDouble.NEGATIVE_INFINITY : EdmDouble.POSITIVE_INFINITY;
} else {
final String floatString = Float.toString(((Double) value).floatValue());
if (floatString.equals(((Double) value).toString())) {
if (floatString.equals(value.toString())) {
return floatString;
} else {
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
@ -135,7 +135,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
} else if (value instanceof BigDecimal) {
final float floatValue = ((BigDecimal) value).floatValue();
if (!Float.isInfinite(floatValue) && BigDecimal.valueOf(floatValue).compareTo((BigDecimal) value) == 0) {
return ((BigDecimal) value).toString();
return value.toString();
} else {
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}

View File

@ -673,7 +673,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
entity.getOperations().add(operation);
} else if (Constants.QNAME_ATOM_ELEM_CONTENT.equals(event.asStartElement().getName())) {
final Attribute type = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TYPE));
if (type == null || ContentType.APPLICATION_XML.equals(type.getValue())) {
if (type == null || ContentType.APPLICATION_XML.toContentTypeString().equals(type.getValue())) {
properties(reader, skipBeforeFirstStartElement(reader), entity);
} else {
entity.setMediaContentType(type.getValue());

View File

@ -170,7 +170,7 @@ public class JsonEntityDeserializer extends JsonDeserializer {
final String linkTitle = getTitle(field);
for (Link link : entity.getMediaEditLinks()) {
if (linkTitle.equals(link.getTitle())) {
((LinkImpl) link).setType(field.getValue().asText());
link.setType(field.getValue().asText());
}
}
toRemove.add(field.getKey());

View File

@ -39,7 +39,7 @@ public class JsonEntitySetSerializer extends JsonSerializer {
protected void doSerialize(final EntitySet entitySet, final JsonGenerator jgen)
throws IOException, EdmPrimitiveTypeException {
doContainerSerialize(new ResWrap<EntitySet>((URI) null, null, entitySet), jgen);
doContainerSerialize(new ResWrap<EntitySet>(null, null, entitySet), jgen);
}
protected void doContainerSerialize(final ResWrap<EntitySet> container, final JsonGenerator jgen)

View File

@ -49,7 +49,7 @@ public class JsonPropertyDeserializer extends JsonDeserializer {
protected ResWrap<Property> doDeserialize(final JsonParser parser) throws IOException {
final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
final ObjectNode tree = parser.getCodec().readTree(parser);
final String metadataETag;
final URI contextURL;

View File

@ -46,7 +46,7 @@ public class EntitySerializerOptions {
private EntitySerializerOptions() {}
/** Initializes the options builder. */
public static final Builder with() {
public static Builder with() {
return new Builder();
}

View File

@ -63,5 +63,5 @@ public enum UriInfoKind {
* Class: {@link UriInfoService}<br>
* URI: http://.../serviceroot
*/
service;
service
}

View File

@ -119,8 +119,7 @@ public class ODataExceptionHelper {
}
private static ODataServerError basicServerError(Exception e) {
ODataServerError serverError = new ODataServerError().setException(e).setMessage(e.getMessage());
return serverError;
return new ODataServerError().setException(e).setMessage(e.getMessage());
}
private static ODataServerError basicTranslatedError(ODataTranslatedException e, Locale requestedLocale) {

View File

@ -36,7 +36,7 @@ public class FixedFormatDeserializerImpl implements FixedFormatDeserializer {
public byte[] binary(InputStream content) throws DeserializerException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[128];
int count = -1;
int count;
try {
while ((count = content.read(buffer)) > -1) {
result.write(buffer, 0, count);

View File

@ -38,8 +38,7 @@ public class EdmComplexTypeImpl extends AbstractEdmComplexType {
public static EdmComplexTypeImpl getInstance(
final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
final EdmComplexTypeImpl instance = new EdmComplexTypeImpl(edm, name, complexType);
return instance;
return new EdmComplexTypeImpl(edm, name, complexType);
}
private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName name, final ComplexType complexType) {

View File

@ -46,8 +46,7 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName name,
final EntityType entityType) {
final EdmEntityTypeImpl instance = new EdmEntityTypeImpl(edm, name, entityType);
return instance;
return new EdmEntityTypeImpl(edm, name, entityType);
}
private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName name, final EntityType entityType) {

View File

@ -121,7 +121,7 @@ public class BatchResponseSerializer {
}
private void appendChangeSetHeader(StringBuilder builder, final String changeSetBoundary) {
appendHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED.toString() + "; boundary="
appendHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + "; boundary="
+ changeSetBoundary, builder);
}
@ -136,7 +136,7 @@ public class BatchResponseSerializer {
private void appendStatusLine(ODataResponse response, StringBuilder builder) {
builder.append("HTTP/1.1")
.append(SP)
.append("" + response.getStatusCode())
.append(response.getStatusCode())
.append(SP)
.append(HttpStatusCode.fromStatusCode(response.getStatusCode()).toString())
.append(CRLF);

View File

@ -59,8 +59,6 @@ public class UriResourceLambdaAllImpl extends UriResourceTypedImpl implements Ur
return this;
}
;
@Override
public Expression getExpression() {
return expression;
@ -71,8 +69,6 @@ public class UriResourceLambdaAllImpl extends UriResourceTypedImpl implements Ur
return this;
}
;
@Override
public String toString() {
return "all";

View File

@ -59,8 +59,6 @@ public class UriResourceLambdaAnyImpl extends UriResourceTypedImpl implements Ur
return this;
}
;
@Override
public Expression getExpression() {
return expression;
@ -74,5 +72,5 @@ public class UriResourceLambdaAnyImpl extends UriResourceTypedImpl implements Ur
@Override
public String toString() {
return "any";
};
}
}

View File

@ -69,7 +69,7 @@ public class Parser {
private enum ParserEntryRules {
All, Batch, CrossJoin, Entity, ExpandItems, FilterExpression, Metadata, PathSegment, Orderby, Select
};
}
public Parser setLogLevel(final int logLevel) {
this.logLevel = logLevel;
@ -162,10 +162,7 @@ public class Parser {
FilterExpressionEOFContext ctxFilterExpression =
(FilterExpressionEOFContext) parseRule(option.value, ParserEntryRules.FilterExpression);
FilterOptionImpl filterOption =
(FilterOptionImpl) uriParseTreeVisitor.visitFilterExpressionEOF(ctxFilterExpression);
systemOption = filterOption;
systemOption = (FilterOptionImpl) uriParseTreeVisitor.visitFilterExpressionEOF(ctxFilterExpression);
} else if (option.name.equals(SystemQueryOptionKind.FORMAT.toString())) {
FormatOptionImpl formatOption = new FormatOptionImpl();
@ -186,10 +183,7 @@ public class Parser {
ExpandItemsEOFContext ctxExpandItems =
(ExpandItemsEOFContext) parseRule(option.value, ParserEntryRules.ExpandItems);
ExpandOptionImpl expandOption =
(ExpandOptionImpl) uriParseTreeVisitor.visitExpandItemsEOF(ctxExpandItems);
systemOption = expandOption;
systemOption = (ExpandOptionImpl) uriParseTreeVisitor.visitExpandItemsEOF(ctxExpandItems);
} else if (option.name.equals(SystemQueryOptionKind.ID.toString())) {
IdOptionImpl idOption = new IdOptionImpl();
@ -204,20 +198,14 @@ public class Parser {
OrderByEOFContext ctxOrderByExpression =
(OrderByEOFContext) parseRule(option.value, ParserEntryRules.Orderby);
OrderByOptionImpl orderByOption =
(OrderByOptionImpl) uriParseTreeVisitor.visitOrderByEOF(ctxOrderByExpression);
systemOption = orderByOption;
systemOption = (OrderByOptionImpl) uriParseTreeVisitor.visitOrderByEOF(ctxOrderByExpression);
} else if (option.name.equals(SystemQueryOptionKind.SEARCH.toString())) {
throw new RuntimeException("System query option '$search' not implemented!");
} else if (option.name.equals(SystemQueryOptionKind.SELECT.toString())) {
SelectEOFContext ctxSelectEOF =
(SelectEOFContext) parseRule(option.value, ParserEntryRules.Select);
SelectOptionImpl selectOption =
(SelectOptionImpl) uriParseTreeVisitor.visitSelectEOF(ctxSelectEOF);
systemOption = selectOption;
systemOption = (SelectOptionImpl) uriParseTreeVisitor.visitSelectEOF(ctxSelectEOF);
} else if (option.name.equals(SystemQueryOptionKind.SKIP.toString())) {
SkipOptionImpl skipOption = new SkipOptionImpl();
skipOption.setName(option.name);

View File

@ -87,7 +87,6 @@ public class UriDecoder {
// Empty path segments of the resource path are removed.
while (list.remove("")) {
// this place intentionally left blank
;
}
return skipSegments > 0 ? list.subList(skipSegments, list.size()) : list;

View File

@ -666,8 +666,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
@Override
public Object visitAllEOF(final AllEOFContext ctx) {
UriInfoImpl crossJoin = new UriInfoImpl().setKind(UriInfoKind.all);
context.contextUriInfo = crossJoin;
context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.all);
return null;
}
@ -861,9 +860,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
@Override
public Object visitMetadataEOF(final MetadataEOFContext ctx) {
UriInfoImpl uriInfo = new UriInfoImpl().setKind(UriInfoKind.metadata);
context.contextUriInfo = uriInfo;
context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.metadata);
return null;
}
@ -1259,15 +1257,13 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
@Override
public Object visitFilter(final FilterContext ctx) {
FilterOptionImpl filter = new FilterOptionImpl().setExpression((ExpressionImpl) ctx.children.get(2).accept(this));
return filter;
return new FilterOptionImpl().setExpression((ExpressionImpl) ctx.children.get(2).accept(this));
}
@Override
public Object visitFilterExpressionEOF(final FilterExpressionEOFContext ctx) {
FilterOptionImpl filter = new FilterOptionImpl().setExpression((ExpressionImpl) ctx.children.get(0).accept(this));
return filter;
return new FilterOptionImpl().setExpression((ExpressionImpl) ctx.children.get(0).accept(this));
}
@Override

View File

@ -127,7 +127,7 @@ public class TypedOperand extends VisitorOperand {
return asTypedOperand(EdmInt64.getInstance());
} else if (type.equals(EdmInt32.getInstance()) || oType.equals(EdmInt32.getInstance())) {
return asTypedOperand(EdmInt32.getInstance());
} else if (type.equals(EdmInt16.getInstance()) || oType.equals(equals(EdmInt16.getInstance()))) {
} else if (type.equals(EdmInt16.getInstance()) || oType.equals(EdmInt16.getInstance())) {
return asTypedOperand(EdmInt16.getInstance());
} else {
return asTypedOperand((EdmPrimitiveType) type);

View File

@ -112,10 +112,9 @@ public class ExpandValidator implements TestValidator {
}
public ExpandValidator goExpand() {
ExpandValidator val = new ExpandValidator()
return new ExpandValidator()
.setExpand((ExpandOptionImpl) expandItem.getExpandOption())
.setUpValidator(this);
return val;
}
public ExpandValidator first() {

View File

@ -62,7 +62,7 @@ public class FilterTreeToText implements ExpressionVisitor<String> {
public String visitUnaryOperator(final UnaryOperatorKind operator, final String operand)
throws ExpressionVisitException {
return "<" + operator + " " + operand.toString() + ">";
return "<" + operator + " " + operand + ">";
}
@Override
@ -90,9 +90,7 @@ public class FilterTreeToText implements ExpressionVisitor<String> {
public String visitMember(final UriInfoResource resource) throws ExpressionVisitException, ODataApplicationException {
String ret = "";
UriInfoResource path = resource;
for (UriResource item : path.getUriResourceParts()) {
for (UriResource item : resource.getUriResourceParts()) {
String tmp = "";
if (item instanceof UriResourceLambdaAll) {
UriResourceLambdaAll all = (UriResourceLambdaAll) item;

View File

@ -67,8 +67,7 @@ public class ParseTreeToText {
} else if (t instanceof TerminalNode) {
Token symbol = ((TerminalNode) t).getSymbol();
if (symbol != null) {
String s = symbol.getText();
return s;
return symbol.getText();
}
}
}