diff --git a/frontend/index.html b/frontend/index.html index 93614f3..b343648 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -49,6 +49,7 @@ + diff --git a/src/main/java/ru/IP_LabWorks/IP/configuration/TypeConfiguration.java b/src/main/java/ru/IP_LabWorks/IP/configuration/TypeConfiguration.java index d35aaea..97be210 100644 --- a/src/main/java/ru/IP_LabWorks/IP/configuration/TypeConfiguration.java +++ b/src/main/java/ru/IP_LabWorks/IP/configuration/TypeConfiguration.java @@ -2,6 +2,7 @@ package ru.IP_LabWorks.IP.configuration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import ru.IP_LabWorks.IP.domain.TypeArray; import ru.IP_LabWorks.IP.domain.TypeDouble; import ru.IP_LabWorks.IP.domain.TypeInt; import ru.IP_LabWorks.IP.domain.TypeString; @@ -22,4 +23,9 @@ public class TypeConfiguration { public TypeDouble createDoubleType(){ return new TypeDouble(); } + + @Bean(value = "array") + public TypeArray createArrayType(){ + return new TypeArray(); + } } diff --git a/src/main/java/ru/IP_LabWorks/IP/domain/TypeArray.java b/src/main/java/ru/IP_LabWorks/IP/domain/TypeArray.java new file mode 100644 index 0000000..8619bbd --- /dev/null +++ b/src/main/java/ru/IP_LabWorks/IP/domain/TypeArray.java @@ -0,0 +1,43 @@ +package ru.IP_LabWorks.IP.domain; + +import java.lang.reflect.Array; +import java.util.ArrayList; + +public class TypeArray implements ITypeInterface> { + + @Override + public ArrayList Method1(ArrayList value1, ArrayList value2) { + ArrayList result = new ArrayList<>(); + for (int i = 0; i < Math.min(value1.size(), value2.size()); ++i){ + result.add(value1.get(i) + value2.get(i)); + } + return result; + } + + @Override + public ArrayList Method2(ArrayList value1, ArrayList value2) { + ArrayList result = new ArrayList<>(); + for (int i = 0; i < Math.min(value1.size(), value2.size()); ++i){ + result.add(value1.get(i) - value2.get(i)); + } + return result; + } + + @Override + public ArrayList Method3(ArrayList value1, ArrayList value2) { + ArrayList result = new ArrayList<>(); + for (int i = 0; i < Math.min(value1.size(), value2.size()); ++i){ + result.add(value1.get(i) * value2.get(i)); + } + return result; + } + + @Override + public ArrayList Method4(ArrayList value1, ArrayList value2) { + ArrayList result = new ArrayList<>(); + for (int i = 0; i < Math.min(value1.size(), value2.size()); ++i){ + result.add(value1.get(i) / value2.get(i)); + } + return result; + } +} diff --git a/src/main/java/ru/IP_LabWorks/IP/service/TypeService.java b/src/main/java/ru/IP_LabWorks/IP/service/TypeService.java index 2094e71..9fc67c2 100644 --- a/src/main/java/ru/IP_LabWorks/IP/service/TypeService.java +++ b/src/main/java/ru/IP_LabWorks/IP/service/TypeService.java @@ -4,6 +4,12 @@ import ru.IP_LabWorks.IP.domain.ITypeInterface; import org.springframework.stereotype.Service; import org.springframework.context.ApplicationContext; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.stream.Collectors; + @Service public class TypeService { @@ -42,8 +48,15 @@ public class TypeService { _value1 = value1; _value2 = value2; } + case "array" -> { + _value1 = Arrays.stream(value1.toString().split(",")) + .map(Integer::parseInt) + .collect(Collectors.toList()); + _value2 = Arrays.stream(value2.toString().split(",")) + .map(Integer::parseInt) + .collect(Collectors.toList()); + } } - } public Object Method1(Object value1, Object value2, String type){ diff --git a/src/test/java/ru/IP_LabWorks/IP/IpApplicationTests.java b/src/test/java/ru/IP_LabWorks/IP/IpApplicationTests.java index 9d9a77b..fd8c835 100644 --- a/src/test/java/ru/IP_LabWorks/IP/IpApplicationTests.java +++ b/src/test/java/ru/IP_LabWorks/IP/IpApplicationTests.java @@ -86,4 +86,28 @@ class IpApplicationTests { final String res = (String)Service.Method4( "1.01", "2.76", "double"); Assertions.assertEquals("0.36594202898550726", res); } + + @Test + void testArrayPlus(){ + final String res = (String)Service.Method1( "1,2,3", "1,2,3", "array"); + Assertions.assertEquals("[2, 4, 6]", res); + } + + @Test + void testArrayMinus(){ + final String res = (String)Service.Method2( "1,2,3", "1,2,3", "array"); + Assertions.assertEquals("[0, 0, 0]", res); + } + + @Test + void testArrayMult(){ + final String res = (String)Service.Method3( "1,2,3", "1,2,3", "array"); + Assertions.assertEquals("[1, 4, 9]", res); + } + + @Test + void testArrayDiv(){ + final String res = (String)Service.Method4( "1,2,3", "1,2,3", "array"); + Assertions.assertEquals("[1, 1, 1]", res); + } }