From 1c0dbad152362ac704a27ecfc5b5d08247385d87 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期二, 21 十月 2025 17:12:48 +0800
Subject: [PATCH] 13
---
src/main/java/com/zy/common/model/Shelves.java | 58 ++++++++++++++++++++++++++++++++--------------------------
1 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/src/main/java/com/zy/common/model/Shelves.java b/src/main/java/com/zy/common/model/Shelves.java
index de2aa46..6493c94 100644
--- a/src/main/java/com/zy/common/model/Shelves.java
+++ b/src/main/java/com/zy/common/model/Shelves.java
@@ -1,6 +1,7 @@
package com.zy.common.model;
import com.alibaba.fastjson.JSON;
+import com.core.common.Arith;
import com.core.exception.CoolException;
import java.util.ArrayList;
@@ -30,29 +31,30 @@
}
/**
- * @param size 璐ф灦鍗曟帓鎬绘暟
- * @param group 璐ф灦缁勬暟閲�
+ * @param size 璐ф灦鍗曟帓鎬绘暟
+ * @param group 璐ф灦缁勬暟閲�
* @param offset 搴忓垪鍙峰亸绉婚噺
*/
public Shelves(int size, int group, int offset) {
this.size = size;
this.group = group;
- this.offset = offset;
+ this.offset = offset - 1;
init();
}
+
/**
* 鍒濆鍖栨柟娉曘�愮鏈夈��
*/
- private void init(){
- if (group == 0 || size%group != 0) {
+ private void init() {
+ if (group == 0 || size % group != 0) {
throw new RuntimeException("shelves init fail!");
}
nodes = new ArrayList<>();
- for (int g = 1; g <= this.group; g++){
- int unit = size/group;
+ for (int g = 1; g <= this.group; g++) {
+ int unit = size / group;
List<Integer> node = new ArrayList<>();
- for (int i = (g-1)*unit+1+offset ; i <= g*unit+offset; i++){
+ for (int i = (g - 1) * unit + 1 + offset; i <= g * unit + offset; i++) {
node.add(i);
}
nodes.add(node);
@@ -61,20 +63,20 @@
/**
* 寮�濮嬭绠� =======>>>
- *
- * 璐ф灦鍛戒腑瑙勫垯濡備笅锛�
- * 瀹夎浣嶇疆锛� [1] [2] | [3] [4] -------- [5] [6] | [7] [8]
- * 鍛戒腑椤哄簭锛� 1 -> 5 -> 4 -> 8 -> 2 -> 6 -> 3 -> 7 -> 1 ...
- *
- * 1.璇ヨ鍒欓�備笉闄愬埗璐ф灦鏁伴噺锛屾�绘暟涓庣粍鍒湪鏋勯�犲櫒涓缃�
- * 2.濡傛湁搴忓垪鍙疯捣濮嬮棶棰橈紝鐢ㄥ亸绉婚噺瑙勯伩鍗冲彲
+ * <p>
+ * 璐ф灦鍛戒腑瑙勫垯濡備笅锛�
+ * 瀹夎浣嶇疆锛� [1] [2] | [3] [4] -------- [5] [6] | [7] [8]
+ * 鍛戒腑椤哄簭锛� 1 -> 5 -> 4 -> 8 -> 2 -> 6 -> 3 -> 7 -> 1 ...
+ * <p>
+ * 1.璇ヨ鍒欓�備笉闄愬埗璐ф灦鏁伴噺锛屾�绘暟涓庣粍鍒湪鏋勯�犲櫒涓缃�
+ * 2.濡傛湁搴忓垪鍙疯捣濮嬮棶棰橈紝鐢ㄥ亸绉婚噺瑙勯伩鍗冲彲
*
* @param curSeq 褰撳墠璐ф灦鍙�
* @return 瑙勫垯鍛戒腑璐ф灦鍙�
*/
- public int start(int curSeq){
+ public int start(int curSeq) {
Iterator<List<Integer>> iterator = nodes.iterator();
- while (iterator.hasNext()){
+ while (iterator.hasNext()) {
List<Integer> node = iterator.next();
if (node.contains(curSeq)) {
int idx = node.indexOf(curSeq);
@@ -101,7 +103,7 @@
}
public Integer get(Integer curRow) {
- for (List<Integer> node : nodes){
+ for (List<Integer> node : nodes) {
if (node.contains(curRow)) {
return nodes.indexOf(node) + 1;
}
@@ -110,14 +112,18 @@
}
public static void main(String[] args) throws InterruptedException {
- Shelves shelves = new Shelves(8,2);
- System.out.println(shelves.nodes.toString());
- int start = 1;
- while (true) {
- System.out.println(start);
- start = shelves.start(start);
- Thread.sleep(500L);
- }
+
+ double remainder = Arith.divides(1, 16 - 1, 16);
+ System.out.println(remainder);
+ System.out.println((int) remainder);
+// Shelves shelves = new Shelves(8,2);
+// System.out.println(shelves.nodes.toString());
+// int start = 1;
+// while (true) {
+// System.out.println(start);
+// start = shelves.start(start);
+// Thread.sleep(500L);
+// }
}
}
--
Gitblit v1.9.1