Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.

Commit

Permalink
drop most usage of Guava's com.google.common package (eclipse-archive…
Browse files Browse the repository at this point in the history
…d#6449)

* remove usage of "com.google.common" from Bose SoundTouch"
* remove usage of "com.google.common" from DMX binding
* remove usage of "com.google.common" from Homematic binding
* remove usage of "com.google.common" from Magic binding
* remove usage of "com.google.common" from base test bundle
* remove usage of "com.google.common" from core bundle
* remove usage of "com.google.common" from config.core bundle
* remove usage of "com.google.common" from core thing test bundle
* remove some usage of "com.google.common" from config.discovery bundle
* remove usage of "com.google.common" from config.discovery test bundle
* remove most usage of "com.google.common" from core.thing bundle
* fix config.xml test
* fix core.binding.xml tests
* remove some obsolete imports
* remove "HashMultimap" usage of config.discovery bundle
* remove multimap stuff from core.thing

Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
  • Loading branch information
maggu2810 authored and htreu committed Nov 5, 2018
1 parent 804ea07 commit a0e1788
Show file tree
Hide file tree
Showing 56 changed files with 120 additions and 132 deletions.
Expand Up @@ -7,7 +7,6 @@ Bundle-SymbolicName: org.eclipse.smarthome.automation.event.test;singlet
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 0.10.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.events,
Expand Down
Expand Up @@ -7,7 +7,6 @@ Bundle-SymbolicName: org.eclipse.smarthome.automation.integration.test;s
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 0.10.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.events,
Expand Down
Expand Up @@ -10,7 +10,6 @@ Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 0.10.0.qualifier
Export-Package: org.eclipse.smarthome.automation.module.media.handler
Import-Package:
com.google.common.collect,
org.apache.commons.lang,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
Expand Down
Expand Up @@ -7,7 +7,6 @@ Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 0.10.0.qualifier
Fragment-Host: org.eclipse.smarthome.automation.module.script
Import-Package:
com.google.common.collect,
org.apache.commons.io,
org.apache.commons.lang,
org.eclipse.jdt.annotation;resolution:=optional,
Expand Down
Expand Up @@ -7,7 +7,6 @@ Bundle-SymbolicName: org.eclipse.smarthome.automation.module.timer.test;
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 0.10.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.events,
Expand Down
Expand Up @@ -13,7 +13,6 @@ Export-Package:
org.eclipse.smarthome.automation.module.timer.factory,
org.eclipse.smarthome.automation.module.timer.handler
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.handler,
Expand Down
Expand Up @@ -14,7 +14,6 @@ Export-Package:
org.eclipse.smarthome.config.core.status.events,
org.eclipse.smarthome.config.core.validation
Import-Package:
com.google.common.collect,
com.google.gson,
com.google.gson.annotations,
org.apache.commons.lang.reflect,
Expand Down
Expand Up @@ -13,12 +13,15 @@
package org.eclipse.smarthome.config.core.internal.validation;

import java.math.BigDecimal;
import java.util.AbstractMap.SimpleEntry;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.config.core.ConfigDescriptionParameter.Type;

import com.google.common.collect.ImmutableMap;

/**
* The {@link TypeIntrospections} provides a corresponding {@link TypeIntrospection} for each config description
* parameter type.
Expand All @@ -27,9 +30,12 @@
*/
final class TypeIntrospections {

private static final Map<Type, TypeIntrospection> INTROSPECTIONS = new ImmutableMap.Builder<Type, TypeIntrospection>()
.put(Type.BOOLEAN, new BooleanIntrospection()).put(Type.TEXT, new StringIntrospection())
.put(Type.INTEGER, new IntegerIntrospection()).put(Type.DECIMAL, new FloatIntrospection()).build();
private static final Map<Type, TypeIntrospection> INTROSPECTIONS = Collections.unmodifiableMap(Stream
.of(new SimpleEntry<>(Type.BOOLEAN, new BooleanIntrospection()),
new SimpleEntry<>(Type.TEXT, new StringIntrospection()),
new SimpleEntry<>(Type.INTEGER, new IntegerIntrospection()),
new SimpleEntry<>(Type.DECIMAL, new FloatIntrospection()))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue)));

private TypeIntrospections() {
super();
Expand Down
Expand Up @@ -16,10 +16,14 @@
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;

import java.util.AbstractMap.SimpleEntry;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultFlag;
Expand All @@ -29,8 +33,6 @@
import org.junit.Before;
import org.junit.Test;

import com.google.common.collect.ImmutableMap;

/**
* Tests for {@link InboxPredicates}.
*
Expand Down Expand Up @@ -58,10 +60,10 @@ public class InboxPredicatesTest {
private final static ThingTypeUID THING_TYPE_UID12 = new ThingTypeUID(BINDING_ID1, THING_TYPE_ID2);
private final static ThingTypeUID THING_TYPE_UID21 = new ThingTypeUID(BINDING_ID2, THING_TYPE_ID1);

private final static Map<String, Object> PROPS1 = new ImmutableMap.Builder<String, Object>().put(PROP1, PROP_VAL1)
.put(PROP2, PROP_VAL2).build();
private final static Map<String, Object> PROPS2 = new ImmutableMap.Builder<String, Object>().put(PROP2, PROP_VAL2)
.build();
private final static Map<String, Object> PROPS1 = Collections
.unmodifiableMap(Stream.of(new SimpleEntry<>(PROP1, PROP_VAL1), new SimpleEntry<>(PROP2, PROP_VAL2))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
private final static Map<String, Object> PROPS2 = Collections.singletonMap(PROP2, PROP_VAL2);

private final static List<DiscoveryResultImpl> results = Arrays.asList(
new DiscoveryResultImpl(THING_TYPE_UID11, THING_UID11, null, PROPS1, PROP1, "label",
Expand Down
Expand Up @@ -11,8 +11,6 @@ Export-Package:
org.eclipse.smarthome.config.discovery.inbox,
org.eclipse.smarthome.config.discovery.inbox.events
Import-Package:
com.google.common.base,
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.config.discovery,
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CancellationException;
Expand Down Expand Up @@ -93,7 +94,7 @@ public AbstractDiscoveryService(@Nullable Set<ThingTypeUID> supportedThingTypes,
if (supportedThingTypes == null) {
this.supportedThingTypes = Collections.emptySet();
} else {
this.supportedThingTypes = supportedThingTypes;
this.supportedThingTypes = Collections.unmodifiableSet(new HashSet<>(supportedThingTypes));
}

if (timeout < 0) {
Expand Down
Expand Up @@ -12,6 +12,9 @@
*/
package org.eclipse.smarthome.config.discovery.inbox.events;

import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.dto.DiscoveryResultDTO;
import org.eclipse.smarthome.config.discovery.dto.DiscoveryResultDTOMapper;
Expand All @@ -20,8 +23,6 @@
import org.eclipse.smarthome.core.events.EventFactory;
import org.osgi.service.component.annotations.Component;

import com.google.common.collect.Sets;

/**
* An {@link InboxEventFactory} is responsible for creating inbox event instances.
*
Expand All @@ -40,7 +41,8 @@ public class InboxEventFactory extends AbstractEventFactory {
* Constructs a new InboxEventFactory.
*/
public InboxEventFactory() {
super(Sets.newHashSet(InboxAddedEvent.TYPE, InboxUpdatedEvent.TYPE, InboxRemovedEvent.TYPE));
super(Stream.of(InboxAddedEvent.TYPE, InboxUpdatedEvent.TYPE, InboxRemovedEvent.TYPE)
.collect(Collectors.toSet()));
}

@Override
Expand Down
Expand Up @@ -16,10 +16,10 @@
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CopyOnWriteArraySet;
Expand All @@ -46,8 +46,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.HashMultimap;

/**
* The {@link DiscoveryServiceRegistryImpl} is a concrete implementation of the {@link DiscoveryServiceRegistry}.
* <p>
Expand All @@ -69,7 +67,7 @@
@NonNullByDefault
public final class DiscoveryServiceRegistryImpl implements DiscoveryServiceRegistry, DiscoveryListener {

private final HashMultimap<DiscoveryService, DiscoveryResult> cachedResults = HashMultimap.create();
private final HashMap<DiscoveryService, Set<DiscoveryResult>> cachedResults = new HashMap<>();

private final class AggregatingScanListener implements ScanListener {

Expand Down Expand Up @@ -186,10 +184,9 @@ public boolean abortScan(String bindingId) throws IllegalStateException {
@Override
public void addDiscoveryListener(DiscoveryListener listener) throws IllegalStateException {
synchronized (cachedResults) {
Set<Entry<DiscoveryService, DiscoveryResult>> entries = cachedResults.entries();
for (Entry<DiscoveryService, DiscoveryResult> entry : entries) {
listener.thingDiscovered(entry.getKey(), entry.getValue());
}
cachedResults.forEach((service, results) -> {
results.forEach(result -> listener.thingDiscovered(service, result));
});
}
this.listeners.add(listener);
}
Expand Down Expand Up @@ -257,8 +254,7 @@ public synchronized void removeDiscoveryListener(DiscoveryListener listener) thr
@Override
public synchronized void thingDiscovered(final DiscoveryService source, final DiscoveryResult result) {
synchronized (cachedResults) {
cachedResults.remove(source, result);
cachedResults.put(source, result);
cachedResults.computeIfAbsent(source, unused -> new HashSet<>()).add(result);
}
for (final DiscoveryListener listener : this.listeners) {
try {
Expand Down Expand Up @@ -449,7 +445,7 @@ private void removeDiscoveryServiceActivated(DiscoveryService discoveryService)
this.discoveryServices.remove(discoveryService);
discoveryService.removeDiscoveryListener(this);
synchronized (cachedResults) {
this.cachedResults.removeAll(discoveryService);
this.cachedResults.remove(discoveryService);
}
}

Expand Down
Expand Up @@ -8,6 +8,5 @@ Bundle-SymbolicName: ConfigDescriptionsFragmentTest.fragment;singleton:=
Bundle-Version: 0.0.1.qualifier
Fragment-Host: ConfigDescriptionsFragmentTest.host
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -6,6 +6,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: ConfigDescriptionsFragmentTest.host;singleton:=true
Bundle-Version: 0.0.1.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -7,6 +7,5 @@ Bundle-SymbolicName: LoadingConfigDescriptionsTest.bundle;singleton:=tru
e
Bundle-Version: 0.0.1.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -7,6 +7,5 @@ Bundle-SymbolicName: yahooweather.bundle;singleton:=true
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 0.7.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -6,6 +6,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: BundleInfoTest.bundle;singleton:=true
Bundle-Version: 0.0.1.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -6,6 +6,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: BundleInfoTestNoAuthor.bundle;singleton:=true
Bundle-Version: 0.0.1.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -7,6 +7,5 @@ Bundle-SymbolicName: yahooweather.bundle;singleton:=true
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 0.7.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -16,6 +16,7 @@
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertThat;

import java.util.Arrays;
import java.util.Set;

import org.eclipse.smarthome.core.events.Event;
Expand All @@ -26,8 +27,6 @@
import org.junit.Before;
import org.junit.Test;

import com.google.common.collect.Lists;

/**
*
* @author Dimitar Ivanov - Initial contribution
Expand Down Expand Up @@ -97,7 +96,7 @@ public void testSerializationAndDeserializationFirmwareStatusInfo() throws Excep
public void testSerializationAndDeserializationFirmwareUpdateProgressInfo() throws Exception {
FirmwareUpdateProgressInfo firmwareUpdateProgressInfo = FirmwareUpdateProgressInfo
.createFirmwareUpdateProgressInfo(thingUID, "1.2.3", ProgressStep.UPDATING,
Lists.newArrayList(ProgressStep.WAITING, ProgressStep.UPDATING), false, 10);
Arrays.asList(ProgressStep.WAITING, ProgressStep.UPDATING), false, 10);
FirmwareUpdateProgressInfoEvent progressInfoEvent = FirmwareEventFactory
.createFirmwareUpdateProgressInfoEvent(firmwareUpdateProgressInfo);

Expand Down
Expand Up @@ -6,6 +6,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: ChannelTypesI18nTest.bundle;singleton:=true
Bundle-Version: 1.0.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -6,6 +6,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: ChannelTypesTest.bundle;singleton:=true
Bundle-Version: 1.0.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -6,6 +6,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: ConfigDescriptionsTest.bundle;singleton:=true
Bundle-Version: 0.0.1.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -7,6 +7,5 @@ Bundle-SymbolicName: SystemChannels.bundle;singleton:=true
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 1.0.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -8,6 +8,5 @@ Bundle-SymbolicName: SystemChannelsInChannelGroups.bundle;singleton:=tru
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 1.0.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -7,6 +7,5 @@ Bundle-SymbolicName: SystemChannelsNoThingTypes.bundle;singleton:=true
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 1.0.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -7,6 +7,5 @@ Bundle-SymbolicName: SystemChannelsUser.bundle;singleton:=true
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 1.0.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -6,6 +6,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: ThingTypesTest.bundle;singleton:=true
Bundle-Version: 1.0.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -7,6 +7,5 @@ Bundle-SymbolicName: yahooweather.bundle;singleton:=true
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 1.0.0.qualifier
Import-Package:
com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.osgi.framework
Expand Up @@ -24,7 +24,6 @@ Export-Package:
org.eclipse.smarthome.core.thing.type,
org.eclipse.smarthome.core.thing.util
Import-Package:
com.google.common.collect,
javax.measure,
javax.measure.quantity,
org.apache.commons.collections.iterators,
Expand Down

0 comments on commit a0e1788

Please sign in to comment.