use of groovy.lang.Range in project groovy by apache.
the class StringGroovyMethods method getAt.
/**
* Select a List of values from a Matcher using a Collection
* to identify the indices to be selected.
*
* @param self a Matcher
* @param indices a Collection of indices
* @return a String of the values at the given indices
* @since 1.6.0
*/
public static List getAt(Matcher self, Collection indices) {
List result = new ArrayList();
if (indices instanceof IntRange) {
int size = (int) size(self);
RangeInfo info = subListBorders(size, (Range) indices);
indices = new IntRange(((IntRange) indices).getInclusive(), info.from, info.to - 1);
}
for (Object value : indices) {
if (value instanceof Range) {
result.addAll(getAt(self, (Range) value));
} else {
int idx = DefaultTypeTransformation.intUnbox(value);
result.add(getAt(self, idx));
}
}
return result;
}
use of groovy.lang.Range in project grails-core by grails.
the class ConstrainedProperty method setMin.
/**
* @param min The min to set.
*/
@SuppressWarnings("rawtypes")
public void setMin(Comparable min) {
if (min == null) {
appliedConstraints.remove(MIN_CONSTRAINT);
return;
}
if (!propertyType.equals(min.getClass())) {
throw new MissingPropertyException(MIN_CONSTRAINT, propertyType);
}
Range r = getRange();
if (r != null) {
LOG.warn("Range constraint already set ignoring constraint [" + MIN_CONSTRAINT + "] for value [" + min + "]");
return;
}
Constraint c = appliedConstraints.get(MIN_CONSTRAINT);
if (c == null) {
c = new MinConstraint();
c.setOwningClass(owningClass);
c.setPropertyName(propertyName);
appliedConstraints.put(MIN_CONSTRAINT, c);
}
c.setParameter(min);
}
use of groovy.lang.Range in project grails-core by grails.
the class ConstrainedProperty method setMax.
/**
* @param max The max to set.
*/
@SuppressWarnings("rawtypes")
public void setMax(Comparable max) {
if (max == null) {
appliedConstraints.remove(MAX_CONSTRAINT);
return;
}
if (!propertyType.equals(max.getClass())) {
throw new MissingPropertyException(MAX_CONSTRAINT, propertyType);
}
Range r = getRange();
if (r != null) {
LOG.warn("Range constraint already set ignoring constraint [" + MAX_CONSTRAINT + "] for value [" + max + "]");
return;
}
Constraint c = appliedConstraints.get(MAX_CONSTRAINT);
if (c == null) {
c = new MaxConstraint();
c.setOwningClass(owningClass);
c.setPropertyName(propertyName);
appliedConstraints.put(MAX_CONSTRAINT, c);
}
c.setParameter(max);
}
use of groovy.lang.Range in project groovy-core by groovy.
the class StringGroovyMethods method getAt.
/**
* Select a List of values from a Matcher using a Collection
* to identify the indices to be selected.
*
* @param self a Matcher
* @param indices a Collection of indices
* @return a String of the values at the given indices
* @since 1.6.0
*/
public static List getAt(Matcher self, Collection indices) {
List result = new ArrayList();
for (Object value : indices) {
if (value instanceof Range) {
result.addAll(getAt(self, (Range) value));
} else {
int idx = DefaultTypeTransformation.intUnbox(value);
result.add(getAt(self, idx));
}
}
return result;
}
Aggregations