Collection footprint optimization. Sys to Ui event bus memory leak fix.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
kaizimmerm
2016-09-20 13:35:52 +02:00
parent 3babb8976b
commit bacaed8482
6 changed files with 0 additions and 315 deletions

View File

@@ -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();
}

View File

@@ -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<FilterExpression> 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;
}
}
}

View File

@@ -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> targetFilterQuery;
/**
* Initialize.
*
* @param targetFilterQuery
* custom target filter applied
*/
public CustomTargetFilter(final Optional<TargetFilterQuery> 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;
}
}

View File

@@ -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);
}
}

View File

@@ -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> 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<TargetUpdateStatus> 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;
}
}

View File

@@ -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<String> 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<String> 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<String> targetTags = target.getTags().stream().map(targetTag -> targetTag.getName())
.collect(Collectors.toList());
if (targetTags.isEmpty() || (noTag && targetTags.isEmpty())) {
return false;
}
return !CollectionUtils.containsAny(targetTags, tags);
}
}