|
@@ -0,0 +1,45 @@
|
|
|
+package db.util;
|
|
|
+
|
|
|
+import db.DBVal;
|
|
|
+import db.Globals;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class ConvertFormat {
|
|
|
+ /**
|
|
|
+ * 将resodb查询到的id分配到各个磁盘文件中
|
|
|
+ *
|
|
|
+ * @param lists
|
|
|
+ */
|
|
|
+ public HashMap<Long, ArrayList<Integer>> convertToLongAndGetIndex(List<DBVal> lists) {
|
|
|
+ HashMap<Long, ArrayList<Integer>> map = new HashMap<>();
|
|
|
+ for (DBVal dbVal : lists) {
|
|
|
+ Long longId = Double.doubleToRawLongBits(dbVal.getValue());
|
|
|
+ long fileId = longId / Globals.MAX_LOG_ITEM;
|
|
|
+ int index = (int) (longId % Globals.MAX_LOG_ITEM);
|
|
|
+
|
|
|
+ ArrayList<Integer> arrayList = map.get(fileId);
|
|
|
+ if (arrayList == null) {
|
|
|
+ arrayList = new ArrayList<Integer>();
|
|
|
+ arrayList.add(index);
|
|
|
+ map.put(fileId, arrayList);
|
|
|
+ } else {
|
|
|
+ if (!arrayList.contains(index)) {
|
|
|
+ arrayList.add(index);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(Long item : map.keySet()){
|
|
|
+ Collections.sort(map.get(item));
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+}
|