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

fix core-backend checkstyle issue #1852

Merged
merged 19 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
public class EdgeId implements Id {

public static final HugeKeys[] KEYS = new HugeKeys[] {
HugeKeys.OWNER_VERTEX,
HugeKeys.DIRECTION,
HugeKeys.LABEL,
HugeKeys.SORT_VALUES,
HugeKeys.OTHER_VERTEX
HugeKeys.OWNER_VERTEX,
HugeKeys.DIRECTION,
HugeKeys.LABEL,
HugeKeys.SORT_VALUES,
HugeKeys.OTHER_VERTEX
};

private final Id ownerVertexId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public enum ConditionType {

public enum RelationType implements BiPredicate<Object, Object> {

EQ("==", (v1, v2) -> {return equals(v1, v2); }),
EQ("==", (v1, v2) -> { return equals(v1, v2); }),
GT(">", (v1, v2) -> { return compare(v1, v2) > 0; }),
GTE(">=", (v1, v2) -> { return compare(v1, v2) >= 0; }),
LT("<", (v1, v2) -> { return compare(v1, v2) < 0; }),
Expand Down Expand Up @@ -390,7 +390,7 @@ public static Condition contains(Id key, Object value) {
/**
* Condition defines
*/
public static abstract class BinCondition extends Condition {
public abstract static class BinCondition extends Condition {

private Condition left;
private Condition right;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public List<Condition.Relation> relations() {
return relations;
}

public Relation relation(Id key){
public Relation relation(Id key) {
for (Relation r : this.relations()) {
if (r.key().equals(key)) {
return r;
Expand Down Expand Up @@ -831,7 +831,7 @@ public boolean checkRangeIndex(HugeElement element, Condition cond) {
}

private static boolean removeFieldValue(Set<Object> values,
Object value){
Object value) {
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved
for (Object elem : values) {
if (numberEquals(elem, value)) {
values.remove(elem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ private static Condition convTextContainsAny2Or(Relation relation) {
assert relation.relation() == Condition.RelationType.TEXT_CONTAINS_ANY;
@SuppressWarnings("unchecked")
Collection<String> words = (Collection<String>) relation.value();
Condition cond, conds = null;
Condition cond = null;
Condition conds = null;
for (String word : words) {
assert relation.key() instanceof Id;
cond = Condition.textContains((Id) relation.key(), word);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Query implements Cloneable {
public static final long NO_CAPACITY = -1L;
public static final long DEFAULT_CAPACITY = 800000L; // HugeGraph-777

private static final ThreadLocal<Long> capacityContext = new ThreadLocal<>();
private static final ThreadLocal<Long> CAPACITY_CONTEXT = new ThreadLocal<>();

protected static final Query NONE = new Query(HugeType.UNKNOWN);

Expand Down Expand Up @@ -558,17 +558,17 @@ public String toString() {
}

public static long defaultCapacity(long capacity) {
Long old = capacityContext.get();
capacityContext.set(capacity);
Long old = CAPACITY_CONTEXT.get();
CAPACITY_CONTEXT.set(capacity);
return old != null ? old : DEFAULT_CAPACITY;
}

public static long defaultCapacity() {
Long capacity = capacityContext.get();
Long capacity = CAPACITY_CONTEXT.get();
return capacity != null ? capacity : DEFAULT_CAPACITY;
}

public final static void checkForceCapacity(long count)
public static final void checkForceCapacity(long count)
throws LimitExceedException {
if (count > Query.DEFAULT_CAPACITY) {
throw new LimitExceedException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void removeLastRecord() {
((BinaryBackendEntry) this.current).removeColumn(lastOne);
}

public final static long sizeOfEntry(BackendEntry entry) {
public static final long sizeOfEntry(BackendEntry entry) {
/*
* 3 cases:
* 1) one vertex per entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ protected void parseEdge(BackendColumn col, HugeVertex vertex,
}
}


protected void parseVertex(byte[] value, HugeVertex vertex) {
BytesBuffer buffer = BytesBuffer.wrap(value);

Expand Down Expand Up @@ -871,9 +870,9 @@ public BackendEntry parse(BackendEntry originEntry) {
BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
buffer.write(parsedEntry.id().asBytes());
buffer.write(bytes);
parsedEntry = new BinaryBackendEntry(originEntry.type(),
new BinaryId(buffer.bytes(),
BytesBuffer.wrap(buffer.bytes()).readEdgeId()));
parsedEntry = new BinaryBackendEntry(originEntry.type(), new BinaryId(buffer.bytes(),
BytesBuffer.wrap(buffer.bytes()).readEdgeId()));
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved

for (BackendEntry.BackendColumn col : originEntry.columns()) {
parsedEntry.column(buffer.bytes(), col.value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,25 @@

public interface GraphSerializer {

public BackendEntry writeVertex(HugeVertex vertex);
public BackendEntry writeOlapVertex(HugeVertex vertex);
public BackendEntry writeVertexProperty(HugeVertexProperty<?> prop);
public HugeVertex readVertex(HugeGraph graph, BackendEntry entry);
BackendEntry writeVertex(HugeVertex vertex);

public BackendEntry writeEdge(HugeEdge edge);
public BackendEntry writeEdgeProperty(HugeEdgeProperty<?> prop);
public HugeEdge readEdge(HugeGraph graph, BackendEntry entry);
BackendEntry writeOlapVertex(HugeVertex vertex);

public BackendEntry writeIndex(HugeIndex index);
public HugeIndex readIndex(HugeGraph graph, ConditionQuery query,
BackendEntry entry);
BackendEntry writeVertexProperty(HugeVertexProperty<?> prop);

public BackendEntry writeId(HugeType type, Id id);
public Query writeQuery(Query query);
HugeVertex readVertex(HugeGraph graph, BackendEntry entry);

BackendEntry writeEdge(HugeEdge edge);

BackendEntry writeEdgeProperty(HugeEdgeProperty<?> prop);

HugeEdge readEdge(HugeGraph graph, BackendEntry entry);

BackendEntry writeIndex(HugeIndex index);

HugeIndex readIndex(HugeGraph graph, ConditionQuery query, BackendEntry entry);

BackendEntry writeId(HugeType type, Id id);

Query writeQuery(Query query);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@

public interface SchemaSerializer {

public BackendEntry writeVertexLabel(VertexLabel vertexLabel);
public VertexLabel readVertexLabel(HugeGraph graph, BackendEntry entry);
BackendEntry writeVertexLabel(VertexLabel vertexLabel);

public BackendEntry writeEdgeLabel(EdgeLabel edgeLabel);
public EdgeLabel readEdgeLabel(HugeGraph graph, BackendEntry entry);
VertexLabel readVertexLabel(HugeGraph graph, BackendEntry entry);

public BackendEntry writePropertyKey(PropertyKey propertyKey);
public PropertyKey readPropertyKey(HugeGraph graph, BackendEntry entry);
BackendEntry writeEdgeLabel(EdgeLabel edgeLabel);

public BackendEntry writeIndexLabel(IndexLabel indexLabel);
public IndexLabel readIndexLabel(HugeGraph graph, BackendEntry entry);
EdgeLabel readEdgeLabel(HugeGraph graph, BackendEntry entry);

BackendEntry writePropertyKey(PropertyKey propertyKey);

PropertyKey readPropertyKey(HugeGraph graph, BackendEntry entry);

BackendEntry writeIndexLabel(IndexLabel indexLabel);

IndexLabel readIndexLabel(HugeGraph graph, BackendEntry entry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

public interface BackendEntry extends Idfiable {

public static class BackendColumn implements Comparable<BackendColumn> {
class BackendColumn implements Comparable<BackendColumn> {

public byte[] name;
public byte[] value;
Expand Down Expand Up @@ -71,63 +71,64 @@ public boolean equals(Object obj) {
}
}

public HugeType type();
HugeType type();

@Override
public Id id();
Id id();

public Id originId();
Id originId();

public Id subId();
Id subId();

public long ttl();
long ttl();

public int columnsSize();
public Collection<BackendColumn> columns();
int columnsSize();

public void columns(Collection<BackendColumn> columns);
public void columns(BackendColumn column);
Collection<BackendColumn> columns();

public void merge(BackendEntry other);
public boolean mergeable(BackendEntry other);
void columns(Collection<BackendColumn> columns);

public void clear();
void columns(BackendColumn column);

public default boolean belongToMe(BackendColumn column) {
void merge(BackendEntry other);

boolean mergeable(BackendEntry other);

void clear();

default boolean belongToMe(BackendColumn column) {
return Bytes.prefixWith(column.name, id().asBytes());
}

public default boolean olap() {
default boolean olap() {
return false;
}

public interface BackendIterator<T> extends Iterator<T>, AutoCloseable {
interface BackendIterator<T> extends Iterator<T>, AutoCloseable {

@Override
public void close();
void close();

public byte[] position();
byte[] position();
}

public interface BackendColumnIterator
extends BackendIterator<BackendColumn> {
interface BackendColumnIterator extends BackendIterator<BackendColumn> {

public static BackendColumnIterator empty() {
static BackendColumnIterator empty() {
return EMPTY;
}

public static BackendColumnIterator iterator(BackendColumn element) {
static BackendColumnIterator iterator(BackendColumn element) {
return new OneColumnIterator(element);
}

public static BackendColumnIterator wrap(Iterator<BackendColumn> iter) {
static BackendColumnIterator wrap(Iterator<BackendColumn> iter) {
return new BackendColumnIteratorWrapper(iter);
}

public static final BackendColumnIterator EMPTY = new EmptyIterator();
BackendColumnIterator EMPTY = new EmptyIterator();
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved

public static final class EmptyIterator
implements BackendColumnIterator {
final class EmptyIterator implements BackendColumnIterator {
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved

@Override
public boolean hasNext() {
Expand All @@ -150,8 +151,7 @@ public byte[] position() {
}
}

public static final class OneColumnIterator
implements BackendColumnIterator {
final class OneColumnIterator implements BackendColumnIterator {
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved

private BackendColumn element;

Expand Down Expand Up @@ -186,8 +186,7 @@ public byte[] position() {
}
}

public static final class BackendColumnIteratorWrapper
implements BackendColumnIterator {
final class BackendColumnIteratorWrapper implements BackendColumnIterator {
seagle-yuan marked this conversation as resolved.
Show resolved Hide resolved

private final Iterator<BackendColumn> iter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,39 @@
*/
public interface BackendSession {

public void open();
public void close();
void open();

public boolean opened();
public boolean closed();
void close();

public Object commit();
boolean opened();

public void rollback();
boolean closed();

public boolean hasChanges();
Object commit();

public int attach();
public int detach();
void rollback();

public long created();
public long updated();
public void update();
boolean hasChanges();

public default void reconnectIfNeeded() {
int attach();

int detach();

long created();

long updated();

void update();

default void reconnectIfNeeded() {
// pass
}

public default void reset() {
default void reset() {
// pass
}

public abstract class AbstractBackendSession implements BackendSession {
abstract class AbstractBackendSession implements BackendSession {

protected boolean opened;
private int refs;
Expand Down
Loading