Skip to content
Permalink
Browse files
Improve class for Id, Value, GraphOutput and GraphInput (#6)
* Improve class for Id, Value, GraphOutput and GraphInput

* Add ListValue and improve code

* Add IdValueList and IdValueListList

* Let StreamGraphOutput as a proxy of DataOutputStream

* Add CsvStructGraphOutput and JsonStructGraphOutput
  • Loading branch information
Linary committed Jan 19, 2021
1 parent 89e35d9 commit 452233315ca47590210f6da6b6e93123162c9ed2
Show file tree
Hide file tree
Showing 72 changed files with 3,467 additions and 542 deletions.
@@ -25,7 +25,7 @@ before_script:
- $TRAVIS_DIR/install-env.sh

script:
- mvn test -P core-test
- mvn test -P unit-test

after_success:
- bash <(curl -s https://codecov.io/bash)
@@ -2,7 +2,7 @@
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--参考:https://checkstyle.sourceforge.io/checks.html-->
<!-- 参考:https://checkstyle.sourceforge.io/checks.html -->
<module name="Checker">
<!--检查不通过时被判定的违规级别,必须修复后才能使build通过-->
<property name="severity" value="error"/>
@@ -66,6 +66,8 @@
</module>
<!--检查指定标记的周围是否有空格,比如:if、for、while、synchoronized 等-->
<module name="WhitespaceAround"/>
<!--左圆括号之后和右圆括号之前是否需要有一个空格,不需要-->
<module name="ParenPad"/>
<!--检查修饰符是否符合Java建议,顺序是:public、protected、private、abstract、default、static、final、transient、volatile、synchronized、native、strictfp-->
<module name="ModifierOrder"/>
<!--检查代码块的左花括号的放置位置,必须在当前行的末尾-->
@@ -19,25 +19,20 @@

package com.baidu.hugegraph.computer.core.common;

import org.junit.Test;
public final class Constants {

import com.baidu.hugegraph.testutil.Assert;
public static final byte[] EMPTY_BYTES = new byte[0];

public class LongIdTest {
public static final int BYTE_LEN = Byte.BYTES;
public static final int SHORT_LEN = Short.BYTES;
public static final int INT_LEN = Integer.BYTES;
public static final int LONG_LEN = Long.BYTES;
public static final int CHAR_LEN = Character.BYTES;
public static final int FLOAT_LEN = Float.BYTES;
public static final int DOUBLE_LEN = Double.BYTES;
public static final int BLOB_LEN = 4;

@Test
public void test() {
LongId longId1 = new LongId(-100L);
LongId longId2 = new LongId();
LongId longId3 = new LongId(-100L);

Assert.assertEquals(ValueType.LONG_ID, longId1.type());
Assert.assertTrue(longId1.compareTo(longId2) < 0);
Assert.assertTrue(longId2.compareTo(longId1) > 0);
Assert.assertTrue(longId1.compareTo(longId3) == 0);

Assert.assertEquals(Long.hashCode(-100L), longId1.hashCode());
Assert.assertTrue(longId1.equals(new LongId(longId1.value())));
Assert.assertFalse(longId1.equals(longId2));
}
public static final int UINT8_MAX = ((byte) -1) & 0xff;
public static final int UINT16_MAX = ((short) -1) & 0xffff;
public static final long UINT32_MAX = (-1) & 0xffffffffL;
}
@@ -0,0 +1,54 @@
/*
* Copyright 2017 HugeGraph Authors
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.baidu.hugegraph.computer.core.common;

import com.baidu.hugegraph.computer.core.common.exception.ComputerException;
import com.baidu.hugegraph.util.CollectionUtil;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;

public interface SerialEnum {

byte code();

Table<Class<?>, Byte, SerialEnum> TABLE = HashBasedTable.create();

static void register(Class<? extends SerialEnum> clazz) {
Object enums;
try {
enums = clazz.getMethod("values").invoke(null);
} catch (Exception e) {
throw new ComputerException("Call method values() error", e);
}
for (SerialEnum e : CollectionUtil.<SerialEnum>toList(enums)) {
TABLE.put(clazz, e.code(), e);
}
}

static <T extends SerialEnum> T fromCode(Class<T> clazz, byte code) {
@SuppressWarnings("unchecked")
T value = (T) TABLE.get(clazz, code);
if (value == null) {
throw new ComputerException("Can't construct %s from code %s",
clazz.getSimpleName(), code);
}
return value;
}
}

This file was deleted.

This file was deleted.

@@ -17,7 +17,7 @@
* under the License.
*/

package com.baidu.hugegraph.computer.exception;
package com.baidu.hugegraph.computer.core.common.exception;

public class ComputeException extends ComputerException {

@@ -17,7 +17,7 @@
* under the License.
*/

package com.baidu.hugegraph.computer.exception;
package com.baidu.hugegraph.computer.core.common.exception;

/**
* The base class for all exception types
@@ -17,7 +17,7 @@
* under the License.
*/

package com.baidu.hugegraph.computer.exception;
package com.baidu.hugegraph.computer.core.common.exception;

/**
* A wrapper class for IllegalArgumentException
@@ -17,7 +17,7 @@
* under the License.
*/

package com.baidu.hugegraph.computer.exception;
package com.baidu.hugegraph.computer.core.common.exception;

public class ReadException extends ComputerException {

@@ -17,7 +17,7 @@
* under the License.
*/

package com.baidu.hugegraph.computer.exception;
package com.baidu.hugegraph.computer.core.common.exception;

public class WriteException extends ComputerException {

0 comments on commit 4522333

Please sign in to comment.