Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: java
jdk: openjdk17
jdk: openjdk19
jobs:
include:
- script: mvn clean verify package
Expand Down
161 changes: 114 additions & 47 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,73 +1,140 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>UnitTestAssignment</artifactId>
<version>1.0-SNAPSHOT</version>

<groupId>1111</groupId>
<artifactId>1111</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<flexicore-api.version>4.2.1</flexicore-api.version>
<version.compiler.plugin>3.3</version.compiler.plugin>
<version.eclipselink>2.7.7</version.eclipselink>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pf4j-spring.version>0.6.0</pf4j-spring.version>
<FlexiCore.version>4.2.1</FlexiCore.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>${version.eclipselink}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.wizzdi</groupId>
<artifactId>flexicore-api</artifactId>
<version>${flexicore-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j-spring</artifactId>
<version>${pf4j-spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.2</version>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>2.2</version>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.wizzdi</groupId>
<artifactId>FlexiCore</artifactId>
<version>${FlexiCore.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.wizzdi</groupId>
<artifactId>flexicore-entities-provider</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
<goal>shade</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.9</minimum>
</limit>
</limits>
</rule>
</rules>
<minimizeJar>false</minimizeJar>
<createDependencyReducedPom>true</createDependencyReducedPom>
<dependencyReducedPomLocation>${java.io.tmpdir}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Plugin-Id>${artifactId}</Plugin-Id>
<Plugin-Version>${version}</Plugin-Version>
<!--suppress UnresolvedMavenProperty -->
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
Expand Down
164 changes: 155 additions & 9 deletions src/main/java/StringManipulation.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,179 @@
public class StringManipulation implements StringManipulationInterface {

String myString;
@Override
public String getString() {
return null;
}

@Override
public void setString(String string) {
this.myString = string;
}

@Override
public int count() {
return 0;
int tally = 0;
if(myString == null || myString.length() == 0){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this can be shorter for counting.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate?

return tally;
}
// " here is a string" 4
// "a here is a string" 4
// "a " 1
// "here" 1
for (int i = 0; i < myString.length(); i++){
char currentChar = myString.charAt(i);
if(currentChar != ' '){
tally++;
while(currentChar != ' '){
i++;
if(i >= myString.length()){
break;
}
currentChar = myString.charAt(i);
}
}
while (currentChar == ' '){
i++;
if(i >= myString.length()){
break;
}
currentChar = myString.charAt(i);
}


}
return tally;
}

@Override
// n = 3; aaabbbaaaccc -> aabbaacc
//
public String removeNthCharacter(int n, boolean maintainSpacing) {
return null;
if(n <= 0){
throw new IllegalArgumentException("n must be greater than or equal to 0");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe give a message on my it throws and error.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that it does have a message in it.

}
else if (n > myString.length()){
throw new IndexOutOfBoundsException(n);
}
String buildString = "";
if (maintainSpacing) {
if (n == 1){
for (int i = 0; i < myString.length(); i++){
buildString += " ";
}
return buildString;
}
int prior = 0;
for(int i = 0; i < myString.length(); i++){
if ((i+1) % n == 0){
String slice = myString.substring(prior, i);
buildString += slice;
buildString += " ";
prior = i + 1;
}
if (i == myString.length() - 1 && myString.length() % n != 0){
String slice = myString.substring(prior);
buildString += slice;
}
}
}
else {
// todo need to update criteria for n == 1
if (n == 1){
return buildString;
}
int prior = 0;
for(int i = 0; i < myString.length(); i++){
if ((i+1) % n == 0){
String slice = myString.substring(prior, i);
buildString += slice;
prior = i + 1;
}
if (i == myString.length() - 1 && myString.length() % n != 0){
String slice = myString.substring(prior);
buildString += slice;
}
}
}
return buildString;
}

@Override
public String[] getSubStrings(int startWord, int endWord) {
return null;
public String[] getSubStrings(int startWord, int endWord){
if (startWord <= 0 || endWord <= 0 || endWord < startWord){
throw new IllegalArgumentException();
}
int numWords = this.count();
if (endWord > numWords){
throw new IndexOutOfBoundsException(endWord);
}
String[] array = new String[1 + endWord - startWord];
for (int i = 0; i < array.length; i++){
array[i] = null;
}
int arrayPosition = 0;
int wordCount = 0;
while(array[array.length - 1] == null){
char firstChar = myString.charAt(0);
for (int i = 0; i < myString.length(); i++){
char currentChar = myString.charAt(i);
while (currentChar == ' '){
i++;
if(i >= myString.length()){
return array;
}
currentChar = myString.charAt(i);
}
String currentWord = "";
while(currentChar != ' '){
i++;
currentWord += String.valueOf(currentChar);
if(i == myString.length()){
array[arrayPosition] = currentWord;
return array;
}
currentChar = myString.charAt(i);
}
wordCount++;
if(wordCount >= startWord){
array[arrayPosition] = currentWord;
arrayPosition++;
}
if (arrayPosition >= array.length){
return array;
}
}
}
return array;
}

@Override
public String restoreString(int[] indices) {
return null;
public String restoreString(int[] indices){
if(indices.length != myString.length()){
throw new IllegalArgumentException();
}
else {
for (int i = 0; i < indices.length; i++){
int num = indices[i];
if(num > myString.length() - 1 || num < 0){
throw new IndexOutOfBoundsException(i);
}
}
}
String convString = "";
String[] arrayString = new String[myString.length()];
String[] converted = new String[myString.length()];
for(int i = 0; i < myString.length(); i++){
String currentLetter = String.valueOf(myString.charAt(i));
arrayString[i] = currentLetter;
}
for(int i = 0; i < myString.length(); i++){
int index = indices[i];
converted[i] = arrayString[index];
}
for (int i = 0; i < myString.length(); i++){
convString += converted[i];
}
return convString;
}


}
Loading