Skip to content

Commit 2f1e995

Browse files
committed
refactor Protocol enum
1 parent 8df737b commit 2f1e995

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

roc_jni/src/main/impl/protocol.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ roc_protocol get_protocol(JNIEnv* env, jobject jprotocol) {
1111
}
1212

1313
jobject get_protocol_enum(JNIEnv* env, roc_protocol protocol) {
14-
jclass protocolClass = NULL;
14+
jclass protocolUtilsClass = NULL;
1515
jobject jprotocol = NULL;
1616
jmethodID getProtocolMethodID = NULL;
1717

18-
protocolClass = (*env)->FindClass(env, PROTOCOL_CLASS);
19-
assert(protocolClass != NULL);
18+
protocolUtilsClass = (*env)->FindClass(env, PROTOCOL_UTILS_CLASS);
19+
assert(protocolUtilsClass != NULL);
2020

2121
getProtocolMethodID
22-
= (*env)->GetStaticMethodID(env, protocolClass, "getByValue", "(I)L" PROTOCOL_CLASS ";");
22+
= (*env)->GetStaticMethodID(env, protocolUtilsClass, "getByValue", "(I)L" PROTOCOL_CLASS ";");
2323
assert(getProtocolMethodID != NULL);
2424

2525
jprotocol = (jobject) (*env)->CallStaticObjectMethod(
26-
env, protocolClass, getProtocolMethodID, (jint) protocol);
26+
env, protocolUtilsClass, getProtocolMethodID, (jint) protocol);
2727
assert(jprotocol != NULL);
2828
return jprotocol;
2929
}

roc_jni/src/main/impl/protocol.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <roc/config.h>
88

99
#define PROTOCOL_CLASS PACKAGE_BASE_NAME "/Protocol"
10+
#define PROTOCOL_UTILS_CLASS PACKAGE_BASE_NAME "/ProtocolUtils"
1011

1112
roc_protocol get_protocol(JNIEnv* env, jobject jprotocol);
1213

src/main/java/org/rocstreaming/roctoolkit/Protocol.java

-9
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,4 @@ public enum Protocol {
113113
this.value = value;
114114
}
115115

116-
@SuppressWarnings("unused") // used by JNI
117-
private static Protocol getByValue(int value) {
118-
for (Protocol protocol : values()) {
119-
if (value == protocol.value) {
120-
return protocol;
121-
}
122-
}
123-
return null;
124-
}
125116
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.rocstreaming.roctoolkit;
2+
3+
import lombok.NoArgsConstructor;
4+
5+
@SuppressWarnings("unused") // used by JNI
6+
@NoArgsConstructor
7+
class ProtocolUtils {
8+
9+
private static Protocol getByValue(int value) {
10+
for (Protocol protocol : Protocol.values()) {
11+
if (value == protocol.value) {
12+
return protocol;
13+
}
14+
}
15+
return null;
16+
}
17+
}

0 commit comments

Comments
 (0)