
org.jppf.node.policy.Contains Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jppf-common Show documentation
Show all versions of jppf-common Show documentation
JPPF, the open source grid computing solution
/*
* JPPF.
* Copyright (C) 2005-2015 JPPF Team.
* http://www.jppf.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jppf.node.policy;
import org.jppf.utils.PropertiesCollection;
/**
* An execution policy rule that encapsulates a test of type property_value contains string.
* The test applies to string values only.
* @author Laurent Cohen
*/
public class Contains extends ExecutionPolicy
{
/**
* Explicit serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/**
* The name of the property to compare.
*/
private String propertyName = null;
/**
* A string value to compare with.
*/
private String value = null;
/**
* Determines if the comparison should ignore the string case.
*/
private boolean ignoreCase = false;
/**
* Define an equality comparison between the string value of a property and another string value.
* @param propertyName the name of the property to compare.
* @param ignoreCase determines if the comparison should ignore the string case.
* @param a the value to compare with.
*/
public Contains(final String propertyName, final boolean ignoreCase, final String a)
{
this.propertyName = propertyName;
this.value = a;
this.ignoreCase = ignoreCase;
}
/**
* Determines whether this policy accepts the specified node.
* @param info system information for the node on which the tasks will run if accepted.
* @return true if the node is accepted, false otherwise.
*/
@Override
public boolean accepts(final PropertiesCollection info)
{
if (value == null) return false;
String s = getProperty(info, propertyName);
if (s == null) return false;
if (ignoreCase) return s.toLowerCase().contains(value.toLowerCase());
return s.contains(value);
}
/**
* Print this object to a string.
* @return an XML string representation of this object
*/
@Override
public String toString()
{
if (computedToString == null)
{
synchronized(ExecutionPolicy.class)
{
StringBuilder sb = new StringBuilder();
sb.append(indent()).append("\n");
toStringIndent++;
sb.append(indent()).append("").append(propertyName).append(" \n");
sb.append(indent()).append("").append(value).append(" \n");
toStringIndent--;
sb.append(indent()).append(" \n");
computedToString = sb.toString();
}
}
return computedToString;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy