Skip to content

Commit

Permalink
Some code cleanup to use Java 7 language features, add annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerd committed Jan 3, 2016
1 parent 9afa895 commit 718526c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.xml
Expand Up @@ -34,7 +34,7 @@
<property name="jmf" value="jmf.jar" />
<property name="bc" value="bcprov-jdk15on-148.jar" />
<property name="bccontrib" value="bccontrib-1.0-SNAPSHOT.jar" />
<property name="junit" value="junit.jar" />
<property name="junit" value="junit-3.8.1.jar" />

<!-- set the path ids to use in the compile targets. To compile
we need some 3rd party libs.
Expand Down
2 changes: 0 additions & 2 deletions src/gnu/java/bigintcrypto/test/BigIntegerTest.java
Expand Up @@ -9,8 +9,6 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;



public class BigIntegerTest
extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion src/gnu/java/zrtp/ZRtp.java
Expand Up @@ -757,7 +757,7 @@ public void setRs2Valid() {
* data as a string.
*
* @param index
* Hello hash of the Hello packet identfied by index. Index must be 0 <= index < SUPPORTED_ZRTP_VERSIONS.
* Hello hash of the Hello packet identified by index. Index must be 0 <= index < SUPPORTED_ZRTP_VERSIONS.
*
* @return a string containing the Hello hash value as hex-digits. The
* hello hash is available immediately after class instantiation.
Expand Down
23 changes: 23 additions & 0 deletions src/gnu/java/zrtp/annotations/IntDef.java
@@ -0,0 +1,23 @@
package gnu.java.zrtp.annotations;

/**
* Annotations to check for allowed integer constants.
*
* Shamelessly copied from Android's IntDef annotation: core/java/android/annotation/IntDef.java
*
* Created by werner on 03.01.16.
*/
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.RetentionPolicy.CLASS;

@Retention(CLASS)
@Target({ANNOTATION_TYPE})
public @interface IntDef {
/** Defines the allowed constants for this element */
long[] value() default {};
/** Defines whether the constants can be used as a flag, or just as an enum (the default) */
boolean flag() default false;
}
28 changes: 28 additions & 0 deletions src/gnu/java/zrtp/annotations/NonNull.java
@@ -0,0 +1,28 @@
package gnu.java.zrtp.annotations;

/**
*
* Annotations to define a NonNull value.
*
* Shamelessly copied from Android's IntDef annotation: core/java/android/annotation/NonNull.java
*
* Created by werner on 03.01.16.
*/
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Denotes that a parameter, field or method return value can never be null.
* <p/>
* This is a marker annotation and it has no specific attributes.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target({METHOD,PARAMETER,LOCAL_VARIABLE,FIELD})
public @interface NonNull {
}
4 changes: 2 additions & 2 deletions src/gnu/java/zrtp/packets/ZrtpPacketBase.java
Expand Up @@ -19,7 +19,7 @@

package gnu.java.zrtp.packets;

import com.sun.istack.internal.NotNull;
import gnu.java.zrtp.annotations.NonNull;
import gnu.java.zrtp.utils.ZrtpUtils;

/**
Expand Down Expand Up @@ -98,7 +98,7 @@ public final short getLength() {
}

@SuppressWarnings("unused")
@NotNull
@NonNull
public final String getMessageType() {
return new String(packetBuffer, TYPE_OFFSET, TYPE_LENGTH);
}
Expand Down
4 changes: 2 additions & 2 deletions src/gnu/java/zrtp/utils/ZrtpUtils.java
Expand Up @@ -19,7 +19,7 @@

package gnu.java.zrtp.utils;

import com.sun.istack.internal.NotNull;
import gnu.java.zrtp.annotations.NonNull;

/**
* Some helpful functions, all public static
Expand Down Expand Up @@ -184,7 +184,7 @@ public static void hexdump(String title, byte[] buf, int len) {
}
}

@NotNull
@NonNull
public static char[] bytesToHexString(byte[] in, int length) {
if (length > in.length)
length = in.length;
Expand Down

0 comments on commit 718526c

Please sign in to comment.