Skip to content

Commit

Permalink
fix redundant Checkstyle (#1896)
Browse files Browse the repository at this point in the history
* add redundant

* add redundant check

* merge line

* update alignment

* delete duplicates check MissingSwitchDefault

* update wrap line

* update code style

* merge dev

* merge master
  • Loading branch information
seagle-yuan authored Oct 30, 2022
1 parent 3a22263 commit cc80d27
Show file tree
Hide file tree
Showing 58 changed files with 367 additions and 391 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -48,7 +48,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -62,4 +62,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class CypherAPI extends GremlinQueryAPI {

private static final Logger LOG = Log.logger(CypherAPI.class);


@GET
@Timed
@CompressInterceptor.Compress(buffer = (1024 * 40))
Expand Down Expand Up @@ -82,11 +81,11 @@ private Response queryByCypher(String graph,
LOG.debug("translated gremlin is {}", gremlin);

String auth = headers.getHeaderString(HttpHeaders.AUTHORIZATION);
String request = "{"
+ "\"gremlin\":\"" + gremlin + "\","
+ "\"bindings\":{},"
+ "\"language\":\"gremlin-groovy\","
+ "\"aliases\":{\"g\":\"__g_" + graph + "\"}}";
String request = "{" +
"\"gremlin\":\"" + gremlin + "\"," +
"\"bindings\":{}," +
"\"language\":\"gremlin-groovy\"," +
"\"aliases\":{\"g\":\"__g_" + graph + "\"}}";

Response response = this.client().doPostRequest(auth, request);
return transformResponseIfNeeded(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package com.baidu.hugegraph.api.gremlin;

import java.util.Map;
import java.util.Set;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
Expand All @@ -30,22 +27,15 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;

import com.baidu.hugegraph.api.API;
import com.baidu.hugegraph.api.filter.CompressInterceptor.Compress;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.config.ServerOptions;
import com.baidu.hugegraph.exception.HugeGremlinException;
import com.baidu.hugegraph.metrics.MetricsUtil;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.annotation.Timed;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import jakarta.inject.Provider;
import jakarta.inject.Singleton;

@Path("gremlin")
Expand All @@ -58,7 +48,6 @@ public class GremlinAPI extends GremlinQueryAPI {
private static final Histogram GREMLIN_OUTPUT_HISTOGRAM =
MetricsUtil.registerHistogram(GremlinAPI.class, "gremlin-output");


@POST
@Timed
@Compress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public String get(@Context GraphManager manager,
double similarity;
try (JaccardSimilarTraverser traverser =
new JaccardSimilarTraverser(g)) {
similarity = traverser.jaccardSimilarity(sourceId, targetId, dir,
edgeLabel, maxDegree);
similarity = traverser.jaccardSimilarity(sourceId, targetId, dir,
edgeLabel, maxDegree);
}
return JsonUtil.toJson(ImmutableMap.of("jaccard_similarity",
similarity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,33 @@

public interface HugeAuthenticator extends Authenticator {

public static final String KEY_USERNAME =
CredentialGraphTokens.PROPERTY_USERNAME;
public static final String KEY_PASSWORD =
CredentialGraphTokens.PROPERTY_PASSWORD;
public static final String KEY_TOKEN = "token";
public static final String KEY_ROLE = "role";
public static final String KEY_ADDRESS = "address";
public static final String KEY_PATH = "path";
String KEY_USERNAME = CredentialGraphTokens.PROPERTY_USERNAME;
String KEY_PASSWORD = CredentialGraphTokens.PROPERTY_PASSWORD;
String KEY_TOKEN = "token";
String KEY_ROLE = "role";
String KEY_ADDRESS = "address";
String KEY_PATH = "path";

public static final String USER_SYSTEM = "system";
public static final String USER_ADMIN = "admin";
public static final String USER_ANONY = AuthenticatedUser.ANONYMOUS_USERNAME;
String USER_SYSTEM = "system";
String USER_ADMIN = "admin";
String USER_ANONY = AuthenticatedUser.ANONYMOUS_USERNAME;

public static final RolePermission ROLE_NONE = RolePermission.none();
public static final RolePermission ROLE_ADMIN = RolePermission.admin();
RolePermission ROLE_NONE = RolePermission.none();
RolePermission ROLE_ADMIN = RolePermission.admin();

public static final String VAR_PREFIX = "$";
public static final String KEY_OWNER = VAR_PREFIX + "owner";
public static final String KEY_DYNAMIC = VAR_PREFIX + "dynamic";
public static final String KEY_ACTION = VAR_PREFIX + "action";
String VAR_PREFIX = "$";
String KEY_OWNER = VAR_PREFIX + "owner";
String KEY_DYNAMIC = VAR_PREFIX + "dynamic";
String KEY_ACTION = VAR_PREFIX + "action";

public void setup(HugeConfig config);
void setup(HugeConfig config);

public UserWithRole authenticate(String username, String password,
String token);
UserWithRole authenticate(String username, String password, String token);

public AuthManager authManager();
AuthManager authManager();

@Override
public default void setup(final Map<String, Object> config) {
default void setup(final Map<String, Object> config) {
E.checkState(config != null,
"Must provide a 'config' in the 'authentication'");
String path = (String) config.get("tokens");
Expand All @@ -83,8 +80,9 @@ public default void setup(final Map<String, Object> config) {
}

@Override
public default User authenticate(final Map<String, String> credentials)
throws AuthenticationException {
default User authenticate(final Map<String, String> credentials)
throws AuthenticationException {

HugeGraphAuthProxy.resetContext();

User user = User.ANONYMOUS;
Expand Down Expand Up @@ -115,21 +113,21 @@ public default User authenticate(final Map<String, String> credentials)
}

@Override
public default boolean requireAuthentication() {
default boolean requireAuthentication() {
return true;
}

public default boolean verifyRole(RolePermission role) {
default boolean verifyRole(RolePermission role) {
if (role == ROLE_NONE || role == null) {
return false;
} else {
return true;
}
}

public void initAdminUser(String password) throws Exception;
void initAdminUser(String password) throws Exception;

public static HugeAuthenticator loadAuthenticator(HugeConfig conf) {
static HugeAuthenticator loadAuthenticator(HugeConfig conf) {
String authClass = conf.get(ServerOptions.AUTHENTICATOR);
if (authClass.isEmpty()) {
return null;
Expand All @@ -150,7 +148,7 @@ public static HugeAuthenticator loadAuthenticator(HugeConfig conf) {
return authenticator;
}

public static class User extends AuthenticatedUser {
class User extends AuthenticatedUser {

public static final User ADMIN = new User(USER_ADMIN, ROLE_ADMIN);
public static final User ANONYMOUS = new User(USER_ANONY, ROLE_ADMIN);
Expand Down Expand Up @@ -255,7 +253,7 @@ public static class UserJson {
}
}

public static class RolePerm {
class RolePerm {

@JsonProperty("roles") // graph -> action -> resource
private Map<String, Map<HugePermission, Object>> roles;
Expand Down Expand Up @@ -395,7 +393,7 @@ public static boolean match(Object role, RolePermission grant,
}
}

public static class RequiredPerm {
class RequiredPerm {

@JsonProperty("owner")
private String owner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1790,17 +1790,17 @@ public String toString() {

private static final ThreadLocal<Context> CONTEXTS = new InheritableThreadLocal<>();

protected static final Context setContext(Context context) {
protected static Context setContext(Context context) {
Context old = CONTEXTS.get();
CONTEXTS.set(context);
return old;
}

protected static final void resetContext() {
protected static void resetContext() {
CONTEXTS.remove();
}

protected static final Context getContext() {
protected static Context getContext() {
// Return task context first
String taskContext = TaskManager.getContext();
User user = User.fromJson(taskContext);
Expand All @@ -1811,15 +1811,15 @@ protected static final Context getContext() {
return CONTEXTS.get();
}

protected static final String getContextString() {
protected static String getContextString() {
Context context = getContext();
if (context == null) {
return null;
}
return context.user().toJson();
}

protected static final void logUser(User user, String path) {
protected static void logUser(User user, String path) {
LOG.info("User '{}' login from client [{}] with path '{}'",
user.username(), user.client(), path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
}
}

private void sendError(ChannelHandlerContext ctx, Object msg) {
private void sendError(ChannelHandlerContext context, Object msg) {
// Close the connection as soon as the error message is sent.
ctx.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, UNAUTHORIZED))
.addListener(ChannelFutureListener.CLOSE);
context.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, UNAUTHORIZED))
.addListener(ChannelFutureListener.CLOSE);
ReferenceCountUtil.release(msg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

public interface Checkable {

public void checkCreate(boolean isBatch);
void checkCreate(boolean isBatch);

public default void checkUpdate() {
default void checkUpdate() {
this.checkCreate(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,65 +42,60 @@

public interface Serializer {

public String writeMap(Map<?, ?> map);
String writeMap(Map<?, ?> map);

public String writeList(String label, Collection<?> list);
String writeList(String label, Collection<?> list);

public String writePropertyKey(PropertyKey propertyKey);
String writePropertyKey(PropertyKey propertyKey);

public String writePropertyKeys(List<PropertyKey> propertyKeys);
String writePropertyKeys(List<PropertyKey> propertyKeys);

public String writeVertexLabel(VertexLabel vertexLabel);
String writeVertexLabel(VertexLabel vertexLabel);

public String writeVertexLabels(List<VertexLabel> vertexLabels);
String writeVertexLabels(List<VertexLabel> vertexLabels);

public String writeEdgeLabel(EdgeLabel edgeLabel);
String writeEdgeLabel(EdgeLabel edgeLabel);

public String writeEdgeLabels(List<EdgeLabel> edgeLabels);
String writeEdgeLabels(List<EdgeLabel> edgeLabels);

public String writeIndexlabel(IndexLabel indexLabel);
String writeIndexlabel(IndexLabel indexLabel);

public String writeIndexlabels(List<IndexLabel> indexLabels);
String writeIndexlabels(List<IndexLabel> indexLabels);

public String writeTaskWithSchema(SchemaElement.TaskWithSchema tws);
String writeTaskWithSchema(SchemaElement.TaskWithSchema tws);

public String writeVertex(Vertex v);
String writeVertex(Vertex v);

public String writeVertices(Iterator<Vertex> vertices, boolean paging);
String writeVertices(Iterator<Vertex> vertices, boolean paging);

public String writeEdge(Edge e);
String writeEdge(Edge e);

public String writeEdges(Iterator<Edge> edges, boolean paging);
String writeEdges(Iterator<Edge> edges, boolean paging);

public String writeIds(List<Id> ids);
String writeIds(List<Id> ids);

public String writeAuthElement(AuthElement elem);
String writeAuthElement(AuthElement elem);

public <V extends AuthElement> String writeAuthElements(String label,
List<V> users);
<V extends AuthElement> String writeAuthElements(String label, List<V> users);

public String writePaths(String name, Collection<HugeTraverser.Path> paths,
boolean withCrossPoint, Iterator<Vertex> vertices);
String writePaths(String name, Collection<HugeTraverser.Path> paths,
boolean withCrossPoint, Iterator<Vertex> vertices);

public default String writePaths(String name,
Collection<HugeTraverser.Path> paths,
boolean withCrossPoint) {
default String writePaths(String name, Collection<HugeTraverser.Path> paths,
boolean withCrossPoint) {
return this.writePaths(name, paths, withCrossPoint, null);
}

public String writeCrosspoints(CrosspointsPaths paths,
Iterator<Vertex> iterator, boolean withPath);
String writeCrosspoints(CrosspointsPaths paths, Iterator<Vertex> iterator,
boolean withPath);

public String writeSimilars(SimilarsMap similars,
Iterator<Vertex> vertices);
String writeSimilars(SimilarsMap similars, Iterator<Vertex> vertices);

public String writeWeightedPath(NodeWithWeight path,
Iterator<Vertex> vertices);
String writeWeightedPath(NodeWithWeight path, Iterator<Vertex> vertices);

public String writeWeightedPaths(WeightedPaths paths,
Iterator<Vertex> vertices);
String writeWeightedPaths(WeightedPaths paths, Iterator<Vertex> vertices);

public String writeNodesWithPath(String name, List<Id> nodes, long size,
Collection<HugeTraverser.Path> paths,
Iterator<Vertex> vertices);
String writeNodesWithPath(String name, List<Id> nodes, long size,
Collection<HugeTraverser.Path> paths,
Iterator<Vertex> vertices);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@

public interface Analyzer {

public Set<String> segment(String text);
Set<String> segment(String text);
}
Loading

0 comments on commit cc80d27

Please sign in to comment.