| | |
| | | package com.zy.common.model; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.Arith; |
| | | import com.core.exception.CoolException; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | |
| | | public class Shelves { |
| | | |
| | | // 货架排数量 |
| | | private final int size; |
| | | public final int size; |
| | | |
| | | // 货架组数量 |
| | | private final int group; |
| | | public final int group; |
| | | |
| | | // 偏移量[default:0] |
| | | private final int offset; |
| | | public final int offset; |
| | | |
| | | // 货架实例节点集合 |
| | | private List<List<Integer>> nodes; |
| | | public List<List<Integer>> nodes; |
| | | |
| | | public Shelves(int size, int group) { |
| | | this(size, group, 0); |
| | |
| | | public Shelves(int size, int group, int offset) { |
| | | this.size = size; |
| | | this.group = group; |
| | | this.offset = offset; |
| | | this.offset = offset-1; |
| | | init(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 初始化方法【私有】 |
| | |
| | | * |
| | | * 货架命中规则如下: |
| | | * 安装位置: [1] [2] | [3] [4] -------- [5] [6] | [7] [8] |
| | | * 命中顺序: 1 -> 5 -> 4 -> 8 -> 2 -> 6 -> 3 -> 9 -> 1 ... |
| | | * 命中顺序: 1 -> 5 -> 4 -> 8 -> 2 -> 6 -> 3 -> 7 -> 1 ... |
| | | * |
| | | * 1.该规则适不限制货架数量,总数与组别在构造器中设置 |
| | | * 2.如有序列号起始问题,用偏移量规避即可 |
| | |
| | | } |
| | | } |
| | | } |
| | | return 0; |
| | | return -1; |
| | | } |
| | | |
| | | public Integer get(Integer curRow) { |
| | | for (List<Integer> node : nodes){ |
| | | if (node.contains(curRow)) { |
| | | return nodes.indexOf(node) + 1; |
| | | } |
| | | } |
| | | throw new CoolException("货排检索系统报错, node:" + JSON.toJSONString(nodes) + ", curRow:" + curRow); |
| | | } |
| | | |
| | | 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); |
| | | // } |
| | | } |
| | | |
| | | } |