idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
5,200
private Polygon createPolygon ( double [ ] [ ] [ ] coordinates , CrsId crsId ) { LinearRing [ ] rings = new LinearRing [ coordinates . length ] ; for ( int i = 0 ; i < coordinates . length ; i ++ ) { rings [ i ] = new LinearRing ( createPointSequence ( coordinates [ i ] , crsId ) ) ; } return new Polygon ( rings ) ; }
Creates a polygon starting from its geojson coordinate array
5,201
private PointSequence createPointSequence ( double [ ] [ ] coordinates , CrsId crsId ) { if ( coordinates == null ) { return null ; } else if ( coordinates . length == 0 ) { return PointCollectionFactory . createEmpty ( ) ; } DimensionalFlag df = coordinates [ 0 ] . length == 4 ? DimensionalFlag . d3DM : coordinates [ 0 ] . length == 3 ? DimensionalFlag . d3D : DimensionalFlag . d2D ; PointSequenceBuilder psb = PointSequenceBuilders . variableSized ( df , crsId ) ; for ( double [ ] point : coordinates ) { psb . add ( point ) ; } return psb . toPointSequence ( ) ; }
Helpermethod that creates a geolatte pointsequence starting from an array containing coordinate arrays
5,202
private Point createPoint ( double [ ] input , CrsId crsIdValue ) { if ( input == null ) { return null ; } if ( input . length == 2 ) { return Points . create2D ( input [ 0 ] , input [ 1 ] , crsIdValue ) ; } else if ( input . length == 3 ) { return Points . create3D ( input [ 0 ] , input [ 1 ] , input [ 2 ] , crsIdValue ) ; } else { double z = input [ 2 ] ; double m = input [ 3 ] ; if ( Double . isNaN ( z ) ) { return Points . create2DM ( input [ 0 ] , input [ 1 ] , m , crsIdValue ) ; } else { return Points . create3DM ( input [ 0 ] , input [ 1 ] , z , m , crsIdValue ) ; } } }
Helpermethod that creates a point starting from its geojsonto coordinate array
5,203
private double [ ] [ ] getPoints ( Geometry input ) { double [ ] [ ] result = new double [ input . getNumPoints ( ) ] [ ] ; for ( int i = 0 ; i < input . getPoints ( ) . size ( ) ; i ++ ) { Point p = input . getPointN ( i ) ; if ( p . isMeasured ( ) && p . is3D ( ) ) { result [ i ] = new double [ ] { p . getX ( ) , p . getY ( ) , p . getZ ( ) , p . getM ( ) } ; } else if ( p . isMeasured ( ) ) { result [ i ] = new double [ ] { p . getX ( ) , p . getY ( ) , 0 , p . getM ( ) } ; } else if ( p . is3D ( ) ) { result [ i ] = new double [ ] { p . getX ( ) , p . getY ( ) , p . getZ ( ) } ; } else { result [ i ] = new double [ ] { p . getX ( ) , p . getY ( ) } ; } } return result ; }
Serializes all points of the input into a list of their coordinates
5,204
public static void invoke ( ) { for ( final Runnable instance : instances ) { try { instance . run ( ) ; } catch ( final Throwable t ) { LOGGER . error ( SHUTDOWN_HOOK_MARKER , "Caught exception executing shutdown hook {}" , instance , t ) ; } } }
Invoke all ShutdownCallbackRegistry instances .
5,205
public void run ( ) { if ( state . compareAndSet ( State . STARTED , State . STOPPING ) ) { for ( final Runnable hook : hooks ) { try { hook . run ( ) ; } catch ( final Throwable t ) { LOGGER . error ( SHUTDOWN_HOOK_MARKER , "Caught exception executing shutdown hook {}" , hook , t ) ; } } state . set ( State . STOPPED ) ; } }
Executes the registered shutdown callbacks .
5,206
public void checkExpectedValidationViolations ( Set < ConstraintViolation < T > > violations , List < String > expectedValidationViolations ) { if ( violations != null && expectedValidationViolations != null ) { List < String > givenViolations = new ArrayList < String > ( ) ; for ( ConstraintViolation < T > violation : violations ) { givenViolations . add ( violation . getMessageTemplate ( ) ) ; } checkViolations ( givenViolations , expectedValidationViolations ) ; } }
This method checks the violations against expected violations .
5,207
public static void checkExpectedValidationViolations ( ConstraintViolationException exception , List < String > expectedValidationViolations ) { if ( exception != null && expectedValidationViolations != null ) { List < String > givenViolations = new ArrayList < String > ( ) ; for ( ConstraintViolation < ? > violation : exception . getConstraintViolations ( ) ) { givenViolations . add ( violation . getMessageTemplate ( ) ) ; } checkViolations ( givenViolations , expectedValidationViolations ) ; } }
This method checks if the validation violations matches the violations given in a ViolationException .
5,208
private static void checkViolations ( List < String > givenViolations , List < String > expectedValidationViolations ) { Assert . assertEquals ( String . format ( "number of expected validation violations (%s) does not match the number of given violations (%s)" , StringUtils . join ( expectedValidationViolations , LIST_DELIMITER ) , StringUtils . join ( givenViolations , LIST_DELIMITER ) ) , expectedValidationViolations . size ( ) , givenViolations . size ( ) ) ; boolean listsAreCongruent = true ; List < String > givenButNotExpected = new ArrayList < String > ( ) ; for ( String givenViolation : givenViolations ) { if ( ! expectedValidationViolations . contains ( givenViolation ) ) { listsAreCongruent = false ; givenButNotExpected . add ( givenViolation ) ; } } Assert . assertTrue ( String . format ( "the violations (%s) where given but not expected: all given violations (%s), all expected violations (%s)" , StringUtils . join ( givenButNotExpected , LIST_DELIMITER ) , StringUtils . join ( givenViolations , LIST_DELIMITER ) , StringUtils . join ( expectedValidationViolations , LIST_DELIMITER ) ) , listsAreCongruent ) ; }
Helper method doing the checking work .
5,209
public synchronized String toJson ( Object input ) throws JsonException { try { return recurse ( input ) ; } catch ( IOException e ) { throw new JsonException ( e ) ; } }
Converts a given object into a JSON String
5,210
public synchronized < T > T fromJson ( String jsonString , Class < T > clazz ) throws JsonException { if ( jsonString == null ) { return null ; } Reader reader = new StringReader ( jsonString ) ; try { return mapper . readValue ( reader , clazz ) ; } catch ( JsonParseException e ) { throw new JsonException ( e . getMessage ( ) , e ) ; } catch ( JsonMappingException e ) { throw new JsonException ( e . getMessage ( ) , e ) ; } catch ( IOException e ) { throw new JsonException ( e . getMessage ( ) , e ) ; } }
Converts a given string into an object of the given class .
5,211
public < T > List < T > collectionFromJson ( String json , Class < T > clazz ) throws JsonException { if ( json == null ) { return null ; } try { List < T > result = new ArrayList < T > ( ) ; List tempParseResult = ( List ) mapper . readValue ( json , new TypeReference < List < T > > ( ) { } ) ; for ( Object temp : tempParseResult ) { result . add ( fromJson ( toJson ( temp ) , clazz ) ) ; } return result ; } catch ( JsonParseException e ) { throw new JsonException ( e . getMessage ( ) , e ) ; } catch ( JsonMappingException e ) { throw new JsonException ( e . getMessage ( ) , e ) ; } catch ( IOException e ) { throw new JsonException ( e . getMessage ( ) , e ) ; } }
Converts a JsonString into a corresponding javaobject of the requested type .
5,212
protected String recurse ( Object input ) throws IOException { increaseDepth ( ) ; if ( depth > MAXIMUMDEPTH ) { decreaseDepth ( ) ; return "{ \"error\": \"maximum serialization-depth reached.\" }" ; } StringWriter writer = new StringWriter ( ) ; mapper . writeValue ( writer , input ) ; writer . close ( ) ; decreaseDepth ( ) ; return writer . getBuffer ( ) . toString ( ) ; }
This method should only be used by serializers who need recursive calls . It prevents overflow due to circular references and ensures that the maximum depth of different sub - parts is limited
5,213
public < T > void addClassSerializer ( Class < ? extends T > classToMap , JsonSerializer < T > classSerializer ) { setNewObjectMapper ( ) ; SimpleModule mod = new SimpleModule ( "GeolatteCommonModule-" + classSerializer . getClass ( ) . getSimpleName ( ) ) ; mod . addSerializer ( classToMap , classSerializer ) ; mapper . registerModule ( mod ) ; }
Adds a serializer to this mapper . Allows a user to alter the serialization behavior for a certain type .
5,214
public < T > void addClassDeserializer ( Class < T > classToMap , JsonDeserializer < ? extends T > classDeserializer ) { setNewObjectMapper ( ) ; SimpleModule mod = new SimpleModule ( "GeolatteCommonModule-" + classDeserializer . getClass ( ) . getSimpleName ( ) ) ; mod . addDeserializer ( classToMap , classDeserializer ) ; mapper . registerModule ( mod ) ; }
Adds a deserializer to this mapper . Allows a user to alter the deserialization behavior for a certain type .
5,215
private void setNewObjectMapper ( ) { mapper = new ObjectMapper ( ) ; if ( ! serializeNullValues ) { mapper . setSerializationInclusion ( JsonInclude . Include . NON_NULL ) ; if ( ignoreUnknownProperties ) { mapper . configure ( DeserializationFeature . FAIL_ON_UNKNOWN_PROPERTIES , false ) ; } } }
Sets a new object mapper taking into account the original configuration parameters .
5,216
public static CrsTo createCrsTo ( String crsName ) { String nameToUse = crsName == null ? "EPSG:4326" : crsName ; CrsTo result = new CrsTo ( ) ; NamedCrsPropertyTo property = new NamedCrsPropertyTo ( ) ; property . setName ( nameToUse ) ; result . setProperties ( property ) ; return result ; }
Convenience method to create a named crs to .
5,217
public static double [ ] createBoundingBox ( double [ ] coordinates ) { int maxActualCoords = Math . min ( coordinates . length , 3 ) ; double [ ] result = new double [ maxActualCoords * 2 ] ; for ( int i = 0 ; i < maxActualCoords ; i ++ ) { result [ i ] = coordinates [ i ] ; result [ maxActualCoords + i ] = coordinates [ i ] ; } return result ; }
Creates a boundingbox for a point . In this case both the lower and higher edges of the bbox are the point itself
5,218
private static void mergeInto ( double [ ] first , double [ ] second ) { for ( int j = 0 ; j < first . length / 2 ; j ++ ) { first [ j ] = Math . min ( first [ j ] , second [ j ] ) ; first [ j + first . length / 2 ] = Math . max ( first [ j + first . length / 2 ] , second [ j + first . length / 2 ] ) ; } }
Merges the second boundingbox into the first . Basically this extends the first boundingbox to also encapsulate the second
5,219
public final double distance ( final double [ ] value1 , final double [ ] value2 ) { double agg = 0 ; for ( int i = 0 ; i < value1 . length ; i ++ ) { agg += ( value1 [ i ] - value2 [ i ] ) * ( value1 [ i ] - value2 [ i ] ) ; } return Math . sqrt ( agg ) ; }
Compute traditional Euclidean distance .
5,220
public Boolean transform ( T input ) throws TransformationException { try { return cqlFilter . evaluate ( input ) ; } catch ( ParseException e ) { throw new TransformationException ( e , input ) ; } }
Checks whether the given input object passes the cql filter .
5,221
public Envelope createEnvelope ( double [ ] coordinates ) throws TypeConversionException { if ( coordinates . length < 4 ) { throw new TypeConversionException ( "Not enough coordinates in inputstring" ) ; } else { double minX = Double . MAX_VALUE ; double minY = Double . MAX_VALUE ; double maxX = Double . MIN_VALUE ; double maxY = Double . MIN_VALUE ; for ( int i = 0 ; i < coordinates . length ; i ++ ) { if ( i % 2 == 0 ) { if ( coordinates [ i ] < minX ) minX = coordinates [ i ] ; if ( coordinates [ i ] > maxX ) maxX = coordinates [ i ] ; } else { if ( coordinates [ i ] < minY ) minY = coordinates [ i ] ; if ( coordinates [ i ] > maxY ) maxY = coordinates [ i ] ; } } return new Envelope ( minX , minY , maxX , maxY ) ; } }
Creates an envelope based on a list of coordinates . If less than two coordinates are in the list a typeconversion exception is thrown . If more than two coordinates are in the list the minimum X - and Y - coordinates are searched .
5,222
public double [ ] getCoordinates ( String inputString ) throws TypeConversionException { String [ ] cstr = inputString . split ( "," ) ; int coordLength ; if ( cstr . length % 2 == 0 ) { coordLength = cstr . length ; } else { coordLength = cstr . length - 1 ; } double [ ] coordinates = new double [ coordLength ] ; try { for ( int index = 0 ; index < coordLength ; index ++ ) { coordinates [ index ] = Double . parseDouble ( cstr [ index ] ) ; } return coordinates ; } catch ( NumberFormatException e ) { throw new TypeConversionException ( "String contains non-numeric data. Impossible to create envelope" , e ) ; } }
Retrieves a list of coordinates from the given string . If the number of numbers in the string is odd the last number is ignored .
5,223
public void start ( ) { collectedOutput = new ArrayList < T > ( ) ; for ( T element : input ) { collectedOutput . add ( element ) ; } }
Starts iterating over its input .
5,224
protected String getPropertyPath ( Collection < String > parts ) { StringBuilder propertyPath = new StringBuilder ( ) ; Iterator < String > partsIterator = parts . iterator ( ) ; propertyPath . append ( partsIterator . next ( ) ) ; while ( partsIterator . hasNext ( ) ) propertyPath . append ( "." ) . append ( partsIterator . next ( ) ) ; return propertyPath . toString ( ) ; }
Creates a dot - separated string of the given parts .
5,225
protected String getStringParam ( String paramName , String errorMessage ) throws IOException { return getStringParam ( paramName , errorMessage , ( Map < String , Object > ) inputParams . get ( ) ) ; }
Convenience method for subclasses . Uses the default map for parameterinput
5,226
protected Double getDoubleParam ( String paramName , String errorMessage ) throws IOException { return getDoubleParam ( paramName , errorMessage , ( Map < String , Object > ) inputParams . get ( ) ) ; }
Convenience method for subclasses . Retrieves a double with the given parametername even if that parametercontent is actually a string containing a number or a long or an int or ... Anything that can be converted to a double is returned . uses the default parameterhashmap from this deserializer .
5,227
protected Double getDoubleParam ( String paramName , String errorMessage , Map < String , Object > mapToUse ) throws IOException { Object o = mapToUse . get ( paramName ) ; if ( o != null ) { try { return Double . parseDouble ( o . toString ( ) ) ; } catch ( NumberFormatException ignored ) { } } return getTypedParam ( paramName , errorMessage , Double . class , mapToUse ) ; }
Convenience method for subclasses . Retrieves a double with the given parametername even if that parametercontent is actually a string containing a number or a long or an int or ... Anything that can be converted to a double is returned .
5,228
protected < A > A getTypedParam ( String paramName , String errorMessage , Class < A > clazz ) throws IOException { return getTypedParam ( paramName , errorMessage , clazz , ( Map < String , Object > ) inputParams . get ( ) ) ; }
Convenience method for subclasses . Uses the default parametermap for this deserializer .
5,229
private GeometryCollection asGeomCollection ( CrsId crsId ) throws IOException { try { String subJson = getSubJson ( "geometries" , "A geometrycollection requires a geometries parameter" ) . replaceAll ( " " , "" ) ; String noSpaces = subJson . replace ( " " , "" ) ; if ( noSpaces . contains ( "\"crs\":{" ) ) { throw new IOException ( "Specification of the crs information is forbidden in child elements. Either " + "leave it out, or specify it at the toplevel object." ) ; } subJson = setCrsIds ( subJson , crsId ) ; List < Geometry > geometries = parent . collectionFromJson ( subJson , Geometry . class ) ; return new GeometryCollection ( geometries . toArray ( new Geometry [ geometries . size ( ) ] ) ) ; } catch ( JsonException e ) { throw new IOException ( e ) ; } }
Parses the JSON as a GeometryCollection .
5,230
private MultiPolygon asMultiPolygon ( List < List < List < List > > > coords , CrsId crsId ) throws IOException { if ( coords == null || coords . isEmpty ( ) ) { throw new IOException ( "A multipolygon should have at least one polyon." ) ; } Polygon [ ] polygons = new Polygon [ coords . size ( ) ] ; for ( int i = 0 ; i < coords . size ( ) ; i ++ ) { polygons [ i ] = asPolygon ( coords . get ( i ) , crsId ) ; } return new MultiPolygon ( polygons ) ; }
Parses the JSON as a MultiPolygon geometry
5,231
private MultiLineString asMultiLineString ( List < List < List > > coords , CrsId crsId ) throws IOException { if ( coords == null || coords . isEmpty ( ) ) { throw new IOException ( "A multilinestring requires at least one line string" ) ; } LineString [ ] lineStrings = new LineString [ coords . size ( ) ] ; for ( int i = 0 ; i < lineStrings . length ; i ++ ) { lineStrings [ i ] = asLineString ( coords . get ( i ) , crsId ) ; } return new MultiLineString ( lineStrings ) ; }
Parses the JSON as a MultiLineString geometry
5,232
private Polygon asPolygon ( List < List < List > > coords , CrsId crsId ) throws IOException { if ( coords == null || coords . isEmpty ( ) ) { throw new IOException ( "A polygon requires the specification of its outer ring" ) ; } List < LinearRing > rings = new ArrayList < LinearRing > ( ) ; try { for ( List < List > ring : coords ) { PointSequence ringCoords = getPointSequence ( ring , crsId ) ; rings . add ( new LinearRing ( ringCoords ) ) ; } return new Polygon ( rings . toArray ( new LinearRing [ ] { } ) ) ; } catch ( IllegalArgumentException e ) { throw new IOException ( "Invalid Polygon: " + e . getMessage ( ) , e ) ; } }
Parses the JSON as a polygon geometry
5,233
private Point asPoint ( List coords , CrsId crsId ) throws IOException { if ( coords != null && coords . size ( ) >= 2 ) { ArrayList < List > coordinates = new ArrayList < List > ( ) ; coordinates . add ( coords ) ; return new Point ( getPointSequence ( coordinates , crsId ) ) ; } else { throw new IOException ( "A point must has exactly one coordinate (an x, a y and possibly a z value). Additional numbers in the coordinate are permitted but ignored." ) ; } }
Parses the JSON as a point geometry .
5,234
public final Solution < T > cluster ( final JavaRDD < T > input_data ) { if ( k <= 0 ) { throw new IllegalStateException ( "k must be > 0!" ) ; } if ( similarity == null ) { throw new IllegalStateException ( "Similarity is not defined!" ) ; } if ( budget == null ) { throw new IllegalStateException ( "No budget is defined!" ) ; } JavaRDD < T > data = input_data . cache ( ) ; Solution < T > solution = new Solution < > ( data . count ( ) ) ; logger . debug ( "Dataset contains {} objects" , solution . getDatasetSize ( ) ) ; neighbor_generator . init ( k ) ; points_supplier = new RandomPointsSupplier < > ( data , solution . getDatasetSize ( ) ) ; ArrayList < T > random_medoids = points_supplier . pick ( k ) ; solution . setNewMedoids ( random_medoids , evaluate ( data , random_medoids ) ) ; solution . incComputedSimilarities ( k * solution . getDatasetSize ( ) ) ; while ( true ) { logger . trace ( "Trial {}" , solution . getTrials ( ) ) ; CountingSimilarity < T > counting_sim = new CountingSimilarity < > ( similarity ) ; ArrayList < T > candidate ; try { candidate = neighbor_generator . getNeighbor ( new NeighborGeneratorHelper < > ( this ) , solution , counting_sim ) ; } catch ( NoNeighborFoundException ex ) { solution . incComputedSimilarities ( counting_sim . getCount ( ) ) ; break ; } solution . incComputedSimilarities ( counting_sim . getCount ( ) ) ; double candidate_similarity = evaluate ( data , candidate ) ; solution . incComputedSimilarities ( k * solution . getDatasetSize ( ) ) ; neighbor_generator . notifyCandidateSolutionCost ( candidate , candidate_similarity ) ; if ( candidate_similarity > solution . getTotalSimilarity ( ) ) { solution . setNewMedoids ( candidate , candidate_similarity ) ; solution . incIterations ( ) ; neighbor_generator . notifyNewSolution ( candidate , candidate_similarity ) ; } solution . incTrials ( ) ; if ( budget . isExhausted ( solution ) ) { break ; } } solution . end ( ) ; logger . debug ( "Found solution {}" , solution ) ; return solution ; }
Cluster the data according to defined parameters .
5,235
private static int argmax ( final double [ ] values ) { double max = - Double . MAX_VALUE ; int max_index = - 1 ; for ( int i = 0 ; i < values . length ; i ++ ) { if ( values [ i ] > max ) { max = values [ i ] ; max_index = i ; } } return max_index ; }
Return the index of the highest value in the array .
5,236
public static BooleanIsEqual isEqual ( ComparableExpression < Boolean > left , Boolean constant ) { return new BooleanIsEqual ( left , constant ( constant ) ) ; }
Creates a BooleanIsEqual expression from the given expression and constant .
5,237
public static IsGreaterThan isGreaterThan ( ComparableExpression < Number > left , ComparableExpression < Number > right ) { return new IsGreaterThan ( left , right ) ; }
Creates an IsGreaterThan expression from the given expressions .
5,238
public static IsGreaterThanOrEqual isGreaterThanOrEqual ( ComparableExpression < Number > left , ComparableExpression < Number > right ) { return new IsGreaterThanOrEqual ( left , right ) ; }
Creates an IsGreaterThanOrEqual expression from the given expressions .
5,239
public static BooleanIsLessThanOrEqual isLessThanOrEqual ( ComparableExpression < Boolean > left , Object constant ) { if ( ! ( constant instanceof Boolean ) ) throw new IllegalArgumentException ( "constant is not a Boolean" ) ; return new BooleanIsLessThanOrEqual ( left , constant ( ( Boolean ) constant ) ) ; }
Creates an BooleanIsGreaterThanOrEqual expression from the given expression and constant .
5,240
public static IsLessThan isLessThan ( ComparableExpression < Number > left , ComparableExpression < Number > right ) { return new IsLessThan ( left , right ) ; }
Creates an IsLessThan expression from the given expressions .
5,241
public static IsLessThan isLessThan ( ComparableExpression < Number > left , Object constant ) { if ( ! ( constant instanceof Number ) ) throw new IllegalArgumentException ( "constant is not a Number" ) ; return new IsLessThan ( left , constant ( ( Number ) constant ) ) ; }
Creates an IsLessThan expression from the given expression and constant .
5,242
public static BooleanIsLessThan isLessThan ( BooleanExpression left , Object constant ) { if ( ! ( constant instanceof Boolean ) ) throw new IllegalArgumentException ( "constant is not a Boolean" ) ; return new BooleanIsLessThan ( left , constant ( ( Boolean ) constant ) ) ; }
Creates an BooleanIsLessThan expression from the given expression and constant .
5,243
public static StringIsLessThan isLessThan ( StringExpression left , Object constant ) { if ( ! ( constant instanceof String ) ) throw new IllegalArgumentException ( "constant is not a String" ) ; return new StringIsLessThan ( left , constant ( ( String ) constant ) ) ; }
Creates an StringIsLessThan expression from the given expression and constant .
5,244
public static IsLessThanOrEqual isLessThanOrEqual ( NumberExpression left , Object constant ) { if ( ! ( constant instanceof Number ) ) throw new IllegalArgumentException ( "constant is not a Number" ) ; return new IsLessThanOrEqual ( left , constant ( ( Number ) constant ) ) ; }
Creates an IsLessThanOrEqual expression from the given expression and constant .
5,245
public static StringIsLessThanOrEqual isLessThanOrEqual ( StringExpression left , Object constant ) { if ( ! ( constant instanceof String ) ) throw new IllegalArgumentException ( "constant is not a String" ) ; return new StringIsLessThanOrEqual ( left , constant ( ( String ) constant ) ) ; }
Creates an StringIsLessThanOrEqual expression from the given expression and constant .
5,246
public static IsNotEqual isNotEqual ( ComparableExpression < Number > left , Object constant ) { if ( ! ( constant instanceof Number ) ) throw new IllegalArgumentException ( "constant is not a Number" ) ; return new IsNotEqual ( left , constant ( ( Number ) constant ) ) ; }
Creates an IsNotEqual expression from the given expression and constant .
5,247
public static BooleanIsNotEqual isNotEqual ( ComparableExpression < Boolean > left , ComparableExpression < Boolean > right ) { return new BooleanIsNotEqual ( left , right ) ; }
Creates an BooleanIsNotEqual expression from the given expressions .
5,248
public static Add add ( Expression < Number > left , Expression < Number > right ) { return new Add ( left , right ) ; }
Creates an Add expression from the given expressions .
5,249
public static NotLike notLike ( Expression < String > left , String constant , boolean caseInsensitive ) { return new NotLike ( left , constant ( constant ) , caseInsensitive ) ; }
Creates a NotLike expression from the given expressions with % as the wildcard character
5,250
public static NotLike notLike ( Expression < String > left , Expression < String > right , char wildCardCharacter ) { return new NotLike ( left , right , wildCardCharacter ) ; }
Creates a NotLike expression from the given expressions .
5,251
public static And and ( Expression < Boolean > left , Expression < Boolean > right ) { return new And ( left , right ) ; }
Creates an And expression from the given expressions .
5,252
public static Or or ( Expression < Boolean > left , Expression < Boolean > right ) { return new Or ( left , right ) ; }
Creates an Or expression from the given expressions .
5,253
public static IsBefore isBefore ( Expression < Date > left , Expression < Date > right ) { return new IsBefore ( left , right ) ; }
Creates an IsBefore expression from the given expressions .
5,254
public static IsAfter isAfter ( Expression < Date > left , Expression < Date > right ) { return new IsAfter ( left , right ) ; }
Creates an IsAfter expression from the given expressions .
5,255
public static DateIsBetween isBetween ( ComparableExpression < Date > date , ComparableExpression < Date > lowDate , ComparableExpression < Date > highDate ) { return new DateIsBetween ( date , lowDate , highDate ) ; }
Creates an IsBetween expression from the given expressions .
5,256
public static GeoEquals geoEquals ( Expression < Geometry > left , Expression < Geometry > right ) { return new GeoEquals ( left , right ) ; }
Creates a GeoEquals expression from the left and right expressions .
5,257
public void setGeometry ( String name , Geometry value ) { if ( name == null ) { geomPropertyName = null ; geomValue = null ; } else { geomPropertyName = name ; geomValue = value ; } }
Sets the geometry property of the feature . This method also allows wiping the current geometry by setting the name of the property to null . The value will in that case be ignored .
5,258
public void setId ( String name , Object value ) { if ( name == null ) { idPropertyName = null ; idValue = null ; } else { idPropertyName = name ; idValue = value ; } }
Sets the id property of the feature . This method also allows wiping the current id by setting the name of the id to null . The value will in that case be ignored .
5,259
public void addProperty ( String propertyName , Object value ) { if ( propertyName != null ) { propertyNames . add ( propertyName ) ; if ( value == null ) { properties . remove ( propertyName ) ; } else { properties . put ( propertyName , value ) ; } } }
The name of the property to add . if it already exists the value is updated . If the propertyname is null the property addition is ignored .
5,260
public void wipeProperty ( String propertyName ) { if ( propertyName != null ) { propertyNames . remove ( propertyName ) ; if ( properties . containsKey ( propertyName ) ) { properties . remove ( propertyName ) ; } } }
If a property with the specified name exists it is removed from this feature . if the given propertyname is null the call is ignored . Note that this method has no effect whatsoever regarding the geometry or id property .
5,261
public static Filter toStaticFilter ( String cqlExpression , Class clazz ) throws ParseException { try { Parser p = new Parser ( new Lexer ( new PushbackReader ( new StringReader ( cqlExpression ) , 1024 ) ) ) ; Start tree = p . parse ( ) ; FilterExpressionBuilder builder = new FilterExpressionBuilder ( ) ; tree . apply ( builder ) ; return new Filter ( builder . getExp ( ) ) ; } catch ( ParserException e ) { ParseException parseException = new ParseException ( e . getMessage ( ) , e . getToken ( ) . getPos ( ) ) ; parseException . initCause ( e ) ; throw parseException ; } catch ( LexerException e ) { ParseException parseException = new ParseException ( e . getMessage ( ) , 0 ) ; parseException . initCause ( e ) ; throw parseException ; } catch ( IOException e ) { ParseException parseException = new ParseException ( e . getMessage ( ) , 0 ) ; parseException . initCause ( e ) ; throw parseException ; } }
Creates an executable object filter based on the given CQL expression . This filter is only applicable for the given class .
5,262
private void swap ( int n , int m ) { int eM = elements [ m ] ; int eN = elements [ n ] ; elements [ m ] = eN ; elements [ n ] = eM ; positions [ eM ] = n ; positions [ eN ] = m ; }
swap data in node n with data in node m
5,263
private void moveAtFirst ( int n_from ) { int eT = elements [ 0 ] ; int eF = elements [ n_from ] ; positions [ eT ] = - 1 ; positions [ eF ] = 0 ; elements [ 0 ] = eF ; elements [ n_from ] = - 1 ; }
moveAtFirst data in node n_from to node 0 Erase previous information of node 0
5,264
public boolean registerConfiguration ( EncodingConfiguration ec ) { boolean changed = false ; if ( sc . getChannelCount ( ) != 2 ) ec . setChannelConfig ( EncodingConfiguration . ChannelConfig . INDEPENDENT ) ; this . ec = new EncodingConfiguration ( ec ) ; verbatimSubframe . registerConfiguration ( this . ec ) ; fixedSubframe . registerConfiguration ( this . ec ) ; lpcSubframe . registerConfiguration ( this . ec ) ; constantSubframe . registerConfiguration ( this . ec ) ; changed = true ; return changed ; }
This method is used to set the encoding configuration . This configuration can be altered throughout the stream but cannot be called while an encoding process is active .
5,265
public boolean removeNode ( int x , ICause cause ) throws ContradictionException { assert cause != null ; assert ( x >= 0 && x < n ) ; if ( LB . getNodes ( ) . contains ( x ) ) { this . contradiction ( cause , "remove mandatory node" ) ; return true ; } else if ( ! UB . getNodes ( ) . contains ( x ) ) { return false ; } ISet nei = UB . getSuccOrNeighOf ( x ) ; for ( int i : nei ) { removeArc ( x , i , cause ) ; } nei = UB . getPredOrNeighOf ( x ) ; for ( int i : nei ) { removeArc ( i , x , cause ) ; } if ( UB . removeNode ( x ) ) { if ( reactOnModification ) { delta . add ( x , GraphDelta . NR , cause ) ; } GraphEventType e = GraphEventType . REMOVE_NODE ; notifyPropagators ( e , cause ) ; return true ; } return false ; }
Remove node x from the domain Removes x from the upper bound graph
5,266
public boolean enforceNode ( int x , ICause cause ) throws ContradictionException { assert cause != null ; assert ( x >= 0 && x < n ) ; if ( UB . getNodes ( ) . contains ( x ) ) { if ( LB . addNode ( x ) ) { if ( reactOnModification ) { delta . add ( x , GraphDelta . NE , cause ) ; } GraphEventType e = GraphEventType . ADD_NODE ; notifyPropagators ( e , cause ) ; return true ; } return false ; } this . contradiction ( cause , "enforce node which is not in the domain" ) ; return true ; }
Enforce the node x to belong to any solution Adds x to the lower bound graph
5,267
public void clear ( int size , int off ) { if ( size % 4 != 4 ) size = ( size / 4 + 1 ) * 4 ; next = null ; previous = null ; data = new byte [ size ] ; offset = off ; for ( int i = 0 ; i < data . length ; i ++ ) data [ i ] = 0 ; usableBits = off ; }
Completely clear this element and use the given size and offset for the new data array .
5,268
protected static EncodedElement getEnd_S ( EncodedElement e ) { if ( e == null ) return null ; EncodedElement temp = e . next ; EncodedElement end = e ; while ( temp != null ) { end = temp ; temp = temp . next ; } return end ; }
Return the last element of the list given . This is a static funtion to provide minor speed improvement . Loops through all elements next pointers till the last is found .
5,269
public EncodedElement getEnd ( ) { EncodedElement temp = next ; EncodedElement end = this ; while ( temp != null ) { end = temp ; temp = temp . next ; } return end ; }
Return the last element of the list given . Loops through all elements next pointers till the last is found .
5,270
public boolean attachEnd ( EncodedElement e ) { if ( DEBUG_LEV > 0 ) System . err . println ( "EncodedElement::attachEnd : Begin" ) ; boolean attached = true ; EncodedElement current = this ; while ( current . getNext ( ) != null ) { current = current . getNext ( ) ; } current . setNext ( e ) ; e . setPrevious ( current ) ; if ( DEBUG_LEV > 0 ) System . err . println ( "EncodedElement::attachEnd : End" ) ; return attached ; }
Attach an element to the end of this list .
5,271
public EncodedElement addLong ( long input , int bitCount ) { if ( next != null ) { EncodedElement end = EncodedElement . getEnd_S ( next ) ; return end . addLong ( input , bitCount ) ; } else if ( data . length * 8 <= usableBits + bitCount ) { int tOff = usableBits % 8 ; int size = data . length / 2 + 1 ; if ( size < bitCount ) size = bitCount * 10 ; next = new EncodedElement ( size , tOff ) ; return next . addLong ( input , bitCount ) ; } int startPos = this . usableBits ; byte [ ] dest = this . data ; EncodedElement . addLong ( input , bitCount , startPos , dest ) ; usableBits += bitCount ; return this ; }
Add a number of bits from a long to the end of this list s data . Will add a new element if necessary . The bits stored are taken from the lower - order of input .
5,272
public EncodedElement packInt ( int [ ] inputArray , int bitSize , int start , int skip , int countA ) { if ( next != null ) { EncodedElement end = EncodedElement . getEnd_S ( next ) ; return end . packInt ( inputArray , bitSize , start , skip , countA ) ; } int writeCount = ( data . length * 8 - usableBits ) / bitSize ; if ( writeCount > countA ) writeCount = countA ; EncodedElement . packInt ( inputArray , bitSize , usableBits , start , skip , countA , data ) ; usableBits += writeCount * bitSize ; countA -= writeCount ; if ( countA > 0 ) { int tOff = usableBits % 8 ; int size = data . length / 2 + 1 ; if ( size < bitSize * countA ) size = bitSize * countA + 10 ; next = new EncodedElement ( size , tOff ) ; return next . packInt ( inputArray , bitSize , start + writeCount * ( skip + 1 ) , skip , countA ) ; } else { return this ; } }
Append an equal number of bits from each int in an array within given limits to the end of this list .
5,273
public int getTotalBits ( ) { int total = 0 ; EncodedElement iter = this ; while ( iter != null ) { total += iter . usableBits - iter . offset ; iter = iter . next ; } return total ; }
Total number of usable bits stored by this entire list . This sums the difference of each list element s usableBits and offset .
5,274
private static void addLong ( long input , int count , int startPos , byte [ ] dest ) { if ( DEBUG_LEV > 30 ) System . err . println ( "EncodedElement::addLong : Begin" ) ; int currentByte = startPos / 8 ; int currentOffset = startPos % 8 ; int bitRoom ; long upMask ; int downShift ; int upShift ; while ( count > 0 ) { bitRoom = 8 - currentOffset ; downShift = count - bitRoom ; upMask = 255 >>> currentOffset ; upShift = 0 ; if ( downShift < 0 ) { upShift = bitRoom - count ; upMask = 255 >>> ( currentOffset + upShift ) ; downShift = 0 ; } if ( DEBUG_LEV > 30 ) { System . err . println ( "count:offset:bitRoom:downShift:upShift:" + count + ":" + currentOffset + ":" + bitRoom + ":" + downShift + ":" + upShift ) ; } long currentBits = ( input >>> downShift ) & ( upMask ) ; currentBits = currentBits << upShift ; upMask = ( byte ) upMask << upShift ; dest [ currentByte ] = ( byte ) ( dest [ currentByte ] & ( ~ upMask ) ) ; dest [ currentByte ] = ( byte ) ( dest [ currentByte ] | currentBits ) ; count -= bitRoom ; currentOffset = 0 ; currentByte ++ ; } if ( DEBUG_LEV > 30 ) System . err . println ( "EncodedElement::addLong : End" ) ; }
This method adds a given number of bits of a long to a byte array .
5,275
private static void packInt ( int [ ] inputArray , int bitSize , int startPosIn , int start , int skip , int countA , byte [ ] dest ) { if ( DEBUG_LEV > 30 ) System . err . println ( "EncodedElement::packInt : Begin" ) ; for ( int valI = 0 ; valI < countA ; valI ++ ) { int input = inputArray [ valI * ( skip + 1 ) + start ] ; int count = bitSize ; int startPos = startPosIn + valI * bitSize ; int currentByte = startPos / 8 ; int currentOffset = startPos % 8 ; int bitRoom ; int upMask ; int downShift ; int upShift ; while ( count > 0 ) { bitRoom = 8 - currentOffset ; downShift = count - bitRoom ; upMask = ( currentOffset >= 32 ) ? 0 : 255 >>> currentOffset ; upShift = 0 ; if ( downShift < 0 ) { upShift = bitRoom - count ; upMask = ( ( currentOffset + upShift ) >= 32 ) ? 0 : 255 >>> ( currentOffset + upShift ) ; downShift = 0 ; } if ( DEBUG_LEV > 30 ) { System . err . println ( "count:offset:bitRoom:downShift:upShift:" + count + ":" + currentOffset + ":" + bitRoom + ":" + downShift + ":" + upShift ) ; } int currentBits = ( downShift >= 32 ) ? 0 : ( input >>> downShift ) & upMask ; currentBits = ( upShift >= 32 ) ? 0 : currentBits << upShift ; upMask = ( upShift >= 32 ) ? 0 : ( ( byte ) upMask ) << upShift ; dest [ currentByte ] = ( byte ) ( dest [ currentByte ] & ( ~ upMask ) ) ; dest [ currentByte ] = ( byte ) ( dest [ currentByte ] | currentBits ) ; count -= bitRoom ; currentOffset = 0 ; currentByte ++ ; } } if ( DEBUG_LEV > 30 ) System . err . println ( "EncodedElement::packInt: End" ) ; }
Append an equal number of bits from each int in an array within given limits to the given byte array .
5,276
public boolean padToByte ( ) { boolean padded = false ; EncodedElement end = EncodedElement . getEnd_S ( this ) ; int tempVal = end . usableBits ; if ( tempVal % 8 != 0 ) { int toWrite = 8 - ( tempVal % 8 ) ; end . addInt ( 0 , toWrite ) ; assert ( ( this . getTotalBits ( ) + offset ) % 8 == 0 ) ; padded = true ; } return padded ; }
Force the usable data stored in this list ends on a a byte boundary by padding to the end with zeros .
5,277
public static int getDataFormatSupport ( AudioFormat format ) { int result = SUPPORTED ; float sampleRate = format . getSampleRate ( ) ; AudioFormat . Encoding encoding = format . getEncoding ( ) ; if ( format . getChannels ( ) > 8 || format . getChannels ( ) < 1 ) result |= UNSUPPORTED_CHANNELCOUNT ; if ( format . getSampleSizeInBits ( ) > 24 || format . getSampleSizeInBits ( ) % 8 != 0 ) result |= UNSUPPORTED_SAMPLESIZE ; if ( sampleRate <= 0 || sampleRate > 655350 || sampleRate == AudioSystem . NOT_SPECIFIED ) result |= UNSUPPORTED_SAMPLERATE ; if ( ! ( AudioFormat . Encoding . ALAW . equals ( encoding ) || AudioFormat . Encoding . ULAW . equals ( encoding ) || AudioFormat . Encoding . PCM_SIGNED . equals ( encoding ) || AudioFormat . Encoding . PCM_UNSIGNED . equals ( encoding ) ) ) result |= UNSUPPORTED_ENCODINGTYPE ; return result ; }
Checks whether the given AudioFormat can be properly encoded by this FLAC library .
5,278
private static byte encodeBlockSize ( int blockSize ) { if ( DEBUG_LEV > 0 ) System . err . println ( "FrameHeader::encodeBlockSize : Begin" ) ; byte value = 0 ; int i ; for ( i = 0 ; i < definedBlockSizes . length ; i ++ ) { if ( blockSize == definedBlockSizes [ i ] ) { value = ( byte ) i ; break ; } } if ( i >= definedBlockSizes . length ) { if ( blockSize <= 255 ) value = 0x6 ; else value = 0x7 ; } if ( DEBUG_LEV > 0 ) System . err . println ( "FrameHeader::encodeBlockSize : End" ) ; return value ; }
Given a block size select the proper bit settings to use according to the FLAC stream .
5,279
public void blockWhileQueueExceeds ( int count ) { boolean loop = true ; boolean interrupted = false ; try { do { synchronized ( outstandingCountLock ) { if ( outstandingCount > count ) { try { outstandingCountLock . wait ( ) ; } catch ( InterruptedException e ) { interrupted = true ; } } else loop = false ; } } while ( loop ) ; } finally { if ( interrupted ) Thread . currentThread ( ) . interrupt ( ) ; } }
This function is used to help control flow of BlockEncodeRequests into this manager . It will block so long as their is at least as many unprocessed blocks waiting to be encoded as the value given .
5,280
synchronized public boolean addFrameThread ( Frame frame ) { FrameThread ft = new FrameThread ( frame , this ) ; inactiveFrameThreads . add ( ft ) ; boolean r = true ; startFrameThreads ( ) ; return r ; }
Add a Frame to this manager which it will use to encode a block . Each Frame added allows one more thread to be used for encoding . At least one Frame must be added for this manager to encode .
5,281
synchronized private void startFrameThreads ( ) { if ( ! process ) return ; int requests = unassignedEncodeRequests . size ( ) ; int frames = inactiveFrameThreads . size ( ) ; frames = ( requests <= frames ) ? requests : frames ; for ( int i = 0 ; i < frames ; i ++ ) { FrameThread ft = inactiveFrameThreads . remove ( 0 ) ; Thread thread = new Thread ( ft ) ; frameThreadMap . put ( ft , thread ) ; thread . start ( ) ; } }
Start any available FrameThread objects encoding so long as there are waiting BlockEncodeRequest objects .
5,282
public void run ( ) { boolean loop = true ; boolean interrupted = false ; try { while ( loop ) { try { if ( nextTarget == null ) nextTarget = orderedEncodeRequests . poll ( 500 , TimeUnit . MILLISECONDS ) ; if ( nextTarget == null ) { loop = false ; } else if ( nextTarget . frameNumber < 0 ) { loop = false ; nextTarget = null ; orderedEncodeRequests . clear ( ) ; } else if ( finishedRequestStore . remove ( nextTarget ) ) { encoder . blockFinished ( nextTarget ) ; nextTarget = null ; synchronized ( outstandingCountLock ) { outstandingCount -- ; outstandingCountLock . notifyAll ( ) ; } } else { BlockEncodeRequest ber = finishedEncodeRequests . poll ( 500 , TimeUnit . MILLISECONDS ) ; if ( ber == null ) { loop = false ; } else if ( nextTarget == ber ) { encoder . blockFinished ( ber ) ; nextTarget = null ; synchronized ( outstandingCountLock ) { outstandingCount -- ; outstandingCountLock . notifyAll ( ) ; } } else { finishedRequestStore . add ( ber ) ; } } } catch ( InterruptedException e ) { interrupted = true ; } } } finally { if ( interrupted ) Thread . currentThread ( ) . interrupt ( ) ; } synchronized ( this ) { managerThread = null ; restartManager ( ) ; } }
Waits for the next BlockEncodeRequest that needs to be sent back to the FLACEncoder for finalizing . If no request is finished or currently assigned to an encoding thread will timeout after 0 . 5 seconds and end .
5,283
private void proceedFirstDFS ( ) { for ( int i = 0 ; i < nbNodes ; i ++ ) { iterator [ i ] = successors [ i ] . iterator ( ) ; } int i = root ; int k = 0 ; father [ k ] = k ; dfsNumberOfNode [ root ] = k ; nodeOfDfsNumber [ k ] = root ; int j ; k ++ ; while ( true ) { if ( iterator [ i ] . hasNext ( ) ) { j = iterator [ i ] . next ( ) ; if ( dfsNumberOfNode [ j ] == - 1 ) { father [ k ] = dfsNumberOfNode [ i ] ; dfsNumberOfNode [ j ] = k ; nodeOfDfsNumber [ k ] = j ; i = j ; k ++ ; } } else { if ( i == root ) { break ; } else { i = nodeOfDfsNumber [ father [ dfsNumberOfNode [ i ] ] ] ; } } } if ( k != nbActives ) { throw new UnsupportedOperationException ( "LCApreprocess did not reach all nodes" ) ; } for ( ; k < nbNodes ; k ++ ) { father [ k ] = - 1 ; } }
perform a dfs in graph to label nodes
5,284
public GraphSearch configure ( int policy , boolean enforce ) { if ( enforce ) { decisionType = GraphAssignment . graph_enforcer ; } else { decisionType = GraphAssignment . graph_remover ; } mode = policy ; return this ; }
Configures the search
5,285
public void generate ( org . codehaus . doxia . sink . Sink sink , Locale locale ) throws MavenReportException { generate ( ( Sink ) sink , locale ) ; }
eventually we must replace this with the o . a . m . d . s . Sink class as a parameter
5,286
public boolean setSampleRate ( int rate ) { boolean result = ( rate <= MAX_SAMPLE_RATE && rate >= MIN_SAMPLE_RATE ) ; sampleRate = rate ; return result ; }
Set the sample rate . Because this is not a value that may be guessed and corrected the value will be set to that given even if it is not valid .
5,287
public boolean setBitsPerSample ( int bitsPerSample ) { boolean result = ( ( bitsPerSample <= MAX_BITS_PER_SAMPLE ) && ( bitsPerSample >= MIN_BITS_PER_SAMPLE ) ) ; this . bitsPerSample = bitsPerSample ; return result ; }
Set the bits per sample . Because this is not a value that may be guessed and corrected the value will be set to that given even if it is not valid .
5,288
public int setMaxBlockSize ( int size ) { maxBlockSize = ( size <= MAX_BLOCK_SIZE ) ? size : MAX_BLOCK_SIZE ; maxBlockSize = ( maxBlockSize >= MIN_BLOCK_SIZE ) ? maxBlockSize : MIN_BLOCK_SIZE ; return maxBlockSize ; }
Set the maximum block size to use . If this value is out of a valid range it will be set to the closest valid value . User must ensure that this value is set above or equal to the minimum block size .
5,289
public int setMinBlockSize ( int size ) { minBlockSize = ( size <= MAX_BLOCK_SIZE ) ? size : MAX_BLOCK_SIZE ; minBlockSize = ( minBlockSize >= MIN_BLOCK_SIZE ) ? maxBlockSize : MIN_BLOCK_SIZE ; return minBlockSize ; }
Set the minimum block size to use . If this value is out of a valid range it will be set to the closest valid value . User must ensure that this value is set below or equal to the maximum block size .
5,290
public boolean isEncodingSubsetCompliant ( EncodingConfiguration ec ) { boolean result = true ; result = isStreamSubsetCompliant ( ) ; if ( this . sampleRate <= 48000 ) { result &= ec . maximumLPCOrder <= 12 ; result &= ec . maximumRicePartitionOrder <= 8 ; } return result ; }
Test if this StreamConfiguration and a paired EncodingConfiguration define a Subset compliant stream . FLAC defines a subset of options to ensure resulting FLAC streams are streamable .
5,291
public static EncodedElement getStreamInfo ( StreamConfiguration sc , int minFrameSize , int maxFrameSize , long samplesInStream , byte [ ] md5Hash ) { int bytes = getByteSize ( ) ; EncodedElement ele = new EncodedElement ( bytes , 0 ) ; int encodedBitsPerSample = sc . getBitsPerSample ( ) - 1 ; ele . addInt ( sc . getMinBlockSize ( ) , 16 ) ; ele . addInt ( sc . getMaxBlockSize ( ) , 16 ) ; ele . addInt ( minFrameSize , 24 ) ; ele . addInt ( maxFrameSize , 24 ) ; ele . addInt ( sc . getSampleRate ( ) , 20 ) ; ele . addInt ( sc . getChannelCount ( ) - 1 , 3 ) ; ele . addInt ( encodedBitsPerSample , 5 ) ; ele . addLong ( samplesInStream , 36 ) ; for ( int i = 0 ; i < 16 ; i ++ ) { ele . addInt ( md5Hash [ i ] , 8 ) ; } return ele ; }
Create a FLAC StreamInfo metadata block with the given parameters . Because of the data stored in a StreamInfo block this should generally be created only after all encoding is done .
5,292
static public int getByteSize ( ) { int size = 0 ; size += 16 ; size += 16 ; size += 24 ; size += 24 ; size += 20 ; size += 3 ; size += 5 ; size += 36 ; size += 64 ; size += 64 ; size = size / 8 ; return size ; }
Get the expected size of a properly formed STREAMINFO metadata block .
5,293
public static void calculate ( LPC lpc , long [ ] R ) { int coeffCount = lpc . order ; double [ ] A = lpc . rawCoefficients ; for ( int i = 0 ; i < coeffCount + 1 ; i ++ ) A [ i ] = 0.0 ; A [ 0 ] = 1 ; double E = R [ 0 ] ; if ( R [ 0 ] == 0 ) { for ( int i = 0 ; i < coeffCount + 1 ; i ++ ) A [ i ] = 0.0 ; } else { double [ ] ATemp = lpc . tempCoefficients ; for ( int i = 0 ; i < coeffCount + 1 ; i ++ ) ATemp [ i ] = 0.0 ; for ( int k = 0 ; k < coeffCount ; k ++ ) { double lambda = 0.0 ; double temp = 0 ; for ( int j = 0 ; j <= k ; j ++ ) { temp += A [ j ] * R [ k + 1 - j ] ; } lambda = - temp / E ; for ( int i = 0 ; i <= k + 1 ; i ++ ) { ATemp [ i ] = A [ i ] + lambda * A [ k + 1 - i ] ; } System . arraycopy ( ATemp , 0 , A , 0 , coeffCount + 1 ) ; E = ( 1 - lambda * lambda ) * E ; } } lpc . rawError = E ; }
Calculate an LPC using the given Auto - correlation data . Static method used since this is slightly faster than a more strictly object - oriented approach .
5,294
public static void calculateFromPrior ( LPC lpc , long [ ] R , LPC priorLPC ) { int coeffCount = lpc . order ; double [ ] A = lpc . rawCoefficients ; for ( int i = 0 ; i < coeffCount + 1 ; i ++ ) A [ i ] = 0.0 ; A [ 0 ] = 1 ; double E = R [ 0 ] ; int startIter = 0 ; if ( priorLPC != null && priorLPC . order < lpc . order ) { startIter = priorLPC . order ; E = priorLPC . rawError ; System . arraycopy ( priorLPC . rawCoefficients , 0 , A , 0 , startIter + 1 ) ; } if ( R [ 0 ] == 0 ) { for ( int i = 0 ; i < coeffCount + 1 ; i ++ ) A [ i ] = 0.0 ; } else { double [ ] ATemp = lpc . tempCoefficients ; for ( int i = 0 ; i < coeffCount + 1 ; i ++ ) ATemp [ i ] = 0.0 ; for ( int k = startIter ; k < coeffCount ; k ++ ) { double lambda = 0.0 ; double temp = 0.0 ; for ( int j = 0 ; j <= k ; j ++ ) { temp -= A [ j ] * R [ k - j + 1 ] ; } lambda = temp / E ; for ( int i = 0 ; i <= k + 1 ; i ++ ) { ATemp [ i ] = A [ i ] + lambda * A [ k + 1 - i ] ; } System . arraycopy ( ATemp , 0 , A , 0 , coeffCount + 1 ) ; E = ( 1 - lambda * lambda ) * E ; } } lpc . rawError = E ; }
Calculate an LPC using a prior order LPC s values to save calculations .
5,295
public static int binaryLCA ( int x , int y ) { if ( x == y ) { return x ; } int xor = x ^ y ; int idx = getMaxExp ( xor ) ; if ( idx == - 1 ) { throw new UnsupportedOperationException ( ) ; } return replaceBy1and0sFrom ( x , idx ) ; }
Get the lowest common ancestor of x and y in a complete binary tree
5,296
public void setAll ( int [ ] samples , int count , int start , int skip , long frameNumber , EncodedElement result ) { this . samples = samples ; this . count = count ; this . start = start ; this . skip = skip ; this . frameNumber = frameNumber ; this . result = result ; valid = false ; this . encodedSamples = 0 ; }
Set all values preparing this object to be sent to an encoder . Member variable valid is set to false by this call .
5,297
int getInt ( String [ ] args , int index ) { int result = - 1 ; if ( index >= 0 && index < args . length ) { try { result = Integer . parseInt ( args [ index ] ) ; } catch ( NumberFormatException e ) { result = - 1 ; } } return result ; }
Utility function to parse a positive integer argument out of a String array at the given index .
5,298
private StreamConfiguration adjustConfigurations ( AudioFormat format ) { int sampleRate = ( int ) format . getSampleRate ( ) ; int sampleSize = format . getSampleSizeInBits ( ) ; int channels = format . getChannels ( ) ; StreamConfiguration streamConfiguration = new StreamConfiguration ( ) ; streamConfiguration . setSampleRate ( sampleRate ) ; streamConfiguration . setBitsPerSample ( sampleSize ) ; streamConfiguration . setChannelCount ( channels ) ; return streamConfiguration ; }
Method sets input stream configuration for encoder .
5,299
private static void validateCategories ( String ... categories ) { for ( String category : categories ) { if ( ! category . matches ( FCM_TOPIC_PATTERN ) ) { throw new IllegalArgumentException ( String . format ( "%s does not match %s" , category , FCM_TOPIC_PATTERN ) ) ; } } }
Validates categories against Google s pattern .