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

Implement DstSortedListLinkedImpl for sorted list #378

Merged
merged 34 commits into from
Jan 9, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.distkv.dst.common.exception.DictKeyNotFoundException;
import com.distkv.dst.common.exception.DstListIndexOutOfBoundsException;
import com.distkv.dst.common.exception.SortedListMemberNotFoundException;
import com.distkv.dst.common.exception.SortedListTopNumBePositiveException;
import com.distkv.dst.common.exception.SortedListTopNumIsNonNegativeException;
import com.distkv.dst.common.exception.DstException;
import com.distkv.dst.rpc.protobuf.generated.CommonProtocol;

Expand All @@ -24,7 +24,7 @@ public static void checkStatus(CommonProtocol.Status status, String key, String
case SLIST_MEMBER_NOT_FOUND:
throw new SortedListMemberNotFoundException(key, typeCode);
case SLIST_TOPNUM_BE_POSITIVE:
throw new SortedListTopNumBePositiveException(key, typeCode);
throw new SortedListTopNumIsNonNegativeException(key, typeCode);
default:
throw new DstException(typeCode + "000",
String.format("Error status is %s", status.getClass().toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ public DstTuple<Integer, Integer> getMember(String key, String member) {
service.getMember(getMemberRequest.build()));
CheckStatusUtil.checkStatus(response.getStatus(), key, typeCode);
SortedListProtocol.SortedListEntity sortedListEntity = response.getEntity();
return new DstTuple<Integer, Integer>(sortedListEntity.getScore(), response.getCount());
return new DstTuple<>(sortedListEntity.getScore(), response.getCount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.distkv.dst.common.exception.DictKeyNotFoundException;
import com.distkv.dst.common.exception.DstListIndexOutOfBoundsException;
import com.distkv.dst.common.exception.SortedListMemberNotFoundException;
import com.distkv.dst.common.exception.SortedListTopNumBePositiveException;
import com.distkv.dst.common.exception.SortedListTopNumIsNonNegativeException;
import com.distkv.dst.parser.DstParser;
import com.distkv.dst.parser.po.DstParsedResult;

Expand Down Expand Up @@ -86,7 +86,7 @@ private void loop(DstClient dstClient) {
result = ("errorCode: " + e.getErrorCode() + ";\n Detail: " + e.getMessage());
} catch (SortedListMemberNotFoundException e) {
result = ("errorCode: " + e.getErrorCode() + ";\n Detail: " + e.getMessage());
} catch (SortedListTopNumBePositiveException e) {
} catch (SortedListTopNumIsNonNegativeException e) {
result = ("errorCode: " + e.getErrorCode() + ";\n Detail: " + e.getMessage());
} catch (DstException e) {
result = ("errorCode: " + e.getErrorCode() + ";\n Detail: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,27 @@ public void setMember(String info) {

@Override
public int compareTo(SortedListEntity o) {
return o.getScore() - getScore();
if (o.getScore() != getScore()) {
return o.getScore() - getScore();
}
return getMember().compareTo(o.getMember());
jovany-wang marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SortedListEntity anotherEntity = (SortedListEntity) o;
return member.equals(anotherEntity.getMember());
}

@Override
public int hashCode() {
return member.hashCode();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/
public class DictKeyNotFoundException extends DstException {

protected String errorCode = "001";
protected String errorCode = ErrorCodeEnum
.DictKeyNotFoundErrorCode
.getErrorCode();

protected String key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/
public class DstException extends RuntimeException {

String errorCode = "";
String errorCode = ErrorCodeEnum
.DstErrorCode
.getErrorCode();

public DstException(String errorCode, String errorMessage) {
super(errorMessage);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.distkv.dst.common.exception;

public class DstKeyDuplicatedException extends DstException {

protected String errorCode = ErrorCodeEnum
.DstKeyDuplicatedErrorCode
.getErrorCode();

protected String key;

public DstKeyDuplicatedException(String key) {
super(String.format("The store has multiple duplicate keys %s", key));
}

public DstKeyDuplicatedException(String key, String typeCode) {
super(String.format("The store has multiple duplicate keys %s", key));
this.errorCode = typeCode + this.errorCode;
}

public String getKey() {
return key;
}

public String getErrorCode() {
return errorCode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public class DstListIndexOutOfBoundsException extends DstException {

protected String errorCode = "202";
protected String errorCode = ErrorCodeEnum
.DstListIndexOutOfBoundsErrorCode
.getErrorCode();

protected String key;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.distkv.dst.common.exception;

public enum ErrorCodeEnum {
DictKeyNotFoundErrorCode("001"),
DstErrorCode(""),
DstListIndexOutOfBoundsErrorCode("202"),
KeyNotFoundErrorCode("100"),
DstKeyDuplicatedErrorCode("200"),
SortedListMembersDuplicatedErrorCode("008"),
SortedListIncrScoreOutOfRangeErrorCode("009"),
SortedListMemberNotFoundErrorCode("006"),
SortedListTopNumBeNonNegativeErrorCode("007");

private final String errorcode;

ErrorCodeEnum(String errorcode) {
this.errorcode = errorcode;
}

public String getErrorCode() {
return errorcode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/
public class KeyNotFoundException extends DstException {

protected String errorCode = "100";
protected String errorCode = ErrorCodeEnum
.KeyNotFoundErrorCode
.getErrorCode();

protected String key;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.distkv.dst.common.exception;

public class SortedListIncrScoreOutOfRangeException extends DstException {

protected String errorCode = ErrorCodeEnum
.SortedListIncrScoreOutOfRangeErrorCode
.getErrorCode();

protected String key;

public SortedListIncrScoreOutOfRangeException(String key) {
super(String.format("The score of the member in the SortedList %s" +
" will be outing of range after increasing", key));
}

public SortedListIncrScoreOutOfRangeException(String key, String typeCode) {
super(String.format("The score of the member in the SortedList %s" +
" will be outing of range after increasing", key));
this.errorCode = typeCode + this.errorCode;
}

public String getKey() {
return key;
}

public String getErrorCode() {
return errorCode;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public class SortedListMemberNotFoundException extends DstException {

protected String errorCode = "006";
protected String errorCode = ErrorCodeEnum
.SortedListMemberNotFoundErrorCode
.getErrorCode();

protected String key;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.distkv.dst.common.exception;

public class SortedListMembersDuplicatedException extends DstException {

protected String errorCode = ErrorCodeEnum
.SortedListMembersDuplicatedErrorCode
.getErrorCode();

protected String key;

public SortedListMembersDuplicatedException(String key) {
super(String.format("The SortedList %s which you putted into has " +
"duplicated members.", key));
}

public SortedListMembersDuplicatedException(String key, String typeCode) {
super(String.format("The SortedList %s which you putted into has " +
"duplicated members.", key));
this.errorCode = typeCode + this.errorCode;
}

public String getKey() {
return key;
}

public String getErrorCode() {
return errorCode;
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.distkv.dst.common.exception;

public class SortedListTopNumBePositiveException extends DstException {
public class SortedListTopNumIsNonNegativeException extends DstException {

protected String errorCode = "007";
protected String errorCode = ErrorCodeEnum
.SortedListTopNumBeNonNegativeErrorCode
.getErrorCode();

protected String key;

public SortedListTopNumBePositiveException(String key, int topNum) {
public SortedListTopNumIsNonNegativeException(String key, int topNum) {
super(String.format("The topNum must be bigger than 0, your parameter is %d", topNum));
this.key = key;
}

public SortedListTopNumBePositiveException(String key, String typeCode) {
public SortedListTopNumIsNonNegativeException(String key, String typeCode) {
super("The topNum must be bigger than 0");
this.key = key;
this.errorCode = typeCode + this.errorCode;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/distkv/dst/core/KVStore.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.distkv.dst.core;

import com.distkv.dst.core.concepts.DstDicts;
import com.distkv.dst.core.concepts.DstStrings;
import com.distkv.dst.core.concepts.DstLists;
import com.distkv.dst.core.concepts.DstSets;
import com.distkv.dst.core.concepts.DstStrings;
import com.distkv.dst.core.concepts.DstDicts;
import com.distkv.dst.core.concepts.DstSortedLists;
import com.distkv.dst.core.concepts.DstTables;

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/distkv/dst/core/KVStoreImpl.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.distkv.dst.core;

import com.distkv.dst.core.concepts.DstSortedListsImpl;
import com.distkv.dst.core.concepts.DstDictsImpl;
import com.distkv.dst.core.concepts.DstSetsImpl;
import com.distkv.dst.core.concepts.DstStringsImpl;
import com.distkv.dst.core.concepts.DstTablesImpl;
import com.distkv.dst.core.concepts.DstListsImpl;
import com.distkv.dst.core.concepts.DstTables;
import com.distkv.dst.core.concepts.DstDicts;
import com.distkv.dst.core.concepts.DstSortedLists;
import com.distkv.dst.core.concepts.DstSets;
import com.distkv.dst.core.concepts.DstLists;
import com.distkv.dst.core.concepts.DstStrings;
import com.distkv.dst.core.concepts.DstSortedLists;
import com.distkv.dst.core.concepts.DstSortedListsImpl;

public class KVStoreImpl implements KVStore {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.distkv.dst.common.DstTuple;
import com.distkv.dst.common.entity.sortedList.SortedListEntity;
import com.distkv.dst.common.utils.Status;

import java.util.LinkedList;
import java.util.List;

Expand Down
Loading