/** * @param name * @param label * may be <code>null</code>, in this case the name will be returned as label. * @param intervals * @param singleValues */ public AxisSubset( String name, String label, List<Interval<?, ?>> intervals, List<SingleValue<?>> singleValues ) { this.name = name; this.label = label; this.intervals = intervals; this.singleValues = singleValues; ValueType tmpType = determineType( intervals ); if ( tmpType == null ) { tmpType = determineTypeFromSingles( singleValues ); } this.type = tmpType == null ? ValueType.Void : tmpType; }
/** * @param other * @param convert * if true the intervals and singlevalues of this instance will be converted to the type of the given * axis subset if their names match and if this type is unknown (void). * @return true if this {@link AxisSubset} matches the given AxisSubset, e.g. if the names are equal and the axis * values have matching parameters in the given one. */ public boolean match( AxisSubset other, boolean convert ) { boolean result = other.getName().equalsIgnoreCase( name ); if ( result ) { if ( this.type == ValueType.Void && convert ) { convertTypes( other.getType() ); } boolean ic = checkIntervals( other.getIntervals() ); boolean sc = checkSingles( other.getSingleValues(), other.getIntervals() ); result = ic && sc; } return result; }
/** * @param writer * @param interval * @throws XMLStreamException */ protected static void exportInterval( XMLStreamWriter writer, Interval<?, ?> interval ) throws XMLStreamException { if ( interval != null ) { writer.writeStartElement( WCS_100_NS, "interval" ); writer.writeNamespace( WCS_100_PRE, WCS_100_NS ); if ( interval.getSemantic() != null ) { writer.writeAttribute( WCS_100_PRE, WCS_100_NS, "semantic", interval.getSemantic() ); } writer.writeAttribute( "atomic", interval.isAtomic() ? "true" : "false" ); Closure closure = interval.getClosure(); writer.writeAttribute( WCS_100_PRE, WCS_100_NS, "closure", closure.name().replaceAll( "_", "-" ) ); exportSingleValueType( writer, interval.getMin(), "min" ); exportSingleValueType( writer, interval.getMax(), "max" ); exportSingleValueType( writer, interval.getSpacing(), "res" ); writer.writeEndElement();// WCS_100_NS, "interval" ); } }
/** * Get the interval defined by the given String. * * @param interval * @return */ private static Interval<?, ?> parseInterval( String interval, ValueType type ) { Interval<?, ?> result = null; String[] split = interval.split( "/" ); if ( split.length == 2 || split.length == 3 ) { // should be min/max/res String min = split[0]; String max = split[1]; String res = null; if ( split.length == 3 ) { res = split[2]; } SingleValue<?> spacing = res == null ? null : SingleValue.createFromString( ValueType.Void.name(), res ); result = Interval.createFromStrings( type.toString(), min, max, Closure.closed, null, false, spacing ); } else { LOG.warn( "Given intervall: " + interval + " has not enough values, maybe a default value is ment?" ); } return result; }
private boolean rangeSetsAreApplicable( RangeSet configuredRangeSet, RangeSet requestedRangeSet ) { List<AxisSubset> reqAxis = requestedRangeSet.getAxisDescriptions(); List<AxisSubset> checked = new ArrayList<AxisSubset>( reqAxis ); for ( AxisSubset ras : reqAxis ) { if ( ras.getName() != null ) { boolean hasMatch = false; Iterator<AxisSubset> it = configuredRangeSet.getAxisDescriptions().iterator(); while ( it.hasNext() && !hasMatch ) { AxisSubset as = it.next(); if ( as.getName().equalsIgnoreCase( ras.getName() ) ) { if ( ras.match( as, true ) ) { // delete the one in checked checked.remove( ras ); } else { return false; } } } } } return checked.isEmpty(); }
ValueType determined = ValueType.fromString( type ); SingleValue<?> result = null; switch ( determined ) { case Byte: case Short: result = new SingleValue<Short>( determined, value.shortValue() ); break; case Integer: result = new SingleValue<Integer>( determined, value.intValue() ); break; case Long: result = new SingleValue<Long>( determined, value.longValue() ); break; case Double: result = new SingleValue<Double>( determined, value.doubleValue() ); break; case Float: result = new SingleValue<Float>( determined, value.floatValue() ); break; default: result = new SingleValue<String>( determined, value.toString() );
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "{" ).append( min.type.toString() ).append( "}" ); sb.append( closure.begin ).append( min.value.toString() ).append( "/" ).append( max.value.toString() ).append( closure.end ); if ( spacing != null ) { sb.append( "/" ).append( spacing.toString() ); } return sb.toString(); }
private SingleValue<?> parseTypedLiteral( OMElement typedLiteralType ) { if ( typedLiteralType == null ) { return null; } String type = typedLiteralType.getAttributeValue( new QName( "type" ) ); String value = typedLiteralType.getText(); return SingleValue.createFromString( type, value ); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "{" ).append( type.toString() ).append( "}" ); sb.append( value.toString() ); return sb.toString(); } }
@Override public String toString() { return name().toLowerCase(); }
/** * @param inter * to check against * @return true if this interval is in the bounds of the given interval. */ @SuppressWarnings("unchecked") public boolean isInBounds( Interval<?, ?> inter ) { // unchecked is suppressed because it is actually checked. boolean result = false; if ( inter != null ) { if ( inter.min.type.isCompatible( min.type ) ) { int comp = min.value.compareTo( (T) inter.min.value ); // min fit true if this min value > given min value result = match( comp, inter.closure, true ); if ( result ) { // min is in the interval if the this min value < max value comp = min.value.compareTo( (T) inter.max.value ); result = match( comp, inter.closure, false ); if ( result ) { // so min values match, lets check the max value against max (assuming min > max ) comp = max.value.compareTo( (T) inter.max.value ); result = match( comp, inter.closure, false ); } } } } return result; }
/** * @param inters * @return */ private ValueType determineType( List<Interval<?, ?>> inters ) { ValueType result = null; if ( inters != null && !inters.isEmpty() ) { Iterator<Interval<?, ?>> it = intervals.iterator(); while ( it.hasNext() && result == null ) { Interval<?, ?> interval = it.next(); if ( interval != null ) { result = interval.getMin().type; } } } return result; }
private SimpleCoverage buildCoverage( Coverage coverage, AbstractRaster raster ) { CoverageOptions options = buildOptions( coverage.getNativeFormat(), coverage.getSupportOptions() ); RangeSet rs = RangeSetBuilder.createBandRangeSetFromRaster( "generated", "Automatically generated dataset, created from the native raster types.", raster ); return new SimpleCoverage( coverage.getName(), coverage.getLabel(), raster, options, rs ); }
/** * @param other * to test against * @return true if the given singlevalue matches this one, e.g. the value and types are equal. */ @Override public boolean equals( Object other ) { if ( other != null && other instanceof SingleValue<?> ) { SingleValue<?> that = (SingleValue<?>) other; if ( this.type.isCompatible( that.type ) ) { return ( value == null ) ? that.value == null : value.equals( that.value ); } } return false; }
private Map<BandType, Integer> mapBandsToConstraints( BandType[] dataBands, Map<BandType, AxisSubset> requestedBands ) { Map<BandType, Integer> bandsWithConstraints = new HashMap<BandType, Integer>( dataBands.length ); for ( int b = 0; b < dataBands.length; ++b ) { AxisSubset axisSubset = requestedBands.get( dataBands[b] ); if ( axisSubset != null ) { if ( axisSubset.hasAxisConstraints() ) { bandsWithConstraints.put( dataBands[b], b ); } } } return bandsWithConstraints; }
/** * @param closureValue * to be mapped, '-' will be replaced with '_' * @return the closure value or closed. */ public static Closure fromString( String closureValue ) { Closure result = Closure.closed; if ( closureValue != null && !"".equals( closureValue ) ) { String mapped = closureValue.replaceAll( "-", "_" ); try { result = Closure.valueOf( mapped.toLowerCase() ); } catch ( NullPointerException e ) { // nothing, just use closed as a default. } } return result; }
private Closure parseClosure( OMElement rootElement ) { String closureValue = rootElement.getAttributeValue( new QName( "closure" ) ); return Closure.fromString( closureValue ); }
private final static SingleValue<?> mapTT( TypedType tt ) { if ( tt == null ) { return null; } return SingleValue.createFromString( tt.getType(), tt.getValue() ); }
/** * @param writer * @param singleValue * @param elementName * @throws XMLStreamException */ protected static void exportSingleValueType( XMLStreamWriter writer, SingleValue<?> singleValue, String elementName ) throws XMLStreamException { if ( singleValue != null ) { String type = ( singleValue.type == ValueType.Void ) ? ValueType.String.toString() : singleValue.type.toString(); writeElement( writer, WCS_100_NS, elementName, singleValue.value.toString(), WCS_100_NS, WCS_100_PRE, "type", type, true ); } }