Labwork3 is done.
This commit is contained in:
parent
444e67736e
commit
9655a84025
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
.idea/.name
generated
1
.idea/.name
generated
@ -1 +0,0 @@
|
||||
sbapp
|
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@ -2,4 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="jpab" />
|
||||
</component>
|
||||
</project>
|
@ -14,7 +14,9 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'junit:junit:4.13.1'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'com.h2database:h2:2.1.214'
|
||||
implementation 'junit:junit:4.13.2'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
|
@ -1,44 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.Controllers;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ulstu.is.sbapp.Services.ConverterService;
|
||||
|
||||
@RestController
|
||||
public class StringController {
|
||||
private final ConverterService converterService;
|
||||
|
||||
public StringController(ConverterService converterService)
|
||||
{
|
||||
this.converterService = converterService;
|
||||
}
|
||||
@GetMapping("/toupper")
|
||||
public Object toUpper(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
@RequestParam(value = "type",defaultValue = "String") String converterType)
|
||||
{
|
||||
return converterService.toUpper(value,converterType);
|
||||
}
|
||||
|
||||
@GetMapping("/removews")
|
||||
public Object removeWhitespaces(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
@RequestParam(value = "type",defaultValue = "String") String converterType)
|
||||
{
|
||||
return converterService.removeWhitespaces(value,converterType);
|
||||
}
|
||||
|
||||
@GetMapping("/removedigits")
|
||||
public Object removeDigits(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
@RequestParam(value = "type",defaultValue = "String") String converterType)
|
||||
{
|
||||
return converterService.removeDigits(value,converterType);
|
||||
}
|
||||
|
||||
@GetMapping("/tolower")
|
||||
public Object toLower(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
@RequestParam(value = "type",defaultValue = "String") String converterType)
|
||||
{
|
||||
return converterService.toLower(value,converterType);
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.Implementation;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.ulstu.is.sbapp.Interfaces.Converter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component(value = "AString")
|
||||
public class StringArrayConverter implements Converter<String[]>
|
||||
{
|
||||
@Override
|
||||
public String[] toUpper(String[] value) {
|
||||
return Arrays.stream(value).map(word -> word.toUpperCase()).toArray(String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] removeWhitespaces(String[] value) {
|
||||
return (String[]) Arrays.stream(value).map(word -> word.replaceAll("\s+","")).toArray(String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] removeDigits(String[] value) {
|
||||
return (String[]) Arrays.stream(value).map(word -> word.replaceAll("\\d","")).toArray(String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] toLower(String[] value) {
|
||||
return (String[]) Arrays.stream(value).map(word -> word.toLowerCase()).toArray(String[]::new);
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.Implementation;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.ulstu.is.sbapp.Interfaces.Converter;
|
||||
|
||||
@Component(value = "String")
|
||||
public class StringConverter implements Converter<String>
|
||||
{
|
||||
@Override
|
||||
public String toUpper(String value) {
|
||||
return value.toString().toUpperCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String removeWhitespaces(String value) {
|
||||
return value.toString().replaceAll("\s+","");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String removeDigits(String value) {
|
||||
return value.toString().replaceAll("\\d","");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLower(String value) {
|
||||
return value.toString().toLowerCase();
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.Interfaces;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
public interface Converter<T>
|
||||
{
|
||||
public T toUpper(T value);
|
||||
public T removeWhitespaces(T value);
|
||||
public T removeDigits(T value);
|
||||
public T toLower(T value);
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.Services;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.is.sbapp.Interfaces.Converter;
|
||||
import java.util.Arrays;
|
||||
|
||||
@Service
|
||||
public class ConverterService
|
||||
{
|
||||
private final ApplicationContext applicationContext;
|
||||
public ConverterService(ApplicationContext applicationContext)
|
||||
{
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
public Object toUpper(Object value, String converterType)
|
||||
{
|
||||
Converter converter = (Converter) applicationContext.getBean(converterType);
|
||||
if(converterType.equals("String")) {
|
||||
return converter.toUpper(value);
|
||||
}
|
||||
|
||||
return converter.toUpper(value.toString().split("\s+"));
|
||||
}
|
||||
public Object removeWhitespaces(Object value, String converterType)
|
||||
{
|
||||
Converter converter = (Converter) applicationContext.getBean(converterType);
|
||||
if(converterType.equals("String")) {
|
||||
return converter.removeWhitespaces(value);
|
||||
}
|
||||
return converter.removeWhitespaces(value.toString().split("\s+"));
|
||||
}
|
||||
public Object removeDigits(Object value, String converterType)
|
||||
{
|
||||
Converter converter = (Converter) applicationContext.getBean(converterType);
|
||||
if(converterType.equals("String"))
|
||||
{
|
||||
return converter.removeDigits(value);
|
||||
}
|
||||
return converter.removeDigits(value.toString().split("\s+"));
|
||||
}
|
||||
public Object toLower(Object value, String converterType)
|
||||
{
|
||||
Converter converter = (Converter) applicationContext.getBean(converterType);
|
||||
if(converterType.equals("String"))
|
||||
{
|
||||
return converter.toLower(value);
|
||||
}
|
||||
return converter.toLower(value.toString().split("\s+"));
|
||||
}
|
||||
}
|
@ -1 +1,11 @@
|
||||
|
||||
spring.main.banner-mode=off
|
||||
#server.port=8080
|
||||
spring.datasource.url=jdbc:h2:file:./data
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.h2.console.enabled=true
|
||||
spring.h2.console.settings.trace=false
|
||||
spring.h2.console.settings.web-allow-others=false
|
||||
|
@ -1,60 +0,0 @@
|
||||
package ru.ulstu.is.sbapp;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import ru.ulstu.is.sbapp.Services.ConverterService;
|
||||
|
||||
@SpringBootTest
|
||||
public class ConverterServiceTests
|
||||
{
|
||||
@Autowired
|
||||
ConverterService converterService;
|
||||
|
||||
@Test
|
||||
public void stringToUpper()
|
||||
{
|
||||
Assertions.assertEquals("LOVE PROGRAMMING",converterService.toUpper("love programming","String"));
|
||||
}
|
||||
@Test
|
||||
public void stringToLower()
|
||||
{
|
||||
Assertions.assertEquals("love programming",converterService.toLower("LOVE PROGRAMMING","String"));
|
||||
}
|
||||
@Test
|
||||
public void stringRemoveDigits()
|
||||
{
|
||||
Assertions.assertEquals("LVE PRGRAMMNG",converterService.removeDigits("L0VE PR0GRAMM1NG","String"));
|
||||
}
|
||||
@Test
|
||||
public void stringRemoveWhitespaces()
|
||||
{
|
||||
Assertions.assertEquals("loveprogramming",converterService.removeWhitespaces("lo ve pro gramm i ng","String"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStringToUpper()
|
||||
{
|
||||
String expected[] = new String[]{"LOVE","PROGRAMMING"};
|
||||
Assertions.assertArrayEquals(expected,(String[])converterService.toUpper("love programming","AString"));
|
||||
}
|
||||
@Test
|
||||
public void aStringToLower()
|
||||
{
|
||||
String expected[] = new String[]{"love","programming"};
|
||||
Assertions.assertArrayEquals(expected,(String[])converterService.toLower("LOVE PROGRAMMING","AString"));
|
||||
}
|
||||
@Test
|
||||
public void aStringRemoveDigits()
|
||||
{
|
||||
String expected[] = new String[]{"LVE","PRGRAMMNG"};
|
||||
Assertions.assertArrayEquals(expected, (String[]) converterService.removeDigits("L0VE PR0GRAMM1NG","AString"));
|
||||
}
|
||||
@Test
|
||||
public void aStringRemoveWhitespaces()
|
||||
{
|
||||
String expected[] = new String[]{"lo","ve","pro","gramm","i","ng"};
|
||||
Assertions.assertArrayEquals(expected,(String[])converterService.removeWhitespaces("lo ve pro gramm i ng","AString"));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user