Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Resolves #3 - execute preconditions faster, at least 90% of Guava #4

Merged
merged 9 commits into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
language: java
sudo: false
script: mvn clean install -P '!sonar,ci' --fail-at-end
script: mvn clean install --fail-at-end
notifications:
email:
on_failure: true
jdk:
- openjdk6
- openjdk7
- oraclejdk7
- oraclejdk8
matrix:
include:
- jdk: openjdk6
env: JACOCO=true
- jdk: openjdk7
env: JACOCO=true COVERALLS=true
- jdk: oraclejdk7
env: JACOCO=true
- jdk: oraclejdk8
env: JACOCO=true
- jdk: openjdk7
env: JACOCO=true GDMSESSION=sonar
- jdk: openjdk7
env: JACOCO=true SONAR=publish
script: mvn clean install sonar:sonar --fail-at-end
- jdk: openjdk6
env: JACOCO=false
- jdk: openjdk7
env: JACOCO=false
- jdk: oraclejdk7
env: JACOCO=false
- jdk: oraclejdk8
env: JACOCO=false
23 changes: 16 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@
<sonar.java.source>${java.source.version}</sonar.java.source>
<maven.compiler.source>1.${java.source.version}</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<jacoco.version>0.7.6.201602180812</jacoco.version>

<skipTests/>
<coveralls.skip>${skipTests}</coveralls.skip>
<sonar.skip>${skipTests}</sonar.skip>
<failsafe.rerunFailingTestsCount>2</failsafe.rerunFailingTestsCount>
</properties>

<dependencies>
Expand Down Expand Up @@ -129,7 +132,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.19</version>
<version>1.7.20</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -169,7 +172,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
Expand Down Expand Up @@ -319,8 +322,13 @@

<profiles>
<profile>
<id>ci</id>

<id>jacoco</id>
<activation>
<property>
<name>env.JACOCO</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -374,13 +382,14 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.5</version>
<version>2.4.6</version>
</dependency>
</dependencies>
<configuration>
<defaults>
<sonar.issues.file>${sonar.working.directory}/${sonar.report.export.path}
</sonar.issues.file>
<sonar.skip>${sonar.skip}</sonar.skip>
</defaults>
<source>${project.basedir}/src/test/groovy/verify-sonar-issues.groovy</source>
</configuration>
Expand All @@ -399,10 +408,10 @@
</profile>

<profile>
<id>travis</id>
<id>coveralls</id>
<activation>
<property>
<name>env.TRAVIS</name>
<name>env.COVERALLS</name>
<value>true</value>
</property>
</activation>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package pl.wavesoftware.eid;

import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
* @since 2016-03-26
*/
@Nonnull
@TypeQualifierDefault(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ReturnTypesAreNonnullByDefault {
}
41 changes: 14 additions & 27 deletions src/main/java/pl/wavesoftware/eid/exceptions/Eid.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package pl.wavesoftware.eid.exceptions;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -30,7 +29,7 @@
* <p>
* Exception identifier for all Eid Runtime Exceptions.
*
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class Eid implements Serializable {

Expand All @@ -50,6 +49,8 @@ public class Eid implements Serializable {

private static final int MESSAGE_FORMAT_NUM_SPEC = 2;

private static final String EMPTY_REF = "";

private static String messageFormat = DEFAULT_MESSAGE_FORMAT;

private static UniqIdGenerator uniqIdGenerator = DEFAULT_UNIQ_ID_GENERATOR;
Expand All @@ -62,7 +63,7 @@ public class Eid implements Serializable {

private final String ref;

private final Future<String> futureUniqueId;
private String uniqueId;

/**
* Constructor
Expand All @@ -71,9 +72,8 @@ public class Eid implements Serializable {
* @param ref an optional reference
*/
public Eid(String id, @Nullable String ref) {
futureUniqueId = new UniqFuture();
this.id = id;
this.ref = ref == null ? "" : ref;
this.ref = ref == null ? EMPTY_REF : ref;
}

/**
Expand All @@ -82,7 +82,8 @@ public Eid(String id, @Nullable String ref) {
* @param id the exception id, must be unique developer inserted string, from date
*/
public Eid(String id) {
this(id, null);
this.id = id;
this.ref = EMPTY_REF;
}

/**
Expand Down Expand Up @@ -170,17 +171,17 @@ public static String setRefFormat(String refFormat) {
* @param parameters a parameters for logMessageFormat to by passed to {@link String#format(String, Object...)}
* @return a formatted message
*/
public String makeLogMessage(@Nonnull String logMessageFormat, @Nonnull Object... parameters) {
public String makeLogMessage(String logMessageFormat, Object... parameters) {
String message = String.format(logMessageFormat, parameters);
return String.format(getMessageFormat(), this.toString(), message);
}

@Override
public String toString() {
if ("".equals(ref)) {
return String.format(format, id, futureUniqueId.get());
return String.format(format, id, getUniq());
}
return String.format(refFormat, id, ref, futureUniqueId.get());
return String.format(refFormat, id, ref, getUniq());
}

/**
Expand All @@ -207,7 +208,10 @@ public String getRef() {
* @return a unique string
*/
public String getUniq() {
return futureUniqueId.get();
if (uniqueId == null) {
uniqueId = uniqIdGenerator.generateUniqId();
}
return uniqueId;
}

private static void validateFormat(String format, int numSpecifiers) {
Expand Down Expand Up @@ -241,23 +245,6 @@ public interface UniqIdGenerator {
String generateUniqId();
}

private interface Future<T extends Serializable> extends Serializable {
T get();
}

private static final class UniqFuture implements Future<String> {
private static final long serialVersionUID = 20160325113314L;
private String future;
private UniqFuture() {}
@Override
public String get() {
if (future == null) {
future = uniqIdGenerator.generateUniqId();
}
return future;
}
}

private static final class StdUniqIdGenerator implements UniqIdGenerator {

private static final int BASE36 = 36;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Indicate that object contains a Eid object
*
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public interface EidContainer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @see IllegalArgumentException
* @see EidRuntimeException
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class EidIllegalArgumentException extends EidRuntimeException {

Expand Down Expand Up @@ -85,7 +85,6 @@ public EidIllegalArgumentException(Eid id, String messageFormat, Object... param
}

/**
* @inheritdoc
* @return {@link IllegalArgumentException} class
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @see IllegalStateException
* @see EidRuntimeException
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class EidIllegalStateException extends EidRuntimeException {

Expand Down Expand Up @@ -85,7 +85,6 @@ public EidIllegalStateException(Eid id, String messageFormat, Object... paramete
}

/**
* @inheritdoc
* @return {@link IllegalStateException} class
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @see IndexOutOfBoundsException
* @see EidRuntimeException
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class EidIndexOutOfBoundsException extends EidRuntimeException {

Expand Down Expand Up @@ -85,7 +85,6 @@ public EidIndexOutOfBoundsException(Eid id, String messageFormat, Object... para
}

/**
* @inheritdoc
* @return {@link IndexOutOfBoundsException} class
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @see NullPointerException
* @see EidRuntimeException
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class EidNullPointerException extends EidRuntimeException {

Expand Down Expand Up @@ -85,7 +85,6 @@ public EidNullPointerException(Eid id, String messageFormat, Object... parameter
}

/**
* @inheritdoc
* @return {@link NullPointerException} class
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* <p>
* For convenience use {@link pl.wavesoftware.eid.utils.EidPreconditions}
*
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
*/
public class EidRuntimeException extends RuntimeException implements EidContainer {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @author <a href="mailto:krzysztof.suszynski@coi.gov.pl">Krzysztof Suszynski</a>
* @since 29.03.16
*/
@javax.annotation.ParametersAreNonnullByDefault
@pl.wavesoftware.eid.ReturnTypesAreNonnullByDefault
package pl.wavesoftware.eid.exceptions;
Loading