Skip to content

Commit

Permalink
MockApplication - update methods types
Browse files Browse the repository at this point in the history
  • Loading branch information
Emkas committed Jun 28, 2022
1 parent 3d83260 commit 5c80248
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions impl/src/test/java/com/sun/faces/mock/MockApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public ExpressionFactory getExpressionFactory() {
}

@Override
public Object evaluateExpressionGet(FacesContext context,
public <T> T evaluateExpressionGet(FacesContext context,
String expression,
Class expectedType) throws ELException {
Class<? extends T> expectedType) throws ELException {
ValueExpression ve = getExpressionFactory().createValueExpression(context.getELContext(), expression, expectedType);
return ve.getValue(context.getELContext());
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public void setStateManager(StateManager stateManager) {
this.stateManager = stateManager;
}

private Map components = new HashMap();
private Map<String, String> components = new HashMap<>();

@Override
public void addComponent(String componentType, String componentClass) {
Expand All @@ -212,9 +212,9 @@ public void addComponent(String componentType, String componentClass) {

@Override
public UIComponent createComponent(String componentType) {
String componentClass = (String) components.get(componentType);
String componentClass = components.get(componentType);
try {
Class clazz = Class.forName(componentClass);
Class<?> clazz = Class.forName(componentClass);
return ((UIComponent) clazz.newInstance());
} catch (Exception e) {
throw new FacesException(e);
Expand All @@ -230,27 +230,27 @@ public UIComponent createComponent(ValueExpression componentExpression,
}

@Override
public Iterator getComponentTypes() {
public Iterator<String> getComponentTypes() {
return (components.keySet().iterator());
}

private Map converters = new HashMap();
private Map<String, String> converters = new HashMap<>();

@Override
public void addConverter(String converterId, String converterClass) {
converters.put(converterId, converterClass);
}

@Override
public void addConverter(Class targetClass, String converterClass) {
public void addConverter(Class<?> targetClass, String converterClass) {
throw new UnsupportedOperationException();
}

@Override
public Converter createConverter(String converterId) {
String converterClass = (String) converters.get(converterId);
String converterClass = converters.get(converterId);
try {
Class clazz = Class.forName(converterClass);
Class<?> clazz = Class.forName(converterClass);
return ((Converter) clazz.newInstance());
} catch (Exception e) {
throw new FacesException(e);
Expand All @@ -263,12 +263,12 @@ public Converter createConverter(Class targetClass) {
}

@Override
public Iterator getConverterIds() {
public Iterator<String> getConverterIds() {
return (converters.keySet().iterator());
}

@Override
public Iterator getConverterTypes() {
public Iterator<Class<?>> getConverterTypes() {
throw new UnsupportedOperationException();
}

Expand All @@ -284,7 +284,7 @@ public String getMessageBundle() {
return messageBundle;
}

private Map validators = new HashMap();
private Map<String, String> validators = new HashMap<>();

@Override
public void addValidator(String validatorId, String validatorClass) {
Expand All @@ -293,27 +293,27 @@ public void addValidator(String validatorId, String validatorClass) {

@Override
public Validator createValidator(String validatorId) {
String validatorClass = (String) validators.get(validatorId);
String validatorClass = validators.get(validatorId);
try {
Class clazz = Class.forName(validatorClass);
Class<?> clazz = Class.forName(validatorClass);
return ((Validator) clazz.newInstance());
} catch (Exception e) {
throw new FacesException(e);
}
}

@Override
public Iterator getValidatorIds() {
public Iterator<String> getValidatorIds() {
return (validators.keySet().iterator());
}

@Override
public Iterator getSupportedLocales() {
return Collections.EMPTY_LIST.iterator();
public Iterator<Locale> getSupportedLocales() {
return Collections.emptyListIterator();
}

@Override
public void setSupportedLocales(Collection newLocales) {
public void setSupportedLocales(Collection<Locale> newLocales) {
}

@Override
Expand Down Expand Up @@ -750,7 +750,7 @@ private static class SystemEventHelper {
public SystemEventHelper() {

systemEventInfoCache
= new Cache<Class<? extends SystemEvent>, SystemEventInfo>(
= new Cache<>(
new Factory<Class<? extends SystemEvent>, SystemEventInfo>() {
@Override
public SystemEventInfo newInstance(final Class<? extends SystemEvent> arg)
Expand Down Expand Up @@ -802,23 +802,23 @@ public ComponentSystemEventHelper() {
// Initialize the 'sources' cache for, ahem, readability...
// ~generics++
Factory<Class<?>, Cache<Class<? extends SystemEvent>, EventInfo>> eventCacheFactory
= new Factory<Class<?>, Cache<Class<? extends SystemEvent>, EventInfo>>() {
= new Factory<>() {
@Override
public Cache<Class<? extends SystemEvent>, EventInfo> newInstance(
final Class<?> sourceClass)
throws InterruptedException {
Factory<Class<? extends SystemEvent>, EventInfo> eventInfoFactory
= new Factory<Class<? extends SystemEvent>, EventInfo>() {
= new Factory<>() {
@Override
public EventInfo newInstance(final Class<? extends SystemEvent> systemEventClass)
throws InterruptedException {
return new EventInfo(systemEventClass, sourceClass);
}
};
return new Cache<Class<? extends SystemEvent>, EventInfo>(eventInfoFactory);
return new Cache<>(eventInfoFactory);
}
};
sourceCache = new Cache<Class<?>, Cache<Class<? extends SystemEvent>, EventInfo>>(eventCacheFactory);
sourceCache = new Cache<>(eventCacheFactory);

}

Expand All @@ -841,7 +841,7 @@ public EventInfo getEventInfo(Class<? extends SystemEvent> systemEvent,
*/
private static class SystemEventInfo {

private Cache<Class<?>, EventInfo> cache = new Cache<Class<?>, EventInfo>(
private Cache<Class<?>, EventInfo> cache = new Cache<>(
new Factory<Class<?>, EventInfo>() {
@Override
public EventInfo newInstance(Class<?> arg)
Expand Down Expand Up @@ -888,8 +888,8 @@ public EventInfo(Class<? extends SystemEvent> systemEvent,

this.systemEvent = systemEvent;
this.sourceClass = sourceClass;
this.listeners = new CopyOnWriteArraySet<SystemEventListener>();
this.constructorMap = new HashMap<Class<?>, Constructor>();
this.listeners = new CopyOnWriteArraySet<>();
this.constructorMap = new HashMap<>();
if (!sourceClass.equals(Void.class)) {
eventConstructor = getEventConstructor(sourceClass);
}
Expand Down Expand Up @@ -981,8 +981,7 @@ private interface Factory<K, V> {
*/
private static final class Cache<K, V> {

private ConcurrentMap<K, Future<V>> cache
= new ConcurrentHashMap<K, Future<V>>();
private ConcurrentMap<K, Future<V>> cache = new ConcurrentHashMap<>();
private Factory<K, V> factory;

// -------------------------------------------------------- Constructors
Expand Down Expand Up @@ -1016,13 +1015,13 @@ public V get(final K key) {
while (true) {
Future<V> f = cache.get(key);
if (f == null) {
Callable<V> callable = new Callable<V>() {
Callable<V> callable = new Callable<>() {
@Override
public V call() throws Exception {
return factory.newInstance(key);
}
};
FutureTask<V> ft = new FutureTask<V>(callable);
FutureTask<V> ft = new FutureTask<>(callable);
// here is the real beauty of the concurrent utilities.
// 1. putIfAbsent() is atomic
// 2. putIfAbsent() will return the value already associated
Expand Down

0 comments on commit 5c80248

Please sign in to comment.