Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General code fix 1 #555

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![License](http://img.shields.io/:license-apache-blue.svg)
[![Gitter](https://badges.gitter.im/davidsowerby/krail.svg)](https://gitter.im/davidsowerby/krail?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Build Status](https://travis-ci.org/davidsowerby/krailkrail.svg?branch=master)](https://travis-ci.org/davidsowerby/krail)
[![Build Status](https://travis-ci.org/davidsowerby/krail.svg?branch=master)](https://travis-ci.org/davidsowerby/krail)
[![Coverage Status](https://coveralls.io/repos/github/davidsowerby/krail/badge.svg?branch=master)](https://coveralls.io/github/davidsowerby/krail?branch=master)

Krail provides a framework for rapid Java web development by combining Vaadin, Guice, Apache Shiro, Apache Commons Configuration and others. For more information, see the comprehensive [Tutorial](http://krail.readthedocs.org/en/master/), which also makes a reasonable demo. (You can clone directly from the [Tutorial repo](https://github.com/davidsowerby/krail-tutorial))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected void doStart() {
log.debug("adding configuration from {} at index {}", file.getAbsolutePath(), k);
} catch (Exception ce) {
if (!iniConfig.isOptional()) {
String msg = ("Configuration Service failed to start, unable to load required configuration file: {}");
String msg = "Configuration Service failed to start, unable to load required configuration file: {}";
log.error(msg, file.getAbsolutePath());
throw new ConfigurationException(msg + file.getAbsolutePath(), ce);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DefaultOptionElementConverter() {
public String convertValueToString(@Nonnull Object value) {
Class<?> modelType = value.getClass();
if (modelType == String.class) {
return ((String) value);
return (String) value;
} else if (modelType == Integer.class) {
return Ints.stringConverter()
.reverse()
Expand Down Expand Up @@ -85,7 +85,7 @@ public String convertValueToString(@Nonnull Object value) {
@Nonnull
public <V> V convertStringToValue(@Nonnull Class<V> elementClass, @Nonnull String valueString) {
if (elementClass == String.class) {
return ((V) valueString);
return (V) valueString;
} else if (elementClass == Integer.class) {
return (V) Ints.stringConverter()
.convert(valueString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public <E> OptionList<E> convertToModel(@Nonnull OptionList<E> defaultValue, @No
String unescaped = StringEscapeUtils.unescapeCsv(s);
elementList.add(converter.convertStringToValue(elementClass, unescaped));
});
return new OptionList<E>(elementList, elementClass);
return new OptionList<>(elementList, elementClass);
}
}
8 changes: 4 additions & 4 deletions src/main/java/uk/q3c/krail/core/eventbus/EventBusModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ protected void bindConfigurationErrorHandlers() {
* All buses use the default error handler by default. Override this method to provide alternative bindings.
*/
protected void bindPublicationErrorHandlers() {
bind((IPublicationErrorHandler.class)).annotatedWith(UIBus.class)
bind(IPublicationErrorHandler.class).annotatedWith(UIBus.class)
.to(DefaultEventBusErrorHandler.class);
bind((IPublicationErrorHandler.class)).annotatedWith(SessionBus.class)
bind(IPublicationErrorHandler.class).annotatedWith(SessionBus.class)
.to(DefaultEventBusErrorHandler.class);
bind((IPublicationErrorHandler.class)).annotatedWith(GlobalBus.class)
bind(IPublicationErrorHandler.class).annotatedWith(GlobalBus.class)
.to(DefaultEventBusErrorHandler.class);
}

Expand Down Expand Up @@ -187,7 +187,7 @@ private PubSubSupport<BusMessage> createBus(IBusConfiguration config, IPublicati
config.setProperty(Properties.Handler.PublicationError, publicationErrorHandler);
config.addConfigurationErrorHandler(configurationErrorHandler);
PubSubSupport<BusMessage> eventBus;
eventBus = (useAsync) ? new MBassador<>(config) : new SyncMessageBus<>(config);
eventBus = useAsync ? new MBassador<>(config) : new SyncMessageBus<>(config);
((AbstractPubSubSupport) eventBus).addErrorHandler(publicationErrorHandler);
log.debug("instantiated a {} Bus with id {}", name, eventBus.getRuntime()
.get(Properties.Common.Id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void reset() {
* Cache class for type capture and minimizing ThreadLocal lookups.
*/
public static class Cache {
private final Map<Key<?>, Object> map = new HashMap<Key<?>, Object>();
private final Map<Key<?>, Object> map = new HashMap<>();

public Cache() {
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/uk/q3c/krail/core/guice/uiscope/UIScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class UIScope implements Scope {

private static volatile UIScope current;

private final Map<UIKey, Map<Key<?>, Object>> cache = new TreeMap<UIKey, Map<Key<?>, Object>>();
private final Map<UIKey, Map<Key<?>, Object>> cache = new TreeMap<>();

public UIScope() {
super();
Expand Down Expand Up @@ -71,7 +71,7 @@ Map<Key<?>, Object> getScopedObjectMap(UIKey uiKey) {
}

private Map<Key<?>, Object> createCacheEntry(UIKey uiKey) {
Map<Key<?>, Object> uiEntry = new HashMap<Key<?>, Object>();
Map<Key<?>, Object> uiEntry = new HashMap<>();
cache.put(uiKey, uiEntry);
log.debug("created a scope cache for UIScope with key: {}", uiKey);
return uiEntry;
Expand Down Expand Up @@ -104,7 +104,7 @@ public void flush() {

@Override
public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped) {
return new UIScopeProvider<T>(this, key, unscoped);
return new UIScopeProvider<>(this, key, unscoped);
}

public ImmutableList<UIKey> scopeKeys() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Map<Key<?>, Object> getScopedObjectMap(VaadinSession vaadinSession) {
}

private Map<Key<?>, Object> createCacheEntry(VaadinSession vaadinSession) {
Map<Key<?>, Object> sessionEntry = new HashMap<Key<?>, Object>();
Map<Key<?>, Object> sessionEntry = new HashMap<>();
cache.put(vaadinSession, sessionEntry);
log.debug("created a scope cache for VaadinSessionScope with key: {}", vaadinSession);
return sessionEntry;
Expand Down Expand Up @@ -102,7 +102,7 @@ public void flush() {

@Override
public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped) {
return new VaadinSessionScopeProvider<T>(this, key, unscoped);
return new VaadinSessionScopeProvider<>(this, key, unscoped);
}

public ImmutableList<VaadinSession> scopeKeys() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void translate(@Nullable Object target) {
return;
}
log.debug("scanning class '{}' for I18N annotations", target.getClass());
List<Object> processedFields = new ArrayList<Object>();
List<Object> processedFields = new ArrayList<>();
translate(processedFields, target);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
*/
public class NavigationState implements Serializable {
private static Logger log = getLogger(NavigationState.class);
private final Map<String, String> parameters = new LinkedHashMap<String, String>();
private final Map<String, String> parameters = new LinkedHashMap<>();
// fragment is out of date
private boolean fragmentChanged;
private boolean partsChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ protected DefaultUserSitemapSorters(AlphabeticAscending alphaAscending, Alphabet
private void select() {
switch (sortType) {
case ALPHA:
selectedComparator = (ascending) ? alphaAscending : alphaDescending;
selectedComparator = ascending ? alphaAscending : alphaDescending;
break;
case INSERTION:
selectedComparator = (ascending) ? insertionAscending : insertionDescending;
selectedComparator = ascending ? insertionAscending : insertionDescending;
break;
case POSITION:
selectedComparator = (ascending) ? positionAscending : positionDescending;
selectedComparator = ascending ? positionAscending : positionDescending;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ public void popup(@Nonnull OptionContext context, I18NKey windowCaption) {

Button defaultsButton = new Button(translate.from(LabelKey.Reset_to_Default));
defaultsButton.setId(ID.getId(optionKeyName, this, defaultsButton));
defaultsButton.addClickListener((event -> {
defaultsButton.addClickListener(event -> {
option.delete(key, 0);
//we create an event to represent the field which whose value will be affected by this change
AbstractField.ValueChangeEvent changeEvent = new AbstractField.ValueChangeEvent(uiField);
context.optionValueChanged(changeEvent);
//update the value of the field - it may have changed
setFieldValue(uiField, option.get(key));
}));
});
baseLayout.addComponent(new FormLayout(uiField), 0, row);
baseLayout.addComponent(new FormLayout(defaultsButton), 1, row);
row++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public String load(@Nonnull PatternCacheKey cacheKey) throws Exception {
*/
protected String stubValue(Class<? extends Annotation> source, PatternCacheKey cacheKey) {
Boolean stubWithKeyName = option.get(optionKeyStubWithKeyName.qualifiedWith(source.getSimpleName()));
return (stubWithKeyName) ? cacheKey.getKeyAsEnum()
return stubWithKeyName ? cacheKey.getKeyAsEnum()
.name() : option.get(optionKeyStubValue.qualifiedWith(source.getSimpleName()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected Optional<String> getStringValue(@Nonnull OptionCacheKey cacheKey) {
protected <V> Optional<String> getRankedValue(@Nonnull OptionCacheKey<V> cacheKey, boolean lowest) {
ImmutableList<String> ranks = cacheKey.getHierarchy()
.ranksForCurrentUser();
ImmutableList<String> ranksToUse = (lowest) ? ranks.reverse() : ranks;
ImmutableList<String> ranksToUse = lowest ? ranks.reverse() : ranks;
for (String rank : ranksToUse) {
OptionCacheKey<V> specificKey = new OptionCacheKey<>(cacheKey, rank, RankOption.SPECIFIC_RANK);
Optional<String> stringValue = getStringValue(specificKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public synchronized List<T> findDependants(@Nonnull T dependency, @Nonnull Selec

private Collection<ServiceEdge> getDependenciesEdges(@Nonnull T dependant) {
Collection<ServiceEdge> edges = graph.getOutEdges(dependant);
return (edges == null) ? new ArrayList<ServiceEdge>() : edges;
return (edges == null) ? new ArrayList<>() : edges;
}


private Collection<ServiceEdge> getDependantsEdges(@Nonnull T dependency) {
Collection<ServiceEdge> edges = graph.getInEdges(dependency);
return (edges == null) ? new ArrayList<ServiceEdge>() : edges;
return (edges == null) ? new ArrayList<>() : edges;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public String subjectName() {
Subject subject = subjectProvider.get();
boolean authenticated = subject.isAuthenticated();
boolean remembered = subject.isRemembered();
String name = (authenticated) ? subject.getPrincipal()
String name = authenticated ? subject.getPrincipal()
.toString() : translate.from(LabelKey.Guest);
return (remembered) ? subject.getPrincipal() + "?" : name;
return remembered ? subject.getPrincipal() + "?" : name;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public List<MasterSitemapNode> authorisedChildNodes(@Nonnull Subject subject, @N
checkNotNull(sitemap);
checkNotNull(parentNode);
List<MasterSitemapNode> subnodes = sitemap.getChildren(parentNode);
ArrayList<MasterSitemapNode> authorisedSubNodes = new ArrayList<MasterSitemapNode>();
ArrayList<MasterSitemapNode> authorisedSubNodes = new ArrayList<>();
for (MasterSitemapNode node : subnodes) {
if (isAuthorised(subject, sitemap, node)) {
authorisedSubNodes.add(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,20 @@ public KrailShiroAopModule select(Class<? extends Annotation> annotationClass) {

protected void bindInterceptors(Provider<SubjectProvider> subjectProviderProvider, Provider<AnnotationResolver> annotationResolverProvider) {
if (selectedAnnotations.contains(RequiresPermissions.class)) {
bindMethodInterceptor((RequiresPermissions.class), permissionsInterceptor(subjectProviderProvider, annotationResolverProvider));
bindMethodInterceptor(RequiresPermissions.class, permissionsInterceptor(subjectProviderProvider, annotationResolverProvider));
}
if (selectedAnnotations.contains(RequiresUser.class)) {
bindMethodInterceptor((RequiresUser.class), userInterceptor(subjectProviderProvider, annotationResolverProvider));
bindMethodInterceptor(RequiresUser.class, userInterceptor(subjectProviderProvider, annotationResolverProvider));
}
if (selectedAnnotations.contains(RequiresGuest.class)) {
bindMethodInterceptor((RequiresGuest.class), guestInterceptor(subjectProviderProvider, annotationResolverProvider));
bindMethodInterceptor(RequiresGuest.class, guestInterceptor(subjectProviderProvider, annotationResolverProvider));
}
if (selectedAnnotations.contains(RequiresAuthentication.class)) {
bindMethodInterceptor((RequiresAuthentication.class), authenticatedInterceptor(subjectProviderProvider, annotationResolverProvider));
bindMethodInterceptor(RequiresAuthentication.class, authenticatedInterceptor(subjectProviderProvider, annotationResolverProvider));
}

if (selectedAnnotations.contains(RequiresRoles.class)) {
bindMethodInterceptor((RequiresRoles.class), rolesInterceptor(subjectProviderProvider, annotationResolverProvider));
bindMethodInterceptor(RequiresRoles.class, rolesInterceptor(subjectProviderProvider, annotationResolverProvider));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ protected Object findPropertyId(java.lang.reflect.Field memberField) {
* The bean to use as data source.
*/
public void setItemDataSource(T bean) {
BeanItem<T> beanItem = new BeanItem<T>(bean);
BeanItem<T> beanItem = new BeanItem<>(bean);
setItemDataSource(beanItem);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected final void build() {
log.debug("building with Locale={}", currentLocale.getLocale());
boolean authenticated = subjectProvider.get()
.isAuthenticated();
String caption = (authenticated) ? translate.from(LabelKey.Log_Out) : translate.from(LabelKey.Log_In);
String caption = authenticated ? translate.from(LabelKey.Log_Out) : translate.from(LabelKey.Log_In);
log.debug("Caption is '{}'", caption);
login_logout_Button.setCaption(caption.toLowerCase());
usernameLabel.setValue(subjectIdentifier.subjectName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected void organiseButtons(List<UserSitemapNode> nodeList) {
log.debug("{} nodes to display before filtering", nodeList.size());
List<UserSitemapNode> filteredList = filteredList(nodeList);
log.debug("{} nodes to display after filtering", filteredList.size());
int maxIndex = (filteredList.size() > buttons.size() ? filteredList.size() : buttons.size());
int maxIndex = filteredList.size() > buttons.size() ? filteredList.size() : buttons.size();
for (int i = 0; i < maxIndex; i++) {
// nothing left in chain
if (i + 1 > filteredList.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class TestEventBusModule extends EventBusModule {
*/
@Override
protected void bindPublicationErrorHandlers() {
bind((IPublicationErrorHandler.class)).annotatedWith(UIBus.class)
bind(IPublicationErrorHandler.class).annotatedWith(UIBus.class)
.to(TestEventBusErrorHandler.class);
bind((IPublicationErrorHandler.class)).annotatedWith(SessionBus.class)
bind(IPublicationErrorHandler.class).annotatedWith(SessionBus.class)
.to(TestEventBusErrorHandler.class);
bind((IPublicationErrorHandler.class)).annotatedWith(GlobalBus.class)
bind(IPublicationErrorHandler.class).annotatedWith(GlobalBus.class)
.to(TestEventBusErrorHandler.class);
}
}
20 changes: 10 additions & 10 deletions src/main/java/uk/q3c/util/BasicForest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class BasicForest<V> implements Serializable {
private Forest<V, Integer> graph;

public BasicForest() {
graph = new DelegateForest<V, Integer>(new DirectedOrderedSparseMultigraph<>());
graph = new DelegateForest<>(new DirectedOrderedSparseMultigraph<>());
}

public boolean hasChild(V parentNode, V childNode) {
Expand Down Expand Up @@ -133,7 +133,7 @@ private Integer newEdge() {
*/
public V getNode(V node) {
Collection<V> x = graph.getVertices();
List<V> list = new ArrayList<V>(x);
List<V> list = new ArrayList<>(x);
int n = list.indexOf(node);
if (n < 0) {
return null;
Expand All @@ -143,7 +143,7 @@ public V getNode(V node) {

public List<V> getChildren(V parentNode) {
Collection<V> children = graph.getChildren(parentNode);
List<V> result = new ArrayList<V>();
List<V> result = new ArrayList<>();
if (children != null) {
result.addAll(children);
}
Expand All @@ -159,7 +159,7 @@ public List<V> getChildren(V parentNode) {
*/
public List<V> getSubtreeNodes(V parentNode) {
Collection<V> children = graph.getChildren(parentNode);
List<V> list = new ArrayList<V>();
List<V> list = new ArrayList<>();
list.add(parentNode);
if (children != null) {
for (V v : children) {
Expand Down Expand Up @@ -200,13 +200,13 @@ private void findLeaves(V parentNode, List<V> leaves) {
* @see #findLeaves(Object)
*/
public List<V> findLeaves() {
List<V> leaves = new ArrayList<V>();
List<V> leaves = new ArrayList<>();
findLeaves(getRoot(), leaves);
return leaves;
}

public List<V> findLeaves(V parentNode) {
List<V> leaves = new ArrayList<V>();
List<V> leaves = new ArrayList<>();
findLeaves(parentNode, leaves);
return leaves;
}
Expand All @@ -221,7 +221,7 @@ public Collection<V> getEntries() {
}

public void clear() {
graph = new DelegateForest<V, Integer>();
graph = new DelegateForest<>();
edgeCount = 0;
}

Expand All @@ -233,7 +233,7 @@ public void clear() {
*/
public List<V> getRoots() {
Collection<Tree<V, Integer>> t = graph.getTrees();
List<V> branchRoots = new ArrayList<V>();
List<V> branchRoots = new ArrayList<>();
for (Tree<V, Integer> branch : t) {
branchRoots.add(branch.getRoot());
}
Expand Down Expand Up @@ -295,7 +295,7 @@ public Forest<V, Integer> getGraph() {
* @return
*/
public List<V> getAllNodes() {
return new ArrayList<V>(graph.getVertices());
return new ArrayList<>(graph.getVertices());
}

public V getRootFor(V node) {
Expand Down Expand Up @@ -359,7 +359,7 @@ private void mergeSubGraph(BasicForest<V> sourceSubGraph, V targetParentVertex)
* @return
*/
private BasicForest<V> subGraph(V root, V newRoot) {
BasicForest<V> subGraph = new BasicForest<V>();
BasicForest<V> subGraph = new BasicForest<>();
copyChildren(this, root, subGraph, newRoot);
return subGraph;
}
Expand Down