Front output of array was changed to basic for arrays.
This commit is contained in:
parent
3136b75b1b
commit
444e67736e
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.
Binary file not shown.
1
.idea/.name
Normal file
1
.idea/.name
Normal file
@ -0,0 +1 @@
|
||||
sbapp
|
@ -15,28 +15,28 @@ public class StringController {
|
||||
this.converterService = converterService;
|
||||
}
|
||||
@GetMapping("/toupper")
|
||||
public String toUpper(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
public Object toUpper(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
@RequestParam(value = "type",defaultValue = "String") String converterType)
|
||||
{
|
||||
return converterService.toUpper(value,converterType);
|
||||
}
|
||||
|
||||
@GetMapping("/removews")
|
||||
public String removeWhitespaces(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
public Object removeWhitespaces(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
@RequestParam(value = "type",defaultValue = "String") String converterType)
|
||||
{
|
||||
return converterService.removeWhitespaces(value,converterType);
|
||||
}
|
||||
|
||||
@GetMapping("/removedigits")
|
||||
public String removeDigits(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
public Object removeDigits(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
@RequestParam(value = "type",defaultValue = "String") String converterType)
|
||||
{
|
||||
return converterService.removeDigits(value,converterType);
|
||||
}
|
||||
|
||||
@GetMapping("/tolower")
|
||||
public String toLower(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
public Object toLower(@RequestParam(value = "value",defaultValue = " ") Object value,
|
||||
@RequestParam(value = "type",defaultValue = "String") String converterType)
|
||||
{
|
||||
return converterService.toLower(value,converterType);
|
||||
|
@ -3,48 +3,29 @@ 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[]>
|
||||
{
|
||||
public StringBuilder fullStr;
|
||||
|
||||
@Override
|
||||
public String toUpper(String [] value) {
|
||||
fullStr = new StringBuilder();
|
||||
for (String word : value)
|
||||
{
|
||||
fullStr.append(word.toUpperCase() + "|");
|
||||
}
|
||||
return fullStr.toString();
|
||||
public String[] toUpper(String[] value) {
|
||||
return Arrays.stream(value).map(word -> word.toUpperCase()).toArray(String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String removeWhitespaces(String[] value) {
|
||||
fullStr = new StringBuilder();
|
||||
for (String word : value)
|
||||
{
|
||||
fullStr.append(word.replaceAll("\s+","") + "|");
|
||||
}
|
||||
return fullStr.toString();
|
||||
public String[] removeWhitespaces(String[] value) {
|
||||
return (String[]) Arrays.stream(value).map(word -> word.replaceAll("\s+","")).toArray(String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String removeDigits(String[] value) {
|
||||
fullStr = new StringBuilder();
|
||||
for (String word : value)
|
||||
{
|
||||
fullStr.append(word.replaceAll("\\d","") + "|");
|
||||
}
|
||||
return fullStr.toString();
|
||||
public String[] removeDigits(String[] value) {
|
||||
return (String[]) Arrays.stream(value).map(word -> word.replaceAll("\\d","")).toArray(String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLower(String[] value) {
|
||||
fullStr = new StringBuilder();
|
||||
for (String word : value)
|
||||
{
|
||||
fullStr.append(word.toLowerCase() + "|");
|
||||
}
|
||||
return fullStr.toString();
|
||||
public String[] toLower(String[] value) {
|
||||
return (String[]) Arrays.stream(value).map(word -> word.toLowerCase()).toArray(String[]::new);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package ru.ulstu.is.sbapp.Interfaces;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
public interface Converter<T>
|
||||
{
|
||||
public String toUpper(T value);
|
||||
public String removeWhitespaces(T value);
|
||||
public String removeDigits(T value);
|
||||
public String toLower(T value);
|
||||
public T toUpper(T value);
|
||||
public T removeWhitespaces(T value);
|
||||
public T removeDigits(T value);
|
||||
public T toLower(T value);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
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;
|
||||
@ -9,50 +10,43 @@ import java.util.Arrays;
|
||||
public class ConverterService
|
||||
{
|
||||
private final ApplicationContext applicationContext;
|
||||
private String[] str;
|
||||
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);
|
||||
}
|
||||
|
||||
public String toUpper(Object value, String converterType)
|
||||
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.toUpper(value.toString());
|
||||
return converter.removeDigits(value);
|
||||
}
|
||||
str = value.toString().split(" ");
|
||||
return converter.toUpper(str);
|
||||
return converter.removeDigits(value.toString().split("\s+"));
|
||||
}
|
||||
public String removeWhitespaces(Object value, String converterType)
|
||||
public Object toLower(Object value, String converterType)
|
||||
{
|
||||
Converter converter = (Converter) applicationContext.getBean(converterType);
|
||||
if(converterType.equals("String"))
|
||||
{
|
||||
return converter.removeWhitespaces(value.toString());
|
||||
return converter.toLower(value);
|
||||
}
|
||||
str = value.toString().split(" ");
|
||||
return converter.removeWhitespaces(str);
|
||||
}
|
||||
public String removeDigits(Object value, String converterType)
|
||||
{
|
||||
Converter converter = (Converter) applicationContext.getBean(converterType);
|
||||
if(converterType.equals("String"))
|
||||
{
|
||||
return converter.removeDigits(value.toString());
|
||||
}
|
||||
str = value.toString().split(" ");
|
||||
return converter.removeDigits(str);
|
||||
}
|
||||
public String toLower(Object value, String converterType)
|
||||
{
|
||||
Converter converter = (Converter) applicationContext.getBean(converterType);
|
||||
if(converterType.equals("String"))
|
||||
{
|
||||
return converter.toLower(value.toString());
|
||||
}
|
||||
str = value.toString().split(" ");
|
||||
return converter.toLower(str);
|
||||
return converter.toLower(value.toString().split("\s+"));
|
||||
}
|
||||
}
|
||||
|
@ -36,21 +36,25 @@ public class ConverterServiceTests
|
||||
@Test
|
||||
public void aStringToUpper()
|
||||
{
|
||||
Assertions.assertEquals("LOVE|PROGRAMMING|",converterService.toUpper("love programming","AString"));
|
||||
String expected[] = new String[]{"LOVE","PROGRAMMING"};
|
||||
Assertions.assertArrayEquals(expected,(String[])converterService.toUpper("love programming","AString"));
|
||||
}
|
||||
@Test
|
||||
public void aStringToLower()
|
||||
{
|
||||
Assertions.assertEquals("love|programming|",converterService.toLower("LOVE PROGRAMMING","AString"));
|
||||
String expected[] = new String[]{"love","programming"};
|
||||
Assertions.assertArrayEquals(expected,(String[])converterService.toLower("LOVE PROGRAMMING","AString"));
|
||||
}
|
||||
@Test
|
||||
public void aStringRemoveDigits()
|
||||
{
|
||||
Assertions.assertEquals("LVE|PRGRAMMNG|",converterService.removeDigits("L0VE PR0GRAMM1NG","AString"));
|
||||
String expected[] = new String[]{"LVE","PRGRAMMNG"};
|
||||
Assertions.assertArrayEquals(expected, (String[]) converterService.removeDigits("L0VE PR0GRAMM1NG","AString"));
|
||||
}
|
||||
@Test
|
||||
public void aStringRemoveWhitespaces()
|
||||
{
|
||||
Assertions.assertEquals("lo|ve|pro|gramm|i|ng|",converterService.removeWhitespaces("lo ve pro gramm i ng","AString"));
|
||||
String expected[] = new String[]{"lo","ve","pro","gramm","i","ng"};
|
||||
Assertions.assertArrayEquals(expected,(String[])converterService.removeWhitespaces("lo ve pro gramm i ng","AString"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user