Skip to content
Permalink
Browse files
add Id as base type of vertex id (#4)
* add Id as base type of vertex id

* rename method readFields to read in Writable

* add TextId, ByteArrayUtil, CoderUtil, PlainByteArrayComparator

* add DoubleValue

* tiny improve

* add ValueType and NullValue

* rename TextId to Utf8Id, add code in ValueType

* add CommonTestSuite

* update the code type into int from byte, and other tiny improvements

* remove String.format
  • Loading branch information
houzhizhen committed Dec 31, 2020
1 parent 7675d96 commit 89e35d92893e0e2cffeb381aef8af367f7740ceb
Showing 21 changed files with 1,159 additions and 1 deletion.
@@ -0,0 +1,82 @@
/*
* 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 java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class DoubleValue implements Value {

private double value;

public DoubleValue() {
this.value = 0.0D;
}

public DoubleValue(double value) {
this.value = value;
}

@Override
public void write(DataOutput out) throws IOException {
out.writeDouble(this.value);
}

@Override
public void read(DataInput in) throws IOException {
this.value = in.readDouble();
}

public double value() {
return this.value;
}

/*
* This method is reserved for performance, otherwise it will create a new
* DoubleValue object when change it's value.
*/
public void value(double value) {
this.value = value;
}

@Override
public ValueType type() {
return ValueType.DOUBLE;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof DoubleValue)) {
return false;
}
return ((DoubleValue) obj).value == this.value;
}

@Override
public int hashCode() {
return Double.hashCode(this.value);
}

@Override
public String toString() {
return String.valueOf(this.value);
}
}
@@ -0,0 +1,23 @@
/*
* 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;

public interface Id<T> extends Value, Comparable<T> {
}
@@ -0,0 +1,59 @@
/*
* 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;

public class LongId extends LongValue implements Id<LongId> {

public LongId() {
super();
}

public LongId(long value) {
super(value);
}

@Override
public ValueType type() {
return ValueType.LONG_ID;
}

@Override
public int compareTo(LongId obj) {
return Long.compare(this.value(), obj.value());
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof LongId)) {
return false;
}
return ((LongId) obj).value() == this.value();
}

@Override
public int hashCode() {
return Long.hashCode(this.value());
}

@Override
public String toString() {
return String.valueOf(this.value());
}
}
@@ -0,0 +1,82 @@
/*
* 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 java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class LongValue implements Value {

private long value;

public LongValue() {
this.value = 0L;
}

public LongValue(long value) {
this.value = value;
}

@Override
public ValueType type() {
return ValueType.LONG;
}

@Override
public void write(DataOutput out) throws IOException {
out.writeLong(this.value);
}

@Override
public void read(DataInput in) throws IOException {
this.value = in.readLong();
}

public long value() {
return this.value;
}

/*
* This method is reserved for performance, otherwise it will create a new
* LongValue object when change it's value.
*/
public void value(long value) {
this.value = value;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof LongValue)) {
return false;
}
return ((LongValue) obj).value == this.value;
}

@Override
public int hashCode() {
return Long.hashCode(this.value);
}

@Override
public String toString() {
return String.valueOf(this.value);
}
}
@@ -0,0 +1,69 @@
/*
* 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 java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class NullValue implements Value {

private static final NullValue INSTANCE = new NullValue();

private NullValue() {
}

/*
* Returns the single instance of this class.
*/
public static NullValue get() {
return INSTANCE;
}

@Override
public ValueType type() {
return ValueType.NULL;
}

@Override
public void write(DataOutput out) throws IOException {
// Do nothing
}

@Override
public void read(DataInput in) throws IOException {
// Do nothing
}

@Override
public boolean equals(Object obj) {
return obj == INSTANCE || obj instanceof NullValue;
}

@Override
public int hashCode() {
return 0;
}

@Override
public String toString() {
return "<null>";
}
}
@@ -0,0 +1,28 @@
/*
* 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 java.io.DataInput;
import java.io.IOException;

public interface Readable {

void read(DataInput in) throws IOException;
}

0 comments on commit 89e35d9

Please sign in to comment.