From 3d3da162de0e70c7fa79a1383b06cc2d3165844a Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Mon, 11 Dec 2017 17:35:51 +0800 Subject: [PATCH] HugeGraph-978: add prefixWith() for bytes Change-Id: I17a493ef0097f9208f4cfa3aad8bbd159283f4bb --- pom.xml | 2 +- .../java/com/baidu/hugegraph/util/Bytes.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/baidu/hugegraph/util/Bytes.java diff --git a/pom.xml b/pom.xml index 75d26bad3..8d5b1231e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.baidu.hugegraph hugegraph-common - 1.3.5-SNAPSHOT + 1.3.6-SNAPSHOT diff --git a/src/main/java/com/baidu/hugegraph/util/Bytes.java b/src/main/java/com/baidu/hugegraph/util/Bytes.java new file mode 100644 index 000000000..75f8dbb50 --- /dev/null +++ b/src/main/java/com/baidu/hugegraph/util/Bytes.java @@ -0,0 +1,38 @@ +/* + * 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.util; + +/** + * TODO: extends com.google.common.primitives.Bytes + */ +public final class Bytes { + + public static boolean prefixWith(byte[] bytes, byte[] prefix) { + if (bytes.length < prefix.length) { + return false; + } + for (int i = 0; i < prefix.length; i++) { + if (bytes[i] != prefix[i]) { + return false; + } + } + return true; + } +}