From bacaed8482c83b73298bb3afe31e5eff78efdf47 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Tue, 20 Sep 2016 13:35:52 +0200 Subject: [PATCH] Collection footprint optimization. Sys to Ui event bus memory leak fix. Signed-off-by: kaizimmerm --- .../hawkbit/ui/filter/FilterExpression.java | 27 ------- .../eclipse/hawkbit/ui/filter/Filters.java | 77 ------------------- .../ui/filter/target/CustomTargetFilter.java | 48 ------------ .../filter/target/TargetSearchTextFilter.java | 67 ---------------- .../ui/filter/target/TargetStatusFilter.java | 42 ---------- .../ui/filter/target/TargetTagFilter.java | 54 ------------- 6 files changed, 315 deletions(-) delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/FilterExpression.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/Filters.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/CustomTargetFilter.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetSearchTextFilter.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetStatusFilter.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetTagFilter.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/FilterExpression.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/FilterExpression.java deleted file mode 100644 index 853c6f095..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/FilterExpression.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.filter; - -/** - * A filter expression interface definition to implement the UI filter - * mechanism. The filter expression can evaluate if e.g. Targets should - * currently be added to the target list or if the current enabled filtered will - * filter the target and not show the newly created target. - * - */ -@FunctionalInterface -public interface FilterExpression { - - /** - * @return {@code true} if the expression evaluate that it should be - * filtered and not shown on the UI, otherwise {@code false} - */ - boolean doFilter(); - -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/Filters.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/Filters.java deleted file mode 100644 index 4b79a5654..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/Filters.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.filter; - -import java.util.Arrays; -import java.util.List; - -/** - * {@link Filters} which provides the functionality to combine - * {@link FilterExpression}s. - * - * - * - * @see FilterExpression - * - */ -public final class Filters { - - /** - * private. - */ - private Filters() { - - } - - /** - * Combines the given filter to an or-expression and evaluate them. - * - * @param expressions - * the expressions to combine with an or-filter - * @return an or-combined filter expression - */ - public static FilterExpression or(final List expressions) { - return or(expressions.toArray(new FilterExpression[expressions.size()])); - } - - /** - * Combines the given filter to an or-expression and evaluate them. - * - * @param expressions - * the expressions to combine with an or-filter - * @return an or-combined filter expression - */ - public static FilterExpression or(final FilterExpression... expressions) { - return new OrFilterExpression(expressions); - } - - private static final class OrFilterExpression implements FilterExpression { - - private final FilterExpression[] expresssions; - - private OrFilterExpression(final FilterExpression[] expresssions) { - this.expresssions = Arrays.copyOf(expresssions, expresssions.length); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.filter.FilterExpression#evaluate() - */ - @Override - public boolean doFilter() { - for (final FilterExpression filterExpression : expresssions) { - if (filterExpression.doFilter()) { - return true; - } - } - return false; - } - } -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/CustomTargetFilter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/CustomTargetFilter.java deleted file mode 100644 index b0aadc01d..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/CustomTargetFilter.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.filter.target; - -import java.util.Optional; - -import org.eclipse.hawkbit.repository.model.TargetFilterQuery; -import org.eclipse.hawkbit.ui.filter.FilterExpression; - -/** - * Checks if custom target filter is applied. - * - */ -public class CustomTargetFilter implements FilterExpression { - - private final Optional targetFilterQuery; - - /** - * Initialize. - * - * @param targetFilterQuery - * custom target filter applied - */ - public CustomTargetFilter(final Optional targetFilterQuery) { - this.targetFilterQuery = targetFilterQuery; - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.ui.filter.FilterExpression#doFilter() - */ - @Override - public boolean doFilter() { - if (!targetFilterQuery.isPresent()) { - return false; - } - return true; - } - -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetSearchTextFilter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetSearchTextFilter.java deleted file mode 100644 index 64e9067e9..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetSearchTextFilter.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved. - */ -package org.eclipse.hawkbit.ui.filter.target; - -import java.net.URI; - -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.ui.filter.FilterExpression; - -/** - * - * - * - */ -public class TargetSearchTextFilter implements FilterExpression { - - private final Target target; - private final String searchTextUpper; - - /** - * @param target - * the target to check against the search text - * @param searchText - * the search text check against the given target - */ - public TargetSearchTextFilter(final Target target, final String searchText) { - this.target = target; - this.searchTextUpper = searchText.toUpperCase(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.filter.FilterExpression#evaluate() - */ - @Override - public boolean doFilter() { - return !(descriptionIgnoreCase() || nameIgnoreCase() || controllerIdIgnoreCase() || ipAddressIgnoreCase()); - } - - private boolean descriptionIgnoreCase() { - if (target.getDescription() == null) { - return false; - } - return target.getDescription().toUpperCase().contains(searchTextUpper); - } - - private boolean nameIgnoreCase() { - if (target.getName() == null) { - return false; - } - return target.getName().toUpperCase().contains(searchTextUpper); - } - - private boolean controllerIdIgnoreCase() { - return target.getControllerId().toUpperCase().contains(searchTextUpper); - } - - private boolean ipAddressIgnoreCase() { - final URI targetAddress = target.getTargetInfo().getAddress(); - if (targetAddress == null || targetAddress.getHost() == null) { - return false; - } - return targetAddress.getHost().toUpperCase().contains(searchTextUpper); - } -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetStatusFilter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetStatusFilter.java deleted file mode 100644 index eee7156e3..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetStatusFilter.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved. - */ -package org.eclipse.hawkbit.ui.filter.target; - -import java.util.List; - -import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.ui.filter.FilterExpression; - -/** - * - * - * - */ -public class TargetStatusFilter implements FilterExpression { - - private final List targetUpdateStatus; - - /** - * @param target - * the target to check the update status against - * @param updateStatus - * the target update status to check against the given target - */ - public TargetStatusFilter(final List updateStatus) { - this.targetUpdateStatus = updateStatus; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.filter.FilterExpression#evaluate() - */ - @Override - public boolean doFilter() { - if (targetUpdateStatus.isEmpty()) { - return false; - } - return true; - } -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetTagFilter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetTagFilter.java deleted file mode 100644 index 5516c279e..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filter/target/TargetTagFilter.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved. - */ -package org.eclipse.hawkbit.ui.filter.target; - -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.ui.filter.FilterExpression; -import org.springframework.util.CollectionUtils; - -/** - * - * - * - */ -public class TargetTagFilter implements FilterExpression { - - private final Target target; - private final Collection tags; - private final boolean noTag; - - /** - * @param target - * the target to check the filter against - * @param tags - * the tags to check the target against it - * @param noTag - * {@code true} indicates that targets which have no tags should - * not be filtered, otherwise {@code false} - */ - public TargetTagFilter(final Target target, final Collection tags, final boolean noTag) { - this.target = target; - this.tags = tags; - this.noTag = noTag; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.ui.filter.FilterExpression#evaluate() - */ - @Override - public boolean doFilter() { - final List targetTags = target.getTags().stream().map(targetTag -> targetTag.getName()) - .collect(Collectors.toList()); - if (targetTags.isEmpty() || (noTag && targetTags.isEmpty())) { - return false; - } - return !CollectionUtils.containsAny(targetTags, tags); - } -}