Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aozarov committed Jan 5, 2015
1 parent e7ce4ea commit 6019e60
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 54 deletions.
6 changes: 3 additions & 3 deletions .checkstyle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="Google Checks" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false">
<fileset name="Java source files" enabled="true" check-config-name="Google Checks" local="false">
<file-match-pattern match-pattern=".*\.java" include-pattern="true"/>
</fileset>
</fileset-config>
30 changes: 7 additions & 23 deletions pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="pmd"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>PMD Plugin preferences rule set</description>
<description>PMD Plugin preferences rule set</description>
<exclude-pattern>.*/test/.*</exclude-pattern>
<rule ref="rulesets/java/design.xml/AbstractClassWithoutAbstractMethod"/>
<rule ref="rulesets/java/design.xml/AbstractClassWithoutAnyMethod"/>
<rule ref="rulesets/java/optimizations.xml/AddEmptyString"/>
Expand All @@ -27,7 +28,6 @@
<rule ref="rulesets/java/migrating.xml/AvoidEnumAsIdentifier"/>
<rule ref="rulesets/java/controversial.xml/AvoidFinalLocalVariable"/>
<rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause"/>
<rule ref="rulesets/java/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>
<rule ref="rulesets/java/strictexception.xml/AvoidLosingExceptionInformation"/>
<rule ref="rulesets/java/basic.xml/AvoidMultipleUnaryOperators"/>
<rule ref="rulesets/java/controversial.xml/AvoidPrefixingMethodParameters"/>
Expand Down Expand Up @@ -69,23 +69,11 @@
<rule ref="rulesets/java/basic.xml/CollapsibleIfStatements"/>
<rule ref="rulesets/vm/basic.xml/CollapsibleIfStatements"/>
<rule ref="rulesets/java/comments.xml/CommentContent"/>
<rule ref="rulesets/java/comments.xml/CommentSize">
<properties>
<property name="maxLineLength" value="100"/>
</properties>
</rule>
<rule ref="rulesets/java/design.xml/CompareObjectsWithEquals"/>
<rule ref="rulesets/java/strings.xml/ConsecutiveAppendsShouldReuse"/>
<rule ref="rulesets/java/strings.xml/ConsecutiveLiteralAppends"/>
<rule ref="rulesets/ecmascript/basic.xml/ConsistentReturn"/>
<rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod"/>
<rule ref="rulesets/java/coupling.xml/CouplingBetweenObjects"/>
<rule ref="rulesets/plsql/codesize.xml/CyclomaticComplexity">
<properties>
<property name="reportLevel" value="14"/>
</properties>
</rule>
<rule ref="rulesets/java/codesize.xml/CyclomaticComplexity"/>
<rule ref="rulesets/java/design.xml/DefaultLabelNotLastInSwitchStmt"/>
<rule ref="rulesets/java/controversial.xml/DoNotCallGarbageCollectionExplicitly"/>
<rule ref="rulesets/java/j2ee.xml/DoNotCallSystemExit"/>
Expand All @@ -103,6 +91,11 @@
<rule ref="rulesets/jsp/basic.xml/DuplicateJspImports"/>
<rule ref="rulesets/java/finalizers.xml/EmptyFinalizer"/>
<rule ref="rulesets/java/empty.xml/EmptyFinallyBlock"/>
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock">
<properties>
<property name="allowCommentedBlocks" value="true"/>
</properties>
</rule>
<rule ref="rulesets/vm/basic.xml/EmptyForeachStmt"/>
<rule ref="rulesets/java/empty.xml/EmptyIfStmt"/>
<rule ref="rulesets/vm/basic.xml/EmptyIfStmt"/>
Expand All @@ -127,7 +120,6 @@
<rule ref="rulesets/plsql/codesize.xml/ExcessivePackageSpecificationLength"/>
<rule ref="rulesets/plsql/codesize.xml/ExcessiveParameterList"/>
<rule ref="rulesets/java/codesize.xml/ExcessiveParameterList"/>
<rule ref="rulesets/java/codesize.xml/ExcessivePublicCount"/>
<rule ref="rulesets/vm/basic.xml/ExcessiveTemplateLength"/>
<rule ref="rulesets/plsql/codesize.xml/ExcessiveTypeLength"/>
<rule ref="rulesets/java/basic.xml/ExtendsObject"/>
Expand Down Expand Up @@ -165,7 +157,6 @@
<rule ref="rulesets/java/junit.xml/JUnitSpelling"/>
<rule ref="rulesets/java/junit.xml/JUnitStaticSuite"/>
<rule ref="rulesets/java/junit.xml/JUnitTestsShouldIncludeAssert"/>
<rule ref="rulesets/java/migrating.xml/JUnitUseExpected"/>
<rule ref="rulesets/jsp/basic.xml/JspEncoding"/>
<rule ref="rulesets/java/basic.xml/JumbledIncrementer"/>
<rule ref="rulesets/java/j2ee.xml/LocalHomeNamingConvention"/>
Expand All @@ -185,10 +176,7 @@
<rule ref="rulesets/java/javabeans.xml/MissingSerialVersionUID"/>
<rule ref="rulesets/java/design.xml/MissingStaticMethodInNonInstantiatableClass"/>
<rule ref="rulesets/xml/basic.xml/MistypedCDATASection"/>
<rule ref="rulesets/java/codesize.xml/ModifiedCyclomaticComplexity"/>
<rule ref="rulesets/java/logging-java.xml/MoreThanOneLogger"/>
<rule ref="rulesets/plsql/codesize.xml/NPathComplexity"/>
<rule ref="rulesets/java/codesize.xml/NPathComplexity"/>
<rule ref="rulesets/java/codesize.xml/NcssConstructorCount"/>
<rule ref="rulesets/plsql/codesize.xml/NcssMethodCount"/>
<rule ref="rulesets/java/codesize.xml/NcssMethodCount"/>
Expand Down Expand Up @@ -233,7 +221,6 @@
</properties>
</rule>
<rule ref="rulesets/java/migrating.xml/ShortInstantiation"/>
<rule ref="rulesets/java/naming.xml/ShortMethodName"/>
<rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException"/>
<rule ref="rulesets/java/design.xml/SimpleDateFormatNeedsLocale"/>
<rule ref="rulesets/java/junit.xml/SimplifyBooleanAssertion"/>
Expand All @@ -243,7 +230,6 @@
<rule ref="rulesets/java/optimizations.xml/SimplifyStartsWith"/>
<rule ref="rulesets/java/design.xml/SingularField"/>
<rule ref="rulesets/java/j2ee.xml/StaticEJBFieldShouldBeFinal"/>
<rule ref="rulesets/java/codesize.xml/StdCyclomaticComplexity"/>
<rule ref="rulesets/java/strings.xml/StringBufferInstantiationWithChar"/>
<rule ref="rulesets/java/strings.xml/StringInstantiation"/>
<rule ref="rulesets/java/strings.xml/StringToString"/>
Expand Down Expand Up @@ -306,9 +292,7 @@
<rule ref="rulesets/java/optimizations.xml/UseStringBufferForStringAppends"/>
<rule ref="rulesets/java/strings.xml/UseStringBufferLength"/>
<rule ref="rulesets/java/design.xml/UseUtilityClass"/>
<rule ref="rulesets/java/design.xml/UseVarargs"/>
<rule ref="rulesets/java/basic.xml/UselessOperationOnImmutable"/>
<rule ref="rulesets/java/basic.xml/UselessOverridingMethod"/>
<rule ref="rulesets/java/basic.xml/UselessParentheses"/>
<rule ref="rulesets/java/strings.xml/UselessStringValueOf"/>
<rule ref="rulesets/java/braces.xml/WhileLoopsMustUseBraces"/>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/google/gcloud/ExceptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private static Method getCallableMethod(Class<?> clazz) {
return getCallableMethod(clazz.getSuperclass());
} catch (SecurityException e) {
// This should never happen
throw new RuntimeException("Unexpected exception", e);
throw new IllegalStateException("Unexpected exception", e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/google/gcloud/datastore/BatchWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public interface BatchWriter extends DatastoreWriter {
* @throws DatastoreServiceException if batch is no longer active
*/
@Override
public void delete(Key... key);
void delete(Key... key);

/**
* {@inheritDoc}
* This operation will also remove from this batch any prior writes for the same entities.
* @throws DatastoreServiceException if batch is no longer active
*/
@Override
public void put(Entity... entity);
void put(Entity... entity);

/**
* Submit the batch to the Datastore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

class BatchWriterImpl implements BatchWriter {

private final LinkedHashMap<Key, Entity> toAdd = new LinkedHashMap<>();
private final LinkedHashMap<Key, Entity> toUpdate = new LinkedHashMap<>();
private final LinkedHashMap<Key, Entity> toPut = new LinkedHashMap<>();
private final LinkedHashSet<Key> toDelete = new LinkedHashSet<>();
private final Map<Key, Entity> toAdd = new LinkedHashMap<>();
private final Map<Key, Entity> toUpdate = new LinkedHashMap<>();
private final Map<Key, Entity> toPut = new LinkedHashMap<>();
private final Set<Key> toDelete = new LinkedHashSet<>();
private final boolean force;
protected final DatastoreServiceImpl datastore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static DatastoreServiceException translateAndThrow(DatastoreException exception)
JSONObject error = json.getJSONObject("error").getJSONArray("errors").getJSONObject(0);
reason = error.getString("reason");
message = error.getString("message");
} catch (JSONException ex) {
} catch (JSONException ignore) {
// ignore - will be converted to unknown
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/google/gcloud/datastore/GqlQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public static final class Builder<V> {
private String namespace;
private String queryString;
private boolean allowLiteral;
private Map<String, Binding> namedBindings = new TreeMap<>();
private List<Binding> positionalBindings = new LinkedList<>();
private final Map<String, Binding> namedBindings = new TreeMap<>();
private final List<Binding> positionalBindings = new LinkedList<>();

Builder(Type<V> type, String query) {
this.type = checkNotNull(type);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/google/gcloud/datastore/Key.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,24 @@ public String toUrlSafe() {
try {
return URLEncoder.encode(toString(), UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unxpeced encoding exception", e);
throw new IllegalStateException("Unxpeced encoding exception", e);
}
}

/**
* Create a {@code Key} given its URL safe encoded form.
*
* @throws RuntimeException when decoding fails
* @throws IllegalArgumentException when decoding fails
*/
public static Key fromUrlSafe(String urlSafe) {
try {
String utf8Str = URLDecoder.decode(urlSafe, UTF_8.name());
DatastoreV1.Key keyPb = DatastoreV1.Key.parseFrom(ByteString.copyFromUtf8(utf8Str));
return fromPb(keyPb);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unxpeced decoding exception", e);
throw new IllegalStateException("Unxpeced decoding exception", e);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Could not parse key", e);
throw new IllegalArgumentException("Could not parse key", e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/google/gcloud/datastore/PartialKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static PartialKey fromPb(DatastoreV1.Key keyPb) {
}
}
List<DatastoreV1.Key.PathElement> pathElementsPb = keyPb.getPathElementList();
Preconditions.checkArgument(pathElementsPb.size() > 0, "Path must not be empty");
Preconditions.checkArgument(!pathElementsPb.isEmpty(), "Path must not be empty");
ImmutableList.Builder<PathElement> pathBuilder = ImmutableList.builder();
for (DatastoreV1.Key.PathElement pathElementPb : pathElementsPb) {
pathBuilder.add(PathElement.fromPb(pathElementPb));
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/google/gcloud/datastore/Serializable.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public String toString() {
return toPb().toString();
}

private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeObject(toPb().toByteArray());
private void writeObject(ObjectOutputStream output) throws IOException {
output.defaultWriteObject();
output.writeObject(toPb().toByteArray());
}

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
bytesPb = (byte[]) in.readObject();
private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException {
input.defaultReadObject();
bytesPb = (byte[]) input.readObject();
}

protected Object readResolve() throws ObjectStreamException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,13 @@ public static Projection first(String property) {

static class BaseBuilder<V, B extends BaseBuilder<V, B>> {

private Type<V> type;
private final Type<V> type;
private String namespace;
private String kind;
private List<Projection> projection = new LinkedList<>();
private final List<Projection> projection = new LinkedList<>();
private Filter filter;
private List<String> groupBy = new LinkedList<>();
private List<OrderBy> orderBy = new LinkedList<>();
private final List<String> groupBy = new LinkedList<>();
private final List<OrderBy> orderBy = new LinkedList<>();
private Cursor startCursor;
private Cursor endCursor;
private int offset;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/google/gcloud/storage/Acl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public interface Acl {

public class ProjectTeam {
class ProjectTeam {
// ProjectNumber: The project number.
//ProjectNumber string `json:"projectNumber,omitempty"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public void testTransactionWithRead() {
transaction.commit();
fail("Expecting a failure");
} catch (DatastoreServiceException expected) {
expected.printStackTrace();
assertEquals(DatastoreServiceException.Code.ABORTED, expected.code());
}
}
Expand All @@ -181,7 +180,6 @@ public void testTransactionWithQuery() {
transaction.commit();
fail("Expecting a failure");
} catch (DatastoreServiceException expected) {
expected.printStackTrace();
assertEquals(DatastoreServiceException.Code.ABORTED, expected.code());
}
}
Expand Down

0 comments on commit 6019e60

Please sign in to comment.