Removed dependency on 'org.apache.commons.collections' (#1244)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2019-11-28 18:43:10 +01:00 committed by Kai Kreuzer
parent 0046774eb6
commit e85e1a6f44
3 changed files with 27 additions and 40 deletions

View File

@ -13,12 +13,13 @@
package org.openhab.core.items;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import org.apache.commons.collections.ListUtils;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.slf4j.Logger;
@ -121,21 +122,20 @@ public class GroupItem extends GenericItem implements StateChangeListener {
* @return the accepted data types of this group item
*/
@Override
@SuppressWarnings("unchecked")
public List<Class<? extends State>> getAcceptedDataTypes() {
if (baseItem != null) {
return baseItem.getAcceptedDataTypes();
} else {
List<Class<? extends State>> acceptedDataTypes = null;
for (Item item : members) {
if (acceptedDataTypes == null) {
if (acceptedDataTypes == null || acceptedDataTypes.isEmpty()) {
acceptedDataTypes = item.getAcceptedDataTypes();
} else {
acceptedDataTypes = ListUtils.intersection(acceptedDataTypes, item.getAcceptedDataTypes());
acceptedDataTypes = item.getAcceptedDataTypes().stream().distinct()
.filter(acceptedDataTypes::contains).collect(Collectors.toList());
}
}
return acceptedDataTypes == null ? ListUtils.EMPTY_LIST : acceptedDataTypes;
return acceptedDataTypes == null ? Collections.emptyList() : acceptedDataTypes;
}
}
@ -147,21 +147,20 @@ public class GroupItem extends GenericItem implements StateChangeListener {
* @return the accepted command types of this group item
*/
@Override
@SuppressWarnings("unchecked")
public List<Class<? extends Command>> getAcceptedCommandTypes() {
if (baseItem != null) {
return baseItem.getAcceptedCommandTypes();
} else {
List<Class<? extends Command>> acceptedCommandTypes = null;
for (Item item : members) {
if (acceptedCommandTypes == null) {
if (acceptedCommandTypes == null || acceptedCommandTypes.isEmpty()) {
acceptedCommandTypes = item.getAcceptedCommandTypes();
} else {
acceptedCommandTypes = ListUtils.intersection(acceptedCommandTypes, item.getAcceptedCommandTypes());
acceptedCommandTypes = item.getAcceptedCommandTypes().stream().distinct()
.filter(acceptedCommandTypes::contains).collect(Collectors.toList());
}
}
return acceptedCommandTypes == null ? ListUtils.EMPTY_LIST : acceptedCommandTypes;
return acceptedCommandTypes == null ? Collections.emptyList() : acceptedCommandTypes;
}
}
@ -174,9 +173,6 @@ public class GroupItem extends GenericItem implements StateChangeListener {
}
}
/**
* @{inheritDoc
*/
@Override
protected void internalSend(Command command) {
if (eventPublisher != null) {
@ -187,9 +183,6 @@ public class GroupItem extends GenericItem implements StateChangeListener {
}
}
/**
* @{inheritDoc
*/
@Override
public State getStateAs(Class<? extends State> typeClass) {
State newState = function.getStateAs(getAllMembers(), typeClass);
@ -204,9 +197,6 @@ public class GroupItem extends GenericItem implements StateChangeListener {
return newState;
}
/**
* @{inheritDoc
*/
@Override
public String toString() {
return getName() + " (" + "Type=" + getClass().getSimpleName() + ", "
@ -214,17 +204,11 @@ public class GroupItem extends GenericItem implements StateChangeListener {
+ members.size() + ", " + "State=" + getState() + ")";
}
/**
* @{inheritDoc
*/
@Override
public void stateChanged(Item item, State oldState, State newState) {
setState(function.calculate(members));
}
/**
* @{inheritDoc
*/
@Override
public void stateUpdated(Item item, State state) {
setState(function.calculate(members));

View File

@ -32,7 +32,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
@ -160,22 +159,30 @@ public class FolderObserver extends AbstractWatchService {
@Override
protected Kind<?>[] getWatchEventKinds(Path directory) {
if (directory != null && MapUtils.isNotEmpty(folderFileExtMap)) {
if (directory != null && isNotEmpty(folderFileExtMap)) {
String folderName = directory.getFileName().toString();
if (this.folderFileExtMap.containsKey(folderName)) {
if (folderFileExtMap.containsKey(folderName)) {
return new Kind<?>[] { ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY };
}
}
return null;
}
private boolean isEmpty(final Map<?, ?> map) {
return map == null || map.isEmpty();
}
private boolean isNotEmpty(final Map<?, ?> map) {
return !isEmpty(map);
}
private void addModelsToRepo() {
if (MapUtils.isNotEmpty(this.folderFileExtMap)) {
Iterator<String> iterator = this.folderFileExtMap.keySet().iterator();
if (isNotEmpty(folderFileExtMap)) {
Iterator<String> iterator = folderFileExtMap.keySet().iterator();
while (iterator.hasNext()) {
String folderName = iterator.next();
final String[] validExtension = this.folderFileExtMap.get(folderName);
final String[] validExtension = folderFileExtMap.get(folderName);
if (validExtension != null && validExtension.length > 0) {
File folder = getFile(folderName);
@ -194,7 +201,7 @@ public class FolderObserver extends AbstractWatchService {
}
private void deleteModelsFromRepo() {
Set<String> folders = this.folderFileExtMap.keySet();
Set<String> folders = folderFileExtMap.keySet();
for (String folder : folders) {
Iterable<String> models = modelRepo.getAllModelNamesOfType(folder);
if (models != null) {
@ -256,7 +263,7 @@ public class FolderObserver extends AbstractWatchService {
}
private File getFileByFileExtMap(Map<String, String[]> folderFileExtMap, String filename) {
if (StringUtils.isNotBlank(filename) && MapUtils.isNotEmpty(folderFileExtMap)) {
if (StringUtils.isNotBlank(filename) && isNotEmpty(folderFileExtMap)) {
String extension = getExtension(filename);
if (StringUtils.isNotBlank(extension)) {
Set<Entry<String, String[]>> entries = folderFileExtMap.entrySet();
@ -270,7 +277,6 @@ public class FolderObserver extends AbstractWatchService {
}
}
}
return null;
}

View File

@ -13,6 +13,7 @@
package org.eclipse.smarthome.core.thing.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@ -22,7 +23,6 @@ import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.collections.iterators.ArrayIterator;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.thing.Bridge;
@ -128,10 +128,7 @@ public class ThingHelper {
* @throws IllegalArgumentException in case there are duplicate channels found
*/
public static void ensureUniqueChannels(final Channel[] channels) {
@SuppressWarnings("unchecked")
final Iterator<Channel> it = new ArrayIterator(channels);
ensureUniqueChannels(it, new HashSet<>(channels.length));
ensureUniqueChannels(Arrays.stream(channels).iterator(), new HashSet<>(channels.length));
}
/**