its ok
This commit is contained in:
parent
8b13e68cfe
commit
8920987488
@ -4,6 +4,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ulstu.is.sbapp.service.TypeService;
|
||||
|
||||
@RestController
|
||||
public class MainController {
|
||||
@ -21,7 +22,7 @@ public class MainController {
|
||||
}
|
||||
|
||||
@GetMapping("/Min")
|
||||
public Object Mul(@RequestParam(value = "Type") String Type,
|
||||
public Object Min(@RequestParam(value = "Type") String Type,
|
||||
@RequestParam(value = "value1") Object value1,
|
||||
@RequestParam(value = "value2") Object value2){
|
||||
return Service.Min(value1,value2,Type);
|
||||
|
@ -0,0 +1,8 @@
|
||||
package ru.ulstu.is.sbapp.domain;
|
||||
|
||||
public interface ITypeInterface<T> {
|
||||
T Sum(T value1, T value2);
|
||||
T Min(T value1, T value2);
|
||||
T Mul(T value1, T value2);
|
||||
T Del(T value1, T value2);
|
||||
}
|
23
src/main/java/ru/ulstu/is/sbapp/domain/TypeArray.java
Normal file
23
src/main/java/ru/ulstu/is/sbapp/domain/TypeArray.java
Normal file
@ -0,0 +1,23 @@
|
||||
package ru.ulstu.is.sbapp.domain;
|
||||
|
||||
public class TypeArray implements ITypeInterface<int[]>{
|
||||
@Override
|
||||
public int[] Sum(int[] value1, int[] value2) {
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] Min(int[] value1, int[] value2) {
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] Mul(int[] value1, int[] value2) {
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] Del(int[] value1, int[] value2) {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
23
src/main/java/ru/ulstu/is/sbapp/domain/TypeInt.java
Normal file
23
src/main/java/ru/ulstu/is/sbapp/domain/TypeInt.java
Normal file
@ -0,0 +1,23 @@
|
||||
package ru.ulstu.is.sbapp.domain;
|
||||
|
||||
public class TypeInt implements ITypeInterface<Integer>{
|
||||
@Override
|
||||
public Integer Sum(Integer value1, Integer value2) {
|
||||
return value1 + value2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer Min(Integer value1, Integer value2) {
|
||||
return value1 - value2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer Mul(Integer value1, Integer value2) {
|
||||
return value1 * value2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer Del(Integer value1, Integer value2) {
|
||||
return value1 * value2;
|
||||
}
|
||||
}
|
23
src/main/java/ru/ulstu/is/sbapp/domain/TypeString.java
Normal file
23
src/main/java/ru/ulstu/is/sbapp/domain/TypeString.java
Normal file
@ -0,0 +1,23 @@
|
||||
package ru.ulstu.is.sbapp.domain;
|
||||
|
||||
public class TypeString implements ITypeInterface<String>{
|
||||
@Override
|
||||
public String Sum(String value1, String value2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Min(String value1, String value2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Mul(String value1, String value2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Del(String value1, String value2) {
|
||||
return null;
|
||||
}
|
||||
}
|
67
src/main/java/ru/ulstu/is/sbapp/service/TypeService.java
Normal file
67
src/main/java/ru/ulstu/is/sbapp/service/TypeService.java
Normal file
@ -0,0 +1,67 @@
|
||||
package ru.ulstu.is.sbapp.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import ru.ulstu.is.sbapp.domain.ITypeInterface;
|
||||
|
||||
@Service
|
||||
public class TypeService {
|
||||
private final ApplicationContext applicationContext;
|
||||
private ITypeInterface _type;
|
||||
private Object _value1;
|
||||
private Object _value2;
|
||||
|
||||
public TypeService(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
private void ValidateParams(Object value1, Object value2, String type){
|
||||
_type = (ITypeInterface)applicationContext.getBean(type);
|
||||
|
||||
switch (type) {
|
||||
case "int" -> {
|
||||
try {
|
||||
_value1 = Integer.valueOf(value1.toString());
|
||||
_value2 = Integer.valueOf(value2.toString());
|
||||
}catch (Exception ex){
|
||||
_value1 = 0;
|
||||
_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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Object Sum(Object value1, Object value2, String type){
|
||||
ValidateParams(value1,value2,type);
|
||||
return String.format("%s", _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));
|
||||
}
|
||||
|
||||
public Object Mul(Object value1, Object value2, String type){
|
||||
ValidateParams(value1,value2,type);
|
||||
return String.format("%s", _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));
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import ru.ulstu.is.sbapp.Service.TypeService;
|
||||
import ru.ulstu.is.sbapp.service.TypeService;
|
||||
|
||||
@SpringBootTest
|
||||
class SbappApplicationTests {
|
||||
|
Loading…
Reference in New Issue
Block a user