This is an automated email from the ASF dual-hosted git repository.

jermy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git


The following commit(s) were added to refs/heads/master by this push:
     new 020b7dc00 refactor(core): improve code by flow idea suggests (#2000)
020b7dc00 is described below

commit 020b7dc00a009bcac97aa5dcf4f458ef2f4d67c5
Author: Jade Peng <pjq...@gmail.com>
AuthorDate: Fri Nov 11 23:34:00 2022 +0800

    refactor(core): improve code by flow idea suggests (#2000)
    
    Co-authored-by: jadepeng <jqp...@iflytek.com>
---
 .../baidu/hugegraph/backend/BackendException.java  |  3 +-
 .../hugegraph/backend/cache/CacheManager.java      |  2 +-
 .../backend/cache/CachedGraphTransaction.java      |  1 -
 .../backend/cache/CachedSchemaTransaction.java     | 51 +++++++---------
 .../hugegraph/backend/cache/OffheapCache.java      |  4 +-
 .../baidu/hugegraph/backend/cache/RamCache.java    | 69 +++++++++++-----------
 .../baidu/hugegraph/backend/id/IdGenerator.java    | 16 ++---
 .../com/baidu/hugegraph/backend/id/IdUtil.java     |  4 +-
 .../hugegraph/backend/id/SnowflakeIdGenerator.java |  5 +-
 .../baidu/hugegraph/backend/page/QueryList.java    |  4 +-
 .../baidu/hugegraph/backend/query/Condition.java   | 12 ++--
 .../hugegraph/backend/query/ConditionQuery.java    |  8 +--
 .../backend/query/ConditionQueryFlatten.java       |  2 +-
 .../com/baidu/hugegraph/backend/query/Query.java   |  7 +--
 .../backend/serializer/AbstractSerializer.java     |  4 +-
 .../backend/serializer/BinaryEntryIterator.java    |  2 +-
 .../hugegraph/backend/serializer/BytesBuffer.java  |  4 +-
 .../backend/serializer/SerializerFactory.java      |  2 +-
 .../backend/serializer/TableBackendEntry.java      |  2 +-
 .../hugegraph/backend/store/ram/IntObjectMap.java  | 31 +++++++++-
 .../backend/tx/SchemaIndexTransaction.java         |  2 +-
 21 files changed, 121 insertions(+), 114 deletions(-)

diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/BackendException.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/BackendException.java
index 18c55f975..ce60d12cd 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/BackendException.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/BackendException.java
@@ -45,8 +45,7 @@ public class BackendException extends HugeException {
         this("Exception in backend", cause);
     }
 
-    public static final void check(boolean expression,
-                                   String message, Object... args)
+    public static final void check(boolean expression, String message, 
Object... args)
                                    throws BackendException {
         if (!expression) {
             throw new BackendException(message, args);
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CacheManager.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CacheManager.java
index 8090815d5..1963a268f 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CacheManager.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CacheManager.java
@@ -37,7 +37,7 @@ public class CacheManager {
 
     private static final Logger LOG = Log.logger(CacheManager.class);
 
-    private static CacheManager INSTANCE = new CacheManager();
+    private static final CacheManager INSTANCE = new CacheManager();
 
     // Check the cache expiration every 30s by default
     private static final long TIMER_TICK_PERIOD = 30;
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java
index 6ba16dca9..7a2a852cc 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java
@@ -345,7 +345,6 @@ public final class CachedGraphTransaction extends 
GraphTransaction {
          * try fetch a few of the head results and determine whether to cache.
          */
         final int tryMax = 1 + MAX_CACHE_EDGES_PER_QUERY;
-        assert tryMax > MAX_CACHE_EDGES_PER_QUERY;
         edges = new ArrayList<>(tryMax);
         for (int i = 0; rs.hasNext() && i < tryMax; i++) {
             edges.add(rs.next());
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java
index a145b53fa..07eac8a8b 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java
@@ -386,23 +386,8 @@ public final class CachedSchemaTransaction extends 
SchemaTransaction {
             if (key >= this.size) {
                 return;
             }
-            switch (type) {
-                case PROPERTY_KEY:
-                    this.pks.set(key, value);
-                    break;
-                case VERTEX_LABEL:
-                    this.vls.set(key, value);
-                    break;
-                case EDGE_LABEL:
-                    this.els.set(key, value);
-                    break;
-                case INDEX_LABEL:
-                    this.ils.set(key, value);
-                    break;
-                default:
-                    // pass
-                    break;
-            }
+
+            this.setValue(type, key, value);
         }
 
         public void remove(HugeType type, Id id) {
@@ -412,10 +397,27 @@ public final class CachedSchemaTransaction extends 
SchemaTransaction {
                 return;
             }
             int key = (int) longId;
-            V value = null;
             if (key >= this.size) {
                 return;
             }
+
+            this.setValue(type, key, null);
+        }
+
+        public void clear() {
+            this.pks.clear();
+            this.vls.clear();
+            this.els.clear();
+            this.ils.clear();
+
+            this.cachedTypes.clear();
+        }
+
+        public CachedTypes cachedTypes() {
+            return this.cachedTypes;
+        }
+
+        private void setValue(HugeType type, int key, V value) {
             switch (type) {
                 case PROPERTY_KEY:
                     this.pks.set(key, value);
@@ -434,19 +436,6 @@ public final class CachedSchemaTransaction extends 
SchemaTransaction {
                     break;
             }
         }
-
-        public void clear() {
-            this.pks.clear();
-            this.vls.clear();
-            this.els.clear();
-            this.ils.clear();
-
-            this.cachedTypes.clear();
-        }
-
-        public CachedTypes cachedTypes() {
-            return this.cachedTypes;
-        }
     }
 
     private static class CachedTypes
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/OffheapCache.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/OffheapCache.java
index cc3ccf05c..835448795 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/OffheapCache.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/OffheapCache.java
@@ -363,7 +363,7 @@ public class OffheapCache extends AbstractCache<Id, Object> 
{
         DATE(DataType.DATE),
         UUID(DataType.UUID);
 
-        private DataType dataType;
+        private final DataType dataType;
 
         ValueType() {
             this(DataType.UNKNOWN);
@@ -390,7 +390,7 @@ public class OffheapCache extends AbstractCache<Id, Object> 
{
 
         public static ValueType valueOf(Object object) {
             E.checkNotNull(object, "object");
-            Class<? extends Object> clazz = object.getClass();
+            Class<?> clazz = object.getClass();
             if (Collection.class.isAssignableFrom(clazz)) {
                 return ValueType.LIST;
             } else if (HugeVertex.class.isAssignableFrom(clazz)) {
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java
index d4c55d4d2..459de43e8 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java
@@ -117,38 +117,7 @@ public class RamCache extends AbstractCache<Id, Object> {
         final Lock lock = this.keyLock.lock(id);
         try {
             // The cache is full
-            while (this.map.size() >= capacity) {
-                /*
-                 * Remove the oldest from the queue
-                 * NOTE: it maybe return null if someone else (that's other
-                 * threads) are doing dequeue() and the queue may be empty.
-                 */
-                LinkNode<Id, Object> removed = this.queue.dequeue();
-                if (removed == null) {
-                    /*
-                     * If at this time someone add some new items, these will
-                     * be cleared in the map, but still stay in the queue, so
-                     * the queue will have some more nodes than the map.
-                     */
-                    this.map.clear();
-                    break;
-                }
-                /*
-                 * Remove the oldest from the map
-                 * NOTE: it maybe return null if other threads are doing remove
-                 */
-                this.map.remove(removed.key());
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("RamCache replaced '{}' with '{}' (capacity={})",
-                              removed.key(), id, capacity);
-                }
-                /*
-                 * Release the object
-                 * NOTE: we can't reuse the removed node due to someone else
-                 * may access the node (will do remove() -> enqueue())
-                 */
-                removed = null;
-            }
+            this.removeOldestIfCacheFull(id, capacity);
 
             // Remove the old node if exists
             LinkNode<Id, Object> node = this.map.get(id);
@@ -170,7 +139,6 @@ public class RamCache extends AbstractCache<Id, Object> {
         if (id == null) {
             return;
         }
-        assert id != null;
 
         final Lock lock = this.keyLock.lock(id);
         try {
@@ -229,6 +197,41 @@ public class RamCache extends AbstractCache<Id, Object> {
         return this.map.toString();
     }
 
+    private void removeOldestIfCacheFull(Id id, long capacity) {
+        while (this.map.size() >= capacity) {
+            /*
+             * Remove the oldest from the queue
+             * NOTE: it maybe return null if someone else (that's other
+             * threads) are doing dequeue() and the queue may be empty.
+             */
+            LinkNode<Id, Object> removed = this.queue.dequeue();
+            if (removed == null) {
+                /*
+                 * If at this time someone add some new items, these will
+                 * be cleared in the map, but still stay in the queue, so
+                 * the queue will have some more nodes than the map.
+                 */
+                this.map.clear();
+                break;
+            }
+            /*
+             * Remove the oldest from the map
+             * NOTE: it maybe return null if other threads are doing remove
+             */
+            this.map.remove(removed.key());
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("RamCache replaced '{}' with '{}' (capacity={})",
+                          removed.key(), id, capacity);
+            }
+            /*
+             * Release the object
+             * NOTE: we can't reuse the removed node due to someone else
+             * may access the node (will do remove() -> enqueue())
+             */
+            removed = null;
+        }
+    }
+
     private static final class LinkNode<K, V> extends CacheNode<K, V> {
 
         private LinkNode<K, V> prev;
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdGenerator.java 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdGenerator.java
index a6b0b829b..4c93e8a21 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdGenerator.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdGenerator.java
@@ -36,19 +36,19 @@ public abstract class IdGenerator {
 
     public abstract Id generate(HugeVertex vertex);
 
-    public static final Id of(String id) {
+    public static Id of(String id) {
         return new StringId(id);
     }
 
-    public static final Id of(UUID id) {
+    public static Id of(UUID id) {
         return new UuidId(id);
     }
 
-    public static final Id of(String id, boolean uuid) {
+    public static Id of(String id, boolean uuid) {
         return uuid ? new UuidId(id) : new StringId(id);
     }
 
-    public static final Id of(long id) {
+    public static Id of(long id) {
         return new LongId(id);
     }
 
@@ -65,7 +65,7 @@ public abstract class IdGenerator {
         return new ObjectId(id);
     }
 
-    public static final Id of(byte[] bytes, IdType type) {
+    public static Id of(byte[] bytes, IdType type) {
         switch (type) {
             case LONG:
                 return new LongId(bytes);
@@ -78,7 +78,7 @@ public abstract class IdGenerator {
         }
     }
 
-    public static final Id ofStoredString(String id, IdType type) {
+    public static Id ofStoredString(String id, IdType type) {
         switch (type) {
             case LONG:
                 return of(LongEncoding.decodeSignedB64(id));
@@ -92,7 +92,7 @@ public abstract class IdGenerator {
         }
     }
 
-    public static final String asStoredString(Id id) {
+    public static String asStoredString(Id id) {
         switch (id.type()) {
             case LONG:
                 return LongEncoding.encodeSignedB64(id.asLong());
@@ -105,7 +105,7 @@ public abstract class IdGenerator {
         }
     }
 
-    public static final IdType idType(Id id) {
+    public static IdType idType(Id id) {
         if (id instanceof LongId) {
             return IdType.LONG;
         }
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdUtil.java 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdUtil.java
index 60111f57c..befc7485b 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdUtil.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/IdUtil.java
@@ -74,9 +74,7 @@ public final class IdUtil {
 
     public static String writeString(Id id) {
         String idString = id.asString();
-        StringBuilder sb = new StringBuilder(1 + idString.length());
-        sb.append(id.type().prefix()).append(idString);
-        return sb.toString();
+        return id.type().prefix() + idString;
     }
 
     public static Id readString(String id) {
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/SnowflakeIdGenerator.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/SnowflakeIdGenerator.java
index b597e59e0..615e0e4ee 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/SnowflakeIdGenerator.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/SnowflakeIdGenerator.java
@@ -110,8 +110,8 @@ public class SnowflakeIdGenerator extends IdGenerator {
      */
     private static class IdWorker {
 
-        private long workerId;
-        private long datacenterId;
+        private final long workerId;
+        private final long datacenterId;
         private long sequence = 0L; // AtomicLong
         private long lastTimestamp = -1L;
 
@@ -159,7 +159,6 @@ public class SnowflakeIdGenerator extends IdGenerator {
                     timestamp = TimeUtil.tillNextMillis(this.lastTimestamp);
                 }
             } else {
-                assert timestamp < this.lastTimestamp;
                 LOG.error("Clock is moving backwards, " +
                           "rejecting requests until {}.",
                           this.lastTimestamp);
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java
index a72ef072d..1f5dd533d 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java
@@ -52,7 +52,7 @@ public final class QueryList<R> {
         return this.parent;
     }
 
-    protected QueryResults.Fetcher<R> fetcher() {
+    private QueryResults.Fetcher<R> fetcher() {
         return this.fetcher;
     }
 
@@ -97,7 +97,7 @@ public final class QueryList<R> {
         }
 
         // Fetch all results once
-        return QueryResults.flatMap(this.queries.iterator(), q -> 
q.iterator());
+        return QueryResults.flatMap(this.queries.iterator(), 
FlattenQuery::iterator);
     }
 
     protected PageResults<R> fetchNext(PageInfo pageInfo, long pageSize) {
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java
index fbeddaa02..1e6632440 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java
@@ -168,8 +168,8 @@ public abstract class Condition {
          * @param second is value in query condition
          * @return true if equal, otherwise false
          */
-        protected static boolean equals(final Object first,
-                                        final Object second) {
+        private static boolean equals(final Object first,
+                                      final Object second) {
             assert second != null;
             if (first instanceof Id) {
                 if (second instanceof String) {
@@ -196,7 +196,7 @@ public abstract class Condition {
          *         second; and a value greater than 0 if first is
          *         numerically greater than second.
          */
-        protected static int compare(final Object first, final Object second) {
+        private static int compare(final Object first, final Object second) {
             assert second != null;
             if (second instanceof Number) {
                 return NumericUtil.compareNumber(first == null ? 0 : first,
@@ -211,7 +211,7 @@ public abstract class Condition {
                       second, second.getClass().getSimpleName()));
         }
 
-        protected static int compareDate(Object first, Date second) {
+        private static int compareDate(Object first, Date second) {
             if (first == null) {
                 first = DateUtil.DATE_ZERO;
             }
@@ -646,7 +646,7 @@ public abstract class Condition {
 
     public static class SyspropRelation extends Relation {
 
-        private HugeKeys key;
+        private final HugeKeys key;
 
         public SyspropRelation(HugeKeys key, Object value) {
             this(key, RelationType.EQ, value);
@@ -701,7 +701,7 @@ public abstract class Condition {
     public static class UserpropRelation extends Relation {
 
         // Id of property key
-        private Id key;
+        private final Id key;
 
         public UserpropRelation(Id key, Object value) {
             this(key, RelationType.EQ, value);
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java
index 6ccfbc025..0def61cf2 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java
@@ -286,13 +286,7 @@ public class ConditionQuery extends IdQuery {
     }
 
     public void unsetCondition(Object key) {
-        for (Iterator<Condition> iter = this.conditions.iterator();
-             iter.hasNext();) {
-            Condition c = iter.next();
-            if (c.isRelation() && ((Condition.Relation) c).key().equals(key)) {
-                iter.remove();
-            }
-        }
+        this.conditions.removeIf(c -> c.isRelation() && ((Relation) 
c).key().equals(key));
     }
 
     public boolean containsCondition(HugeKeys key) {
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java
index d9639b36e..c0bd718df 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQueryFlatten.java
@@ -186,7 +186,7 @@ public final class ConditionQueryFlatten {
         assert relation.relation() == Condition.RelationType.TEXT_CONTAINS_ANY;
         @SuppressWarnings("unchecked")
         Collection<String> words = (Collection<String>) relation.value();
-        Condition cond = null;
+        Condition cond;
         Condition conds = null;
         for (String word : words) {
             assert relation.key() instanceof Id;
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java
index 397b313b5..317699ebf 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Query.java
@@ -522,7 +522,7 @@ public class Query implements Cloneable {
         StringBuilder sb = new StringBuilder(128);
         sb.append("`Query ");
         if (this.aggregate != null) {
-            sb.append(this.aggregate.toString());
+            sb.append(this.aggregate);
         } else {
             sb.append('*');
         }
@@ -568,8 +568,7 @@ public class Query implements Cloneable {
         return capacity != null ? capacity : DEFAULT_CAPACITY;
     }
 
-    public static final void checkForceCapacity(long count)
-                                                throws LimitExceedException {
+    public static void checkForceCapacity(long count) throws 
LimitExceedException {
         if (count > Query.DEFAULT_CAPACITY) {
             throw new LimitExceedException(
                       "Too many records(must <= %s) for one query",
@@ -579,6 +578,6 @@ public class Query implements Cloneable {
 
     public enum Order {
         ASC,
-        DESC;
+        DESC
     }
 }
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/AbstractSerializer.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/AbstractSerializer.java
index 56e75fc7a..47245c22c 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/AbstractSerializer.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/AbstractSerializer.java
@@ -31,12 +31,14 @@ import com.baidu.hugegraph.type.HugeType;
 public abstract class AbstractSerializer
                 implements GraphSerializer, SchemaSerializer {
 
+    protected HugeConfig config;
+
     public AbstractSerializer() {
         // TODO: default constructor
     }
 
     public AbstractSerializer(HugeConfig config) {
-        // TODO: use the config
+       this.config = config;
     }
 
     protected BackendEntry convertEntry(BackendEntry entry) {
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryEntryIterator.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryEntryIterator.java
index c4f87516b..e75ad6d05 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryEntryIterator.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryEntryIterator.java
@@ -129,7 +129,7 @@ public class BinaryEntryIterator<Elem> extends 
BackendEntryIterator {
         ((BinaryBackendEntry) this.current).removeColumn(lastOne);
     }
 
-    public static final long sizeOfEntry(BackendEntry entry) {
+    public static long sizeOfEntry(BackendEntry entry) {
         /*
          * 3 cases:
          *  1) one vertex per entry
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BytesBuffer.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BytesBuffer.java
index 7caba2171..4cda2cb33 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BytesBuffer.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BytesBuffer.java
@@ -123,7 +123,7 @@ public final class BytesBuffer extends OutputStream {
     }
 
     public BytesBuffer forReadWritten() {
-        ((Buffer) this.buffer).flip();
+        this.buffer.flip();
         return this;
     }
 
@@ -263,7 +263,7 @@ public final class BytesBuffer extends OutputStream {
     }
 
     public boolean readBoolean() {
-        return this.buffer.get() == 0 ? false : true;
+        return this.buffer.get() != 0;
     }
 
     public char readChar() {
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java
index 56a6956bb..995c5b4da 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java
@@ -27,7 +27,7 @@ import com.baidu.hugegraph.config.HugeConfig;
 
 public class SerializerFactory {
 
-    private static Map<String, Class<? extends AbstractSerializer>> 
serializers;
+    private static final Map<String, Class<? extends AbstractSerializer>> 
serializers;
 
     static {
         serializers = new ConcurrentHashMap<>();
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableBackendEntry.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableBackendEntry.java
index 6d1ecd984..cfa9b169e 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableBackendEntry.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TableBackendEntry.java
@@ -43,7 +43,7 @@ public class TableBackendEntry implements BackendEntry {
         private HugeType type;
         private Id id;
         private Id subId;
-        private Map<HugeKeys, Object> columns;
+        private final Map<HugeKeys, Object> columns;
         private long ttl;
 
         public Row(HugeType type) {
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/IntObjectMap.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/IntObjectMap.java
index 22d4ebc7d..72b379c16 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/IntObjectMap.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/IntObjectMap.java
@@ -28,18 +28,32 @@ import com.baidu.hugegraph.exception.NotSupportException;
 
 public final class IntObjectMap<V> implements RamMap {
 
-    private final Object[] array;
+    private static final float DEFAULT_INITIAL_FACTOR = 0.25f;
+
+    private final int maxSize;
+    private int currentSize;
+    private Object[] array;
 
     public IntObjectMap(int size) {
-        this.array = new Object[size];
+        this.maxSize = size;
+        this.currentSize = (int) (size * DEFAULT_INITIAL_FACTOR);
+        this.array = new Object[this.currentSize];
     }
 
     @SuppressWarnings("unchecked")
     public V get(int key) {
+        if (key >= this.currentSize) {
+            return null;
+        }
+
         return (V) this.array[key];
     }
 
     public void set(int key, V value) {
+        if (key >= this.currentSize) {
+            this.expandCapacity();
+        }
+
         this.array[key] = value;
     }
 
@@ -50,7 +64,7 @@ public final class IntObjectMap<V> implements RamMap {
 
     @Override
     public long size() {
-        return this.array.length;
+        return this.maxSize;
     }
 
     @Override
@@ -62,4 +76,15 @@ public final class IntObjectMap<V> implements RamMap {
     public void readFrom(DataInputStream buffer) throws IOException {
         throw new NotSupportException("IntObjectMap.readFrom");
     }
+
+    private synchronized void expandCapacity() {
+        if (this.currentSize == this.maxSize) {
+            return;
+        }
+        this.currentSize = Math.min(this.currentSize * 2, this.maxSize);
+        Object[] newArray = new Object[this.currentSize];
+        System.arraycopy(this.array, 0, newArray, 0, this.array.length);
+        this.clear();
+        this.array = newArray;
+    }
 }
diff --git 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/SchemaIndexTransaction.java
 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/SchemaIndexTransaction.java
index e65c20be0..153d730e3 100644
--- 
a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/SchemaIndexTransaction.java
+++ 
b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/SchemaIndexTransaction.java
@@ -86,7 +86,7 @@ public class SchemaIndexTransaction extends 
AbstractTransaction {
             return super.query(query);
         }
         IndexLabel il = IndexLabel.label(query.resultType());
-        String name = (String) query.condition(HugeKeys.NAME);
+        String name = query.condition(HugeKeys.NAME);
         E.checkState(name != null, "The name in condition can't be null " +
                      "when querying schema by name");
 

Reply via email to