This commit is contained in:
VictoriaPresnyakova 2023-03-27 15:47:31 +04:00
parent 8c4c5a2a2a
commit 3f3eb3d348
2 changed files with 36 additions and 17 deletions

View File

@ -3,21 +3,37 @@ package ru.ulstu.is.sbapp.domain;
public class TypeArray implements ITypeInterface<int[]>{
@Override
public int[] Sum(int[] value1, int[] value2) {
return new int[0];
int [] ans = new int[Math.min(value1.length, value2.length)];
for (int i = 0; i < Math.min(value1.length, value2.length); i ++){
ans[i] = value1[i] + value2[i];
}
return ans;
}
@Override
public int[] Min(int[] value1, int[] value2) {
return new int[0];
int [] ans = new int[Math.min(value1.length, value2.length)];
for (int i = 0; i < Math.min(value1.length, value2.length); i ++){
ans[i] = value1[i] - value2[i];
}
return ans;
}
@Override
public int[] Mul(int[] value1, int[] value2) {
return new int[0];
int [] ans = new int[Math.min(value1.length, value2.length)];
for (int i = 0; i < Math.min(value1.length, value2.length); i ++){
ans[i] = value1[i] * value2[i];
}
return ans;
}
@Override
public int[] Del(int[] value1, int[] value2) {
return new int[0];
int [] ans = new int[Math.min(value1.length, value2.length)];
for (int i = 0; i < Math.min(value1.length, value2.length); i ++){
ans[i] = value1[i] / value2[i];
}
return ans;
}
}

View File

@ -4,6 +4,8 @@ import org.springframework.stereotype.Service;
import org.springframework.context.ApplicationContext;
import ru.ulstu.is.sbapp.domain.ITypeInterface;
import java.util.Arrays;
@Service
public class TypeService {
private final ApplicationContext applicationContext;
@ -19,6 +21,16 @@ public class TypeService {
_type = (ITypeInterface)applicationContext.getBean(type);
switch (type) {
case "arr" ->{
try {
_value1 = Arrays.stream(value1.toString().split(",")).mapToInt(Integer::valueOf).toArray();
_value2 = Arrays.stream(value2.toString().split(",")).mapToInt(Integer::valueOf).toArray();
}catch (Exception ex){
_value1 = new int[] {0};
_value2 = new int[] {0};
}
}
case "int" -> {
try {
_value1 = Integer.valueOf(value1.toString());
@ -28,15 +40,6 @@ public class TypeService {
_value2 = 0;
}
}
case "double" -> {
try {
_value1 = Double.valueOf(value1.toString());
_value2 = Double.valueOf(value2.toString());
}catch (Exception ex){
_value1 = 0.0;
_value2 = 0.0;
}
}
case "str" -> {
_value1 = value1;
_value2 = value2;
@ -47,21 +50,21 @@ public class TypeService {
public Object Sum(Object value1, Object value2, String type){
ValidateParams(value1,value2,type);
return String.format("%s", _type.Sum(_value1,_value2));
return _type.Sum(_value1,_value2);
}
public Object Min(Object value1, Object value2, String type){
ValidateParams(value1,value2,type);
return String.format("%s", _type.Min(_value1,_value2));
return _type.Min(_value1,_value2);
}
public Object Mul(Object value1, Object value2, String type){
ValidateParams(value1,value2,type);
return String.format("%s", _type.Mul(_value1,_value2));
return _type.Mul(_value1,_value2);
}
public Object Del(Object value1, Object value2, String type){
ValidateParams(value1,value2,type);
return String.format("%s", _type.Del(_value1,_value2));
return _type.Del(_value1,_value2);
}
}