Skip to content

Commit

Permalink
WFLY-4208: java 7 lang migration
Browse files Browse the repository at this point in the history
  • Loading branch information
emmartins authored and rafabene committed Dec 30, 2014
1 parent 235ce39 commit d8c7794
Show file tree
Hide file tree
Showing 50 changed files with 210 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void processEvent(SystemEvent event) throws AbortProcessingException {

public void startup() {
BasicCache<String, Object> cars = provider.getCacheContainer().getCache(CarManager.CACHE_NAME);
List<String> carNumbers = new ArrayList<String>();
List<String> carNumbers = new ArrayList<>();

utx = getUserTransactionFromJNDI();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ private List<String> getNumberPlateList(BasicCache<String, Object> carCacheLoc)
List<String> result = null;
List<String> carNumberList = (List<String>) carCacheLoc.get(CAR_NUMBERS_KEY);
if (carNumberList == null) {
result = new LinkedList<String>();
result = new LinkedList<>();
} else {
result = new LinkedList<String>(carNumberList);
result = new LinkedList<>(carNumberList);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void processEvent(SystemEvent event) throws AbortProcessingException {

public void startup() {
BasicCache<String, Object> cars = provider.getCacheContainer().getCache(CarManager.CACHE_NAME);
List<String> carNumbers = new ArrayList<String>();
List<String> carNumbers = new ArrayList<>();

try {
Car c = new Car("Ford Focus", 1.6, CarType.COMBI, "white", "FML 23-25", Country.CZECH_REPUBLIC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String addNewCar() {
carCache.put(CarManager.encode(car.getNumberPlate()), car);
List<String> carNumbers = getNumberPlateList();
if (carNumbers == null)
carNumbers = new LinkedList<String>();
carNumbers = new LinkedList<>();
carNumbers.add(car.getNumberPlate());
carCache.replace(CAR_NUMBERS_KEY, carNumbers);
return "home";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ <X extends Creature> void processInjectionTarget(@Observes ProcessInjectionTarge
Class<? extends Creature> klass = pit.getAnnotatedType().getJavaClass();
log.info("Setting up injection target for " + klass);
final Element entry = (Element) document.getElementsByTagName(klass.getSimpleName().toLowerCase()).item(0);
pit.setInjectionTarget(new XmlBackedWrappedInjectionTarget<X>(pit.getInjectionTarget(), entry));
pit.setInjectionTarget(new XmlBackedWrappedInjectionTarget<>(pit.getInjectionTarget(), entry));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@
*/
package org.jboss.as.quickstart.cdi.veto;

import java.util.logging.Logger;
import org.jboss.as.quickstart.cdi.veto.model.Car;

import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;

import org.jboss.as.quickstart.cdi.veto.model.Car;
import java.util.logging.Logger;

/**
* Producer for the {@link Car} entity.
Expand Down Expand Up @@ -69,15 +63,7 @@ public void save(Car car) {
em.joinTransaction();
em.persist(car);
utx.commit();
} catch (NotSupportedException e) {
log.severe("Transaction Error: " + e.getMessage());
} catch (SystemException e) {
log.severe("Transaction Error: " + e.getMessage());
} catch (HeuristicRollbackException e) {
log.severe("Transaction Error: " + e.getMessage());
} catch (RollbackException e) {
log.severe("Transaction Error: " + e.getMessage());
} catch (HeuristicMixedException e) {
} catch (Exception e) {
log.severe("Transaction Error: " + e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class SingletonServiceClient {
* @throws NamingException
*/
private SingletonServiceClient() throws NamingException {
final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
final Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);
String lookupName = "ejb:/wildfly-cluster-ha-singleton-service/ServiceAccessBean!" + ServiceAccess.class.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class ByIdExtension implements Extension {

// All nicks that needs to be found
private final List<String> ids = new LinkedList<String>();
private final List<String> ids = new LinkedList<>();

/**
* This method is fired for every component class supporting injection that may be instantiated by the container at runtime.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public List<MessageProvider> availableMessageProvidersImplementations() {
* @return the {@link List}
*/
private <T> List<T> convertToList(Iterator<T> i) {
List<T> list = new ArrayList<T>();
List<T> list = new ArrayList<>();
while (i.hasNext()) {
list.add(i.next());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class AsynchronousClient {
* @throws NamingException
*/
private AsynchronousClient() throws NamingException {
final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
final Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);
String lookupName = "ejb:/wildfly-ejb-asynchronous-ejb/AsynchronousAccessBean!" + AsynchronousAccess.class.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Future<String> longerRunning(long sleepTime) {
} catch (InterruptedException e) {
}
LOGGER.info("returning the result");
return new AsyncResult<String>("returning at " + new Date() + ", duration was " + sleepTime + "ms");
return new AsyncResult<>("returning at " + new Date() + ", duration was " + sleepTime + "ms");
}

@Asynchronous
Expand All @@ -80,6 +80,6 @@ public Future<String> interfaceAsync(long sleepTime) {
} catch (InterruptedException e) {
}
LOGGER.info("returning the result");
return new AsyncResult<String>("returning at " + new Date() + ", duration was " + sleepTime + "ms");
return new AsyncResult<>("returning at " + new Date() + ", duration was " + sleepTime + "ms");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ParallelAccessBean implements ParallelAccess {

@Override
public Collection<String> invokeAsyncParallel() {
ArrayList<String> results = new ArrayList<String>();
ArrayList<String> results = new ArrayList<>();
Future<String> call1 = asyncBean.longerRunning(5000);
Future<String> call2 = asyncBean.longerRunning(3000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class MainAppBean implements MainApp {
@PostConstruct
public void init() {
try {
final Hashtable<String, String> p = new Hashtable<String, String>();
final Hashtable<String, String> p = new Hashtable<>();
p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
this.iCtx = new InitialContext(p);
}catch (NamingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private String invokeAppOne(String text) {
// jboss-ejb-client.xml.
final AppOne bean = (AppOne) appOneScopedEjbContext.lookup("jboss-ejb-multi-server-app-one/ejb//AppOneBean!" + AppOne.class.getName());

StringBuffer result = new StringBuffer("{");
StringBuilder result = new StringBuilder("{");
for (int i = 0; i < 8; i++) {
// invoke on the bean
final String appOneResult = bean.invoke(text);
Expand Down Expand Up @@ -261,7 +261,7 @@ private String invokeAppTwo(String text) {
LOGGER.error("Could not create InitialContext('appTwoB')");
}

StringBuffer result = new StringBuffer(" appTwo loop(4 time A-B expected){");
StringBuilder result = new StringBuilder(" appTwo loop(4 time A-B expected){");
for (int i = 0; i < 4; i++) {
// invoke on the bean
String appResult = beanA.invokeSecured(text);
Expand Down Expand Up @@ -334,7 +334,7 @@ private String invokeAppTwoAlternative(String text) {
LOGGER.error("Could not create InitialContext('appTwoB')");
}

StringBuffer result = new StringBuffer(" appTwo loop(4 time A-B expected){");
StringBuilder result = new StringBuilder(" appTwo loop(4 time A-B expected){");
for (int i = 0; i < 4; i++) {
// invoke on the bean
String appResult = beanA.invokeSecured(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static void write(HttpServletResponse writer, String message) {
}

private static InitialContext getContext() throws NamingException {
final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
final Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
return new InitialContext(jndiProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,11 @@ protected Group[] getRoleSets() throws LoginException {
private Properties loadProperties(final String name) throws IOException {
ClassLoader classLoader = SecurityActions.getContextClassLoader();
URL url = classLoader.getResource(name);
InputStream is = url.openStream();
try {
try (InputStream is = url.openStream()) {
Properties props = new Properties();
props.load(is);
return props;

} finally {
is.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class EJBUtil {

static IntermediateEJBRemote lookupIntermediateEJB() throws Exception {
final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
final Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);

Expand All @@ -38,7 +38,7 @@ static IntermediateEJBRemote lookupIntermediateEJB() throws Exception {
}

static SecuredEJBRemote lookupSecuredEJB() throws Exception {
final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
final Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
if (configurationName.equals(name) == false) {
throw new IllegalArgumentException("Unexpected configuration name '" + name + "'");
}
Map<String, String> options = new HashMap<String, String>();
Map<String, String> options = new HashMap<>();
options.put("multi-threaded", "true");
options.put("restore-login-identity", "true");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class EJBUtil {

static SecuredEJBRemote lookupSecuredEJB() throws Exception {
final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
final Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,11 @@ private interface PropertiesAction {
public Properties loadProperties(final String name) throws IOException {
ClassLoader classLoader = SecurityActions.getContextClassLoader();
URL url = classLoader.getResource(name);
InputStream is = url.openStream();
try {
try (InputStream is = url.openStream()) {
Properties props = new Properties();
props.load(is);
return props;

} finally {
is.close();
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void main(String[] args) throws Exception {
}

static SecuredRemote lookupEJB() throws Exception {
final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
final Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String sayHello() {
public String sayHelloToName(final String name) {

/* Create a list with just the one value */
final List<String> names = new ArrayList<String>();
final List<String> names = new ArrayList<>();
names.add(name);

return sayHelloToNames(names);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void testHelloNames() {
System.out.println("[Client] Requesting the WebService to say Hello to John, Mary and Mark.");

// Create the array of names for the WebService to say hello to.
final List<String> names = new ArrayList<String>();
final List<String> names = new ArrayList<>();
names.add("John");
names.add("Mary");
names.add("Mark");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void testHelloNames() {
System.out.println("[Client] Requesting the WebService to say Hello to John, Mary and Mark.");

// Create the array of names for the WebService to say hello to.
final List<String> names = new ArrayList<String>();
final List<String> names = new ArrayList<>();
names.add("John");
names.add("Mary");
names.add("Mark");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ public Response createMember(Member member) {
builder = createViolationResponse(ce.getConstraintViolations());
} catch (ValidationException e) {
// Handle the unique constrain violation
Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();
responseObj.put("email", "Email taken");
builder = Response.status(Response.Status.CONFLICT).entity(responseObj);
} catch (Exception e) {
// Handle generic exceptions
Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();
responseObj.put("error", e.getMessage());
builder = Response.status(Response.Status.BAD_REQUEST).entity(responseObj);
}
Expand Down Expand Up @@ -157,7 +157,7 @@ private void validateMember(Member member) throws ConstraintViolationException,
private Response.ResponseBuilder createViolationResponse(Set<ConstraintViolation<?>> violations) {
log.fine("Validation completed. violations found: " + violations.size());

Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();

for (ConstraintViolation<?> violation : violations) {
responseObj.put(violation.getPropertyPath().toString(), violation.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ public Response createMember(Member member) {
builder = createViolationResponse(ce.getConstraintViolations());
} catch (ValidationException e) {
// Handle the unique constrain violation
Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();
responseObj.put("email", "Email taken");
builder = Response.status(Response.Status.CONFLICT).entity(responseObj);
} catch (Exception e) {
// Handle generic exceptions
Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();
responseObj.put("error", e.getMessage());
builder = Response.status(Response.Status.BAD_REQUEST).entity(responseObj);
}
Expand Down Expand Up @@ -156,7 +156,7 @@ private void validateMember(Member member) throws ConstraintViolationException,
private Response.ResponseBuilder createViolationResponse(Set<ConstraintViolation<?>> violations) {
log.fine("Validation completed. violations found: " + violations.size());

Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();

for (ConstraintViolation<?> violation : violations) {
responseObj.put(violation.getPropertyPath().toString(), violation.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public Response createMember(Member member) {
builder = createViolationResponse(ce.getConstraintViolations());
} catch (ValidationException e) {
// Handle the unique constrain violation
Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();
responseObj.put("email", "Email taken");
builder = Response.status(Response.Status.CONFLICT).entity(responseObj);
} catch (Exception e) {
// Handle generic exceptions
Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();
responseObj.put("error", e.getMessage());
builder = Response.status(Response.Status.BAD_REQUEST).entity(responseObj);
}
Expand Down Expand Up @@ -158,7 +158,7 @@ private void validateMember(Member member) throws ConstraintViolationException,
private Response.ResponseBuilder createViolationResponse(Set<ConstraintViolation<?>> violations) {
log.fine("Validation completed. violations found: " + violations.size());

Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();

for (ConstraintViolation<?> violation : violations) {
responseObj.put(violation.getPropertyPath().toString(), violation.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ public Response createMember(Member member) {
builder = createViolationResponse(ce.getConstraintViolations());
} catch (ValidationException e) {
// Handle the unique constrain violation
Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();
responseObj.put("email", "Email taken");
builder = Response.status(Response.Status.CONFLICT).entity(responseObj);
} catch (Exception e) {
// Handle generic exceptions
Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();
responseObj.put("error", e.getMessage());
builder = Response.status(Response.Status.BAD_REQUEST).entity(responseObj);
}
Expand Down Expand Up @@ -156,7 +156,7 @@ private void validateMember(Member member) throws ConstraintViolationException,
private Response.ResponseBuilder createViolationResponse(Set<ConstraintViolation<?>> violations) {
log.fine("Validation completed. violations found: " + violations.size());

Map<String, String> responseObj = new HashMap<String, String>();
Map<String, String> responseObj = new HashMap<>();

for (ConstraintViolation<?> violation : violations) {
responseObj.put(violation.getPropertyPath().toString(), violation.getMessage());
Expand Down
Loading

0 comments on commit d8c7794

Please sign in to comment.