@ SuppressWarnings ( "unchecked" ) public static < S extends Storable > StorableIndex < S > parseNameDescriptor ( String desc , StorableInfo < S > info ) throws IllegalArgumentException { String name = info . getStorableType ( ) . getName ( ) ; if ( ! desc . startsWith ( name ) ) { throw new IllegalArgumentException ( "Descriptor starts with wrong type name: \"" + desc + "\", \"" + name + ' ' ) ; } Map < String , ? extends StorableProperty < S > > allProperties = info . getAllProperties ( ) ; List < StorableProperty < S > > properties = new ArrayList < StorableProperty < S > > ( ) ; List < Direction > directions = new ArrayList < Direction > ( ) ; boolean unique ; try { int pos = name . length ( ) ; if ( desc . charAt ( pos ++ ) != ' ' ) { throw new IllegalArgumentException ( "Invalid syntax" ) ; } { int pos2 = nextSep ( desc , pos ) ; String attr = desc . substring ( pos , pos2 ) ; if ( attr . equals ( "U" ) ) { unique = true ; } else if ( attr . equals ( "N" ) ) { unique = false ; } else { throw new IllegalArgumentException ( "Unknown attribute" ) ; } pos = pos2 ; } while ( pos < desc . length ( ) ) { char sign = desc . charAt ( pos ++ ) ; if ( sign == ' ' ) { directions . add ( Direction . ASCENDING ) ; } else if ( sign == ' ' ) { directions . add ( Direction . DESCENDING ) ; } else if ( sign == ' ' ) { directions . add ( Direction . UNSPECIFIED ) ; } else { throw new IllegalArgumentException ( "Unknown property direction" ) ; } int pos2 = nextSep ( desc , pos ) ; String propertyName = desc . substring ( pos , pos2 ) ; StorableProperty < S > property = allProperties . get ( propertyName ) ; if ( property == null ) { throw new IllegalArgumentException ( "Unknown property: " + propertyName ) ; } properties . add ( property ) ; pos = pos2 ; } } catch ( IndexOutOfBoundsException e ) { throw new IllegalArgumentException ( "Invalid syntax" ) ; } int size = properties . size ( ) ; if ( size == 0 || size != directions . size ( ) ) { throw new IllegalArgumentException ( "No properties specified" ) ; } StorableIndex < S > index = new StorableIndex < S > ( properties . toArray ( new StorableProperty [ size ] ) , directions . toArray ( new Direction [ size ] ) ) ; return index . unique ( unique ) ; }
Parses an index descriptor and returns an index object .