From 63c115f8beaad0346e9decaeb797156fa72f23ad Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Mon, 20 Mar 2023 14:52:50 +0400 Subject: [PATCH] =?UTF-8?q?LabWork=5F02=20=D0=B4=D0=BE=D0=B1=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B5=D1=89=D0=B5=20=D0=BE=D0=B4=D0=B8=D0=BD=20?= =?UTF-8?q?=D1=82=D0=B8=D0=BF,=20=D0=BB=D0=B0=D0=B1=D0=B0=20=D1=81=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/index.html | 1 + .../IP/configuration/TypeConfiguration.java | 6 +++ .../ru/IP_LabWorks/IP/domain/TypeArray.java | 43 +++++++++++++++++++ .../IP_LabWorks/IP/service/TypeService.java | 15 ++++++- .../ru/IP_LabWorks/IP/IpApplicationTests.java | 24 +++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/IP_LabWorks/IP/domain/TypeArray.java 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); + } }