/**
 * Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved.
 */
package org.eclipse.hawkbit.ui.filter.target;

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() {
        if (target.getTargetInfo().getAddress() == null || target.getTargetInfo().getAddress().getHost() == null) {
            return false;
        }
        return target.getTargetInfo().getAddress().getHost().toUpperCase().contains(searchTextUpper);
    }
}

@@ -138,16 +138,38 @@
 arget;%0A%0A
+import java.net.URI;%0A%0A
 import o
@@ -1673,36 +1673,58 @@
 ase() %7B%0A        
-if (
+final URI targetAddress = 
 target.getTarget
@@ -1746,43 +1746,50 @@
 ss()
- == null %7C%7C target.getTargetInfo().
+;%0A        if (targetAddress == null %7C%7C tar
 getA
@@ -1786,34 +1786,32 @@
 %7C%7C targetAddress
-()
 .getHost() == nu
@@ -1877,37 +1877,15 @@
 rget
-.getTargetInfo().get
 Address
-()
 .get

refactor code