MatrixUtils.java
6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package com.huaheng.api.wcs.domain;
import com.huaheng.common.constant.GenConstants;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import javax.validation.constraints.NotNull;
import java.util.*;
/***
* @author tongzonghao
*
*/
public class MatrixUtils {
/**
* 添加矩阵数据
*
* @param matr
* @param inventoryDetailList
*/
public static void add(@NotNull int[][] matr, List<InventoryDetail> inventoryDetailList) {
Map<Integer, InventoryDetail> map = new HashMap<>();
for (InventoryDetail inventoryDetail : inventoryDetailList) {
map.put(inventoryDetail.getContainerDetailNumber(), inventoryDetail);
}
int num = 0;
for (int i = 0; i < matr.length; i++) {
for (int j = 0; j < matr[0].length; j++) {
num++;
if (map.containsKey(num)) {
matr[i][j] = num;
} else {
matr[i][j] = 0;
}
}
}
}
public static void addPoint(@NotNull int[][] matrix,List<Integer> positions){
addPoint(matrix,positions,false);
}
/**
* 填充二维数组
* @param matrix 空二维数组
* @param positions 添加点位
* @param mirrorFill 是否镜像填充 默认false true静态填充
*/
public static void addPoint(@NotNull int[][] matrix,List<Integer> positions,boolean mirrorFill){
Map<Integer, Integer> map = new HashMap<>();
for (Integer integer : positions) {
map.put(integer, integer);
}
int num = 0;
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
num++;
boolean containsKey = map.containsKey(num);
boolean isMirrorFill = mirrorFill ? !containsKey : containsKey;
if (isMirrorFill) {
matrix[i][j] = num;
} else {
matrix[i][j] = 0;
}
}
}
}
/**
* 填充二维数组
* @param stackMatrix 矩阵对象
* @param positions 添加点位
* @param mirrorFill 是否镜像填充 默认false true静态填充
*/
public static void addPoint(StackMatrix stackMatrix,List<Integer> positions,boolean mirrorFill){
int[][] matrix = stackMatrix.getMatr();
Map<Integer, Integer> map = new HashMap<>();
for (Integer integer : positions) {
map.put(integer, integer);
}
int num = 0;
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
num++;
boolean containsKey = map.containsKey(num);
boolean isMirrorFill = mirrorFill ? !containsKey : containsKey;
if (isMirrorFill) {
matrix[i][j] = num;
} else {
matrix[i][j] = 0;
}
}
}
stackMatrix.setMatr(matrix);
}
public static void addSeqNatureNumber(int[][] matrix){
addPoint(matrix,Collections.EMPTY_LIST,true);
}
public static void addSeqNatureNumber(StackMatrix matrix){
int[][] matr = matrix.getMatr();
addPoint(matr,Collections.EMPTY_LIST,true);
matrix.setMatr(matr);
}
/**
* 根据矩阵获取位置
* @param matrix
* @param rowIdx
* @param sequence
* @return
*/
public static int getPositionValue(StackMatrix matrix, int rowIdx,Integer sequence){
//获取根据排序类型匹配位置
int position = 0;
int row = matrix.getRow();
int[][] matr = matrix.getMatr();
if (rowIdx < 0 || rowIdx > row) {
return 0;
}
int[] currentRow = matr[rowIdx];
int currentRowLength = currentRow.length;
if(currentRowLength <= 0){
return 0;
}
switch (sequence){
case GenConstants.NATURE_SEQUENCE:
for (int i : currentRow) {
if(currentRow[i] > 0){
position = currentRow[i];
break;
}
}
break;
case GenConstants.MEDIAN_SEQUENCE:
double two = 2.0;
//取中位值
double mediaValue = (currentRowLength-1) / two;
int mediaUp = Double.valueOf(Math.ceil(mediaValue)).intValue();
int mediaDown = Double.valueOf(Math.floor(mediaValue)).intValue();
for (int i = mediaDown,j = mediaUp; i >= 0 || j <= currentRowLength; i--,j++) {
if(currentRow[i] > currentRow[j]){
position = currentRow[i];
break;
}
if(currentRow[j] > currentRow[i]){
position = currentRow[j];
break;
}
if(i == j){
position = currentRow[i];
break;
}
}
break;
case GenConstants.SKEW_SEQUENCE:
for (int x = 0,j=currentRow.length-1;x <= j; x++,j--) {
if(currentRow[x] > currentRow[j]){
position = currentRow[x];
break;
}
if(currentRow[j] > currentRow[x]){
position = currentRow[j];
break;
}
if(x == j){
position = currentRow[x];
}
}
break;
default:
}
return position;
}
public int getPosition(int[] arys,boolean reverse){
return 0;
}
public int putPositionValue(List<Integer> positionList,Integer sequence){
boolean reverse = true;
return 0;
}
public List<Integer> sortList(List<Integer> list, Integer sequence, boolean reverse){
return list;
}
}