quick-guide-to-the-java-stringtokenizer (#1587)
* rest with spark java * 4 * Update Application.java * indentation changes * spring @requestmapping shortcuts * removing spring requestmapping and pushing spring-mvc-java * Joining/Splitting Strings with Java and Stream API * adding more join/split functionality * changing package name * testcase change * adding webutils * adding testcase for WebUtils and ServletRequestUtils * adding testcase * spring-security-stormpath * adding ratpack module * adding pom.xml * adding following modules with updated testcase : DB, Filter, Json * adding spring-boot custom banner tutorial * changing banner format in plain text * Delete banner.txt~ * Delete b.txt~ * CORS in JAX-RS * ratpack with google guice * adding factory instance example * quick-guide-to-the-java-stringtokenizer * Update Application.java * Delete MovieCrudService.java~
This commit is contained in:
parent
a4f4301196
commit
50ff1d18c4
@ -0,0 +1,21 @@
|
|||||||
|
package com.baeldung.stringtokenizer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public List<String> getTokens(String str) {
|
||||||
|
List<String> tokens = new ArrayList<String>();
|
||||||
|
// StringTokenizer tokenizer = new StringTokenizer( str );
|
||||||
|
StringTokenizer tokenizer = new StringTokenizer( str , "," );
|
||||||
|
// StringTokenizer tokenizer = new StringTokenizer( str , "," , true );
|
||||||
|
while (tokenizer.hasMoreElements()) {
|
||||||
|
tokens.add( tokenizer.nextToken() );
|
||||||
|
// tokens.add( tokenizer.nextToken( "," ) );
|
||||||
|
}
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.baeldung.stringtokenizer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class ApplicationTest {
|
||||||
|
|
||||||
|
Application application = new Application();
|
||||||
|
List<String> expectedTokens = new ArrayList<String>();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
expectedTokens.add( "Welcome" );
|
||||||
|
expectedTokens.add( "to" );
|
||||||
|
expectedTokens.add( "baeldung.com" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenString_thenGetListOfString() {
|
||||||
|
String str = "Welcome,to,baeldung.com";
|
||||||
|
List<String> actualTokens = application.getTokens(str);
|
||||||
|
assertEquals(expectedTokens, actualTokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -46,3 +46,4 @@ public class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
resteasy/src/main/java/com/baeldung/filter/CORSFilter.java
Normal file
18
resteasy/src/main/java/com/baeldung/filter/CORSFilter.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.baeldung.filter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.ws.rs.container.ContainerRequestContext;
|
||||||
|
import javax.ws.rs.container.ContainerResponseContext;
|
||||||
|
import javax.ws.rs.container.ContainerResponseFilter;
|
||||||
|
|
||||||
|
public class CORSFilter implements ContainerResponseFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
|
||||||
|
throws IOException {
|
||||||
|
responseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user