idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
11,700
public int columnIndex ( String columnName ) { for ( int i = 0 ; i < columnCount ( ) ; i ++ ) { if ( columnNames ( ) . get ( i ) . equalsIgnoreCase ( columnName ) ) { return i ; } } throw new IllegalArgumentException ( String . format ( "Column %s is not present in table %s" , columnName , name ( ) ) ) ; }
Returns the index of the column with the given columnName
11,701
public Column < ? > column ( String columnName ) { for ( Column < ? > column : columns ( ) ) { String name = column . name ( ) . trim ( ) ; if ( name . equalsIgnoreCase ( columnName ) ) { return column ; } } throw new IllegalStateException ( String . format ( "Column %s does not exist in table %s" , columnName , name ( ) ) ) ; }
Returns the column with the given columnName ignoring case
11,702
public List < Column < ? > > columns ( int ... columnIndices ) { List < Column < ? > > cols = new ArrayList < > ( columnIndices . length ) ; for ( int i : columnIndices ) { cols . add ( column ( i ) ) ; } return cols ; }
Returns the columns whose indices are given in the input array
11,703
public Object get ( int r , int c ) { Column < ? > column = column ( c ) ; return column . get ( r ) ; }
Returns the value at the given row and column indexes
11,704
public ColumnType [ ] columnTypes ( ) { ColumnType [ ] columnTypes = new ColumnType [ columnCount ( ) ] ; for ( int i = 0 ; i < columnCount ( ) ; i ++ ) { columnTypes [ i ] = columns ( ) . get ( i ) . type ( ) ; } return columnTypes ; }
Returns an array of the column types of all columns in the relation including duplicates as appropriate and maintaining order
11,705
public int [ ] colWidths ( ) { int cols = columnCount ( ) ; int [ ] widths = new int [ cols ] ; for ( int i = 0 ; i < columnCount ( ) ; i ++ ) { widths [ i ] = columns ( ) . get ( i ) . columnWidth ( ) ; } return widths ; }
Returns an array of column widths for printing tables
11,706
public Selection get ( short value ) { Selection selection = new BitmapBackedSelection ( ) ; IntArrayList list = index . get ( value ) ; if ( list != null ) { addAllToSelection ( list , selection ) ; } return selection ; }
Returns a bitmap containing row numbers of all cells matching the given int
11,707
public static long plus ( long packedDateTime , long amountToAdd , TemporalUnit unit ) { LocalDateTime dateTime = asLocalDateTime ( packedDateTime ) ; return pack ( dateTime . plus ( amountToAdd , unit ) ) ; }
Returns the given packedDateTime with amtToAdd of temporal units added
11,708
public ShortColumn asShortColumn ( ) { ShortArrayList values = new ShortArrayList ( ) ; for ( long f : data ) { values . add ( ( short ) f ) ; } values . trim ( ) ; return ShortColumn . create ( this . name ( ) , values . elements ( ) ) ; }
Returns a new ShortColumn containing a value for each value in this column
11,709
private Table splitGroupingColumn ( Table groupTable ) { if ( splitColumnNames . length > 0 ) { List < Column < ? > > newColumns = new ArrayList < > ( ) ; List < Column < ? > > columns = sourceTable . columns ( splitColumnNames ) ; for ( Column < ? > column : columns ) { Column < ? > newColumn = column . emptyCopy ( ) ; newColumns . add ( newColumn ) ; } for ( int row = 0 ; row < groupTable . rowCount ( ) ; row ++ ) { List < String > strings = SPLITTER . splitToList ( groupTable . stringColumn ( "Group" ) . get ( row ) ) ; for ( int col = 0 ; col < newColumns . size ( ) ; col ++ ) { newColumns . get ( col ) . appendCell ( strings . get ( col ) ) ; } } for ( int col = 0 ; col < newColumns . size ( ) ; col ++ ) { Column < ? > c = newColumns . get ( col ) ; groupTable . insertColumn ( col , c ) ; } groupTable . removeColumns ( "Group" ) ; } return groupTable ; }
For a subtable that is grouped by the values in more than one column split the grouping column into separate cols and return the revised view
11,710
public Table aggregate ( String colName1 , AggregateFunction < ? , ? > ... functions ) { ArrayListMultimap < String , AggregateFunction < ? , ? > > columnFunctionMap = ArrayListMultimap . create ( ) ; columnFunctionMap . putAll ( colName1 , Lists . newArrayList ( functions ) ) ; return aggregate ( columnFunctionMap ) ; }
Applies the given aggregation to the given column . The apply and combine steps of a split - apply - combine .
11,711
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public Table aggregate ( ListMultimap < String , AggregateFunction < ? , ? > > functions ) { Preconditions . checkArgument ( ! getSlices ( ) . isEmpty ( ) ) ; Table groupTable = summaryTableName ( sourceTable ) ; StringColumn groupColumn = StringColumn . create ( "Group" ) ; groupTable . addColumns ( groupColumn ) ; for ( Map . Entry < String , Collection < AggregateFunction < ? , ? > > > entry : functions . asMap ( ) . entrySet ( ) ) { String columnName = entry . getKey ( ) ; int functionCount = 0 ; for ( AggregateFunction function : entry . getValue ( ) ) { String colName = aggregateColumnName ( columnName , function . functionName ( ) ) ; ColumnType type = function . returnType ( ) ; Column resultColumn = type . create ( colName ) ; for ( TableSlice subTable : getSlices ( ) ) { Object result = function . summarize ( subTable . column ( columnName ) ) ; if ( functionCount == 0 ) { groupColumn . append ( subTable . name ( ) ) ; } if ( result instanceof Number ) { Number number = ( Number ) result ; resultColumn . append ( number . doubleValue ( ) ) ; } else { resultColumn . append ( result ) ; } } groupTable . addColumns ( resultColumn ) ; functionCount ++ ; } } return splitGroupingColumn ( groupTable ) ; }
Applies the given aggregations to the given columns . The apply and combine steps of a split - apply - combine .
11,712
public static String aggregateColumnName ( String columnName , String functionName ) { return String . format ( "%s [%s]" , functionName , columnName ) ; }
Returns a column name for aggregated data based on the given source column name and function
11,713
public IntColumn asIntColumn ( ) { IntArrayList values = new IntArrayList ( ) ; for ( float d : data ) { values . add ( ( int ) d ) ; } values . trim ( ) ; return IntColumn . create ( this . name ( ) , values . elements ( ) ) ; }
Returns a new IntColumn containing a value for each value in this column truncating if necessary .
11,714
public static long toEpochDay ( int packedDate ) { long y = getYear ( packedDate ) ; long m = getMonthValue ( packedDate ) ; long total = 0 ; total += 365 * y ; if ( y >= 0 ) { total += ( y + 3 ) / 4 - ( y + 99 ) / 100 + ( y + 399 ) / 400 ; } else { total -= y / - 4 - y / - 100 + y / - 400 ; } total += ( ( 367 * m - 362 ) / 12 ) ; total += getDayOfMonth ( packedDate ) - 1 ; if ( m > 2 ) { total -- ; if ( ! isLeapYear ( packedDate ) ) { total -- ; } } return total - DAYS_0000_TO_1970 ; }
Returns the epoch day in a form consistent with the java standard
11,715
public static int getQuarter ( int packedDate ) { if ( packedDate == DateColumnType . missingValueIndicator ( ) ) { return - 1 ; } Month month = getMonth ( packedDate ) ; switch ( month ) { case JANUARY : case FEBRUARY : case MARCH : return 1 ; case APRIL : case MAY : case JUNE : return 2 ; case JULY : case AUGUST : case SEPTEMBER : return 3 ; case OCTOBER : case NOVEMBER : default : return 4 ; } }
Returns the quarter of the year of the given date as an int from 1 to 4 or - 1 if the argument is the MISSING_VALUE for DateColumn
11,716
public double reduce ( String numberColumnName , NumericAggregateFunction function ) { NumberColumn < ? > column = table . numberColumn ( numberColumnName ) ; return function . summarize ( column . where ( selection ) ) ; }
Returns the result of applying the given function to the specified column
11,717
private static Sort getSort ( String ... columnNames ) { Sort key = null ; for ( String s : columnNames ) { if ( key == null ) { key = first ( s , Sort . Order . DESCEND ) ; } else { key . next ( s , Sort . Order . DESCEND ) ; } } return key ; }
Returns an object that can be used to sort this table in the order specified for by the given column names
11,718
public Table addColumns ( final Column < ? > ... cols ) { for ( final Column < ? > c : cols ) { validateColumn ( c ) ; columnList . add ( c ) ; } return this ; }
Adds the given column to this table
11,719
private void validateColumn ( final Column < ? > newColumn ) { Preconditions . checkNotNull ( newColumn , "Attempted to add a null to the columns in table " + name ) ; List < String > stringList = new ArrayList < > ( ) ; for ( String name : columnNames ( ) ) { stringList . add ( name . toLowerCase ( ) ) ; } if ( stringList . contains ( newColumn . name ( ) . toLowerCase ( ) ) ) { String message = String . format ( "Cannot add column with duplicate name %s to table %s" , newColumn , name ) ; throw new IllegalArgumentException ( message ) ; } checkColumnSize ( newColumn ) ; }
Throws an IllegalArgumentException if a column with the given name is already in the table or if the number of rows in the column does not match the number of rows in the table
11,720
public Table insertColumn ( int index , Column < ? > column ) { validateColumn ( column ) ; columnList . add ( index , column ) ; return this ; }
Adds the given column to this table at the given position in the column list
11,721
public int rowCount ( ) { int result = 0 ; if ( ! columnList . isEmpty ( ) ) { result = columnList . get ( 0 ) . size ( ) ; } return result ; }
Returns the number of rows in the table
11,722
public List < CategoricalColumn < ? > > categoricalColumns ( String ... columnNames ) { List < CategoricalColumn < ? > > columns = new ArrayList < > ( ) ; for ( String columnName : columnNames ) { columns . add ( categoricalColumn ( columnName ) ) ; } return columns ; }
Returns only the columns whose names are given in the input array
11,723
public int columnIndex ( String columnName ) { int columnIndex = - 1 ; for ( int i = 0 ; i < columnList . size ( ) ; i ++ ) { if ( columnList . get ( i ) . name ( ) . equalsIgnoreCase ( columnName ) ) { columnIndex = i ; break ; } } if ( columnIndex == - 1 ) { throw new IllegalArgumentException ( String . format ( "Column %s is not present in table %s" , columnName , name ) ) ; } return columnIndex ; }
Returns the index of the column with the given name
11,724
public List < String > columnNames ( ) { return columnList . stream ( ) . map ( Column :: name ) . collect ( toList ( ) ) ; }
Returns a List of the names of all the columns in this table
11,725
public Table copy ( ) { Table copy = new Table ( name ) ; for ( Column < ? > column : columnList ) { copy . addColumns ( column . emptyCopy ( rowCount ( ) ) ) ; } int [ ] rows = new int [ rowCount ( ) ] ; for ( int i = 0 ; i < rowCount ( ) ; i ++ ) { rows [ i ] = i ; } Rows . copyRowsToTable ( rows , this , copy ) ; return copy ; }
Returns a table with the same columns as this table
11,726
public Table emptyCopy ( ) { Table copy = new Table ( name ) ; for ( Column < ? > column : columnList ) { copy . addColumns ( column . emptyCopy ( ) ) ; } return copy ; }
Returns a table with the same columns as this table but no data
11,727
public Table [ ] sampleSplit ( double table1Proportion ) { Table [ ] tables = new Table [ 2 ] ; int table1Count = ( int ) Math . round ( rowCount ( ) * table1Proportion ) ; Selection table2Selection = new BitmapBackedSelection ( ) ; for ( int i = 0 ; i < rowCount ( ) ; i ++ ) { table2Selection . add ( i ) ; } Selection table1Selection = new BitmapBackedSelection ( ) ; Selection table1Records = selectNRowsAtRandom ( table1Count , rowCount ( ) ) ; for ( int table1Record : table1Records ) { table1Selection . add ( table1Record ) ; } table2Selection . andNot ( table1Selection ) ; tables [ 0 ] = where ( table1Selection ) ; tables [ 1 ] = where ( table2Selection ) ; return tables ; }
Splits the table into two randomly assigning records to each according to the proportion given in trainingProportion
11,728
public Table sampleX ( double proportion ) { Preconditions . checkArgument ( proportion <= 1 && proportion >= 0 , "The sample proportion must be between 0 and 1" ) ; int tableSize = ( int ) Math . round ( rowCount ( ) * proportion ) ; return where ( selectNRowsAtRandom ( tableSize , rowCount ( ) ) ) ; }
Returns a table consisting of randomly selected records from this table . The sample size is based on the given proportion
11,729
public Table sampleN ( int nRows ) { Preconditions . checkArgument ( nRows > 0 && nRows < rowCount ( ) , "The number of rows sampled must be greater than 0 and less than the number of rows in the table." ) ; return where ( selectNRowsAtRandom ( nRows , rowCount ( ) ) ) ; }
Returns a table consisting of randomly selected records from this table
11,730
private int [ ] rows ( ) { int [ ] rowIndexes = new int [ rowCount ( ) ] ; for ( int i = 0 ; i < rowCount ( ) ; i ++ ) { rowIndexes [ i ] = i ; } return rowIndexes ; }
Returns an array of ints of the same number of rows as the table
11,731
public void addRow ( int rowIndex , Table sourceTable ) { for ( int i = 0 ; i < columnCount ( ) ; i ++ ) { column ( i ) . appendObj ( sourceTable . column ( i ) . get ( rowIndex ) ) ; } }
Adds a single row to this table from sourceTable copying every column in sourceTable
11,732
public TableSliceGroup splitOn ( String ... columns ) { return splitOn ( categoricalColumns ( columns ) . toArray ( new CategoricalColumn < ? > [ columns . length ] ) ) ; }
Returns a non - overlapping and exhaustive collection of slices over this table . Each slice is like a virtual table containing a subset of the records in this table
11,733
public Table dropRowsWithMissingValues ( ) { Selection missing = new BitmapBackedSelection ( ) ; for ( int row = 0 ; row < rowCount ( ) ; row ++ ) { for ( int col = 0 ; col < columnCount ( ) ; col ++ ) { Column < ? > c = column ( col ) ; if ( c . isMissing ( row ) ) { missing . add ( row ) ; break ; } } } Selection notMissing = Selection . withRange ( 0 , rowCount ( ) ) ; notMissing . andNot ( missing ) ; Table temp = emptyCopy ( notMissing . size ( ) ) ; Rows . copyRowsToTable ( notMissing , this , temp ) ; return temp ; }
Returns only those records in this table that have no columns with missing values
11,734
public Table removeColumns ( Column < ? > ... columns ) { columnList . removeAll ( Arrays . asList ( columns ) ) ; return this ; }
Removes the given columns
11,735
public Table removeColumnsWithMissingValues ( ) { removeColumns ( columnList . stream ( ) . filter ( x -> x . countMissing ( ) > 0 ) . toArray ( Column < ? > [ ] :: new ) ) ; return this ; }
Removes the given columns with missing values
11,736
public Table xTabCounts ( String column1Name , String column2Name ) { return CrossTab . counts ( this , categoricalColumn ( column1Name ) , categoricalColumn ( column2Name ) ) ; }
Returns a table with n by m + 1 cells . The first column contains labels the other cells contains the counts for every unique combination of values from the two specified columns in this table
11,737
public Table xTabTablePercents ( String column1Name , String column2Name ) { return CrossTab . tablePercents ( this , column1Name , column2Name ) ; }
Returns a table with n by m + 1 cells . The first column contains labels the other cells contains the proportion for a unique combination of values from the two specified columns in this table
11,738
public boolean detect ( Predicate < Row > predicate ) { Row row = new Row ( this ) ; while ( row . hasNext ( ) ) { if ( predicate . test ( row . next ( ) ) ) { return true ; } } return false ; }
Applies the predicate to each row and return true if any row returns true
11,739
private Pair < Reader , ColumnType [ ] > getReaderAndColumnTypes ( FixedWidthReadOptions options ) throws IOException { ColumnType [ ] types = options . columnTypes ( ) ; byte [ ] bytesCache = null ; if ( types == null ) { Reader reader = options . source ( ) . createReader ( bytesCache ) ; if ( options . source ( ) . file ( ) == null ) { bytesCache = CharStreams . toString ( reader ) . getBytes ( ) ; reader = options . source ( ) . createReader ( bytesCache ) ; } types = detectColumnTypes ( reader , options ) ; } return Pair . create ( options . source ( ) . createReader ( bytesCache ) , types ) ; }
Determines column types if not provided by the user Reads all input into memory unless File was provided
11,740
public static Table read ( ResultSet resultSet ) throws SQLException { ResultSetMetaData metaData = resultSet . getMetaData ( ) ; Table table = Table . create ( ) ; for ( int i = 1 ; i <= metaData . getColumnCount ( ) ; i ++ ) { String name = metaData . getColumnName ( i ) ; int columnType = metaData . getColumnType ( i ) ; ColumnType type = SQL_TYPE_TO_TABLESAW_TYPE . get ( columnType ) ; if ( columnType == Types . NUMERIC || columnType == Types . DECIMAL ) { int s = metaData . getScale ( i ) ; if ( s == 0 ) { int p = metaData . getPrecision ( i ) ; if ( p <= 4 ) { type = ShortColumnType . instance ( ) ; } else if ( p <= 9 ) { type = ColumnType . INTEGER ; } else if ( p <= 18 ) { type = ColumnType . LONG ; } } else { if ( s <= 7 ) { type = ColumnType . FLOAT ; } else if ( s <= 16 ) { type = ColumnType . DOUBLE ; } } } Preconditions . checkState ( type != null , "No column type found for %s as specified for column %s" , metaData . getColumnType ( i ) , name ) ; Column < ? > newColumn = type . create ( name ) ; table . addColumns ( newColumn ) ; } while ( resultSet . next ( ) ) { for ( int i = 1 ; i <= metaData . getColumnCount ( ) ; i ++ ) { Column < ? > column = table . column ( i - 1 ) ; if ( column instanceof ShortColumn ) { column . appendObj ( resultSet . getShort ( i ) ) ; } else if ( column instanceof IntColumn ) { column . appendObj ( resultSet . getInt ( i ) ) ; } else if ( column instanceof LongColumn ) { column . appendObj ( resultSet . getLong ( i ) ) ; } else if ( column instanceof FloatColumn ) { column . appendObj ( resultSet . getFloat ( i ) ) ; } else if ( column instanceof DoubleColumn ) { column . appendObj ( resultSet . getDouble ( i ) ) ; } else { column . appendObj ( resultSet . getObject ( i ) ) ; } } } return table ; }
Returns a new table with the given tableName constructed from the given result set
11,741
public static IntComparatorChain getChain ( Table table , Sort key ) { Iterator < Map . Entry < String , Sort . Order > > entries = key . iterator ( ) ; Map . Entry < String , Sort . Order > sort = entries . next ( ) ; Column < ? > column = table . column ( sort . getKey ( ) ) ; IntComparator comparator = rowComparator ( column , sort . getValue ( ) ) ; IntComparatorChain chain = new IntComparatorChain ( comparator ) ; while ( entries . hasNext ( ) ) { sort = entries . next ( ) ; chain . addComparator ( rowComparator ( table . column ( sort . getKey ( ) ) , sort . getValue ( ) ) ) ; } return chain ; }
Returns a comparator chain for sorting according to the given key
11,742
public static IntComparator rowComparator ( Column < ? > column , Sort . Order order ) { IntComparator rowComparator = column . rowComparator ( ) ; if ( order == Sort . Order . DESCEND ) { return ReversingIntComparator . reverse ( rowComparator ) ; } else { return rowComparator ; } }
Returns a comparator for the column matching the specified name
11,743
public static IntComparator getComparator ( Table table , Sort key ) { Iterator < Map . Entry < String , Sort . Order > > entries = key . iterator ( ) ; Map . Entry < String , Sort . Order > sort = entries . next ( ) ; Column < ? > column = table . column ( sort . getKey ( ) ) ; return SortUtils . rowComparator ( column , sort . getValue ( ) ) ; }
Returns a comparator that can be used to sort the records in this table according to the given sort key
11,744
private ColumnType detectType ( List < String > valuesList , ReadOptions options ) { CopyOnWriteArrayList < AbstractColumnParser < ? > > parsers = new CopyOnWriteArrayList < > ( getParserList ( typeArray , options ) ) ; CopyOnWriteArrayList < ColumnType > typeCandidates = new CopyOnWriteArrayList < > ( typeArray ) ; for ( String s : valuesList ) { for ( AbstractColumnParser < ? > parser : parsers ) { if ( ! parser . canParse ( s ) ) { typeCandidates . remove ( parser . columnType ( ) ) ; parsers . remove ( parser ) ; } } } return selectType ( typeCandidates ) ; }
Returns a predicted ColumnType derived by analyzing the given list of undifferentiated strings read from a column in the file and applying the given Locale and options
11,745
private List < AbstractColumnParser < ? > > getParserList ( List < ColumnType > typeArray , ReadOptions options ) { List < AbstractColumnParser < ? > > parsers = new ArrayList < > ( ) ; for ( ColumnType type : typeArray ) { parsers . add ( type . customParser ( options ) ) ; } return parsers ; }
Returns the list of parsers to use for type detection
11,746
public static Builder builder ( Reader reader , String tableName ) { Builder builder = new Builder ( reader ) ; return builder . tableName ( tableName ) ; }
This method may cause tablesaw to buffer the entire InputStream .
11,747
private static int [ ] getWidths ( String [ ] headers , String [ ] [ ] data ) { final int [ ] widths = new int [ headers . length ] ; for ( int j = 0 ; j < headers . length ; j ++ ) { final String header = headers [ j ] ; widths [ j ] = Math . max ( widths [ j ] , header != null ? header . length ( ) : 0 ) ; } for ( String [ ] rowValues : data ) { for ( int j = 0 ; j < rowValues . length ; j ++ ) { final String value = rowValues [ j ] ; widths [ j ] = Math . max ( widths [ j ] , value != null ? value . length ( ) : 0 ) ; } } return widths ; }
Returns the column widths required to print the header and data
11,748
private static String getHeaderTemplate ( int [ ] widths , String [ ] headers ) { return IntStream . range ( 0 , widths . length ) . mapToObj ( i -> { final int width = widths [ i ] ; final int length = headers [ i ] . length ( ) ; final int leading = ( width - length ) / 2 ; final int trailing = width - ( length + leading ) ; final StringBuilder text = new StringBuilder ( ) ; whitespace ( text , leading + 1 ) ; text . append ( "%" ) . append ( i + 1 ) . append ( "$s" ) ; whitespace ( text , trailing ) ; text . append ( " |" ) ; return text . toString ( ) ; } ) . reduce ( ( left , right ) -> left + " " + right ) . orElse ( "" ) ; }
Returns the header template given the widths specified
11,749
private static String getDataTemplate ( int [ ] widths ) { return IntStream . range ( 0 , widths . length ) . mapToObj ( i -> " %" + ( i + 1 ) + "$" + widths [ i ] + "s |" ) . reduce ( ( left , right ) -> left + " " + right ) . orElse ( "" ) ; }
Returns the data template given the widths specified
11,750
private static void whitespace ( StringBuilder text , int length ) { IntStream . range ( 0 , length ) . forEach ( i -> text . append ( " " ) ) ; }
Returns a whitespace string of the length specified
11,751
public void print ( Relation frame ) { try { final String [ ] headers = getHeaderTokens ( frame ) ; final String [ ] [ ] data = getDataTokens ( frame ) ; final int [ ] widths = getWidths ( headers , data ) ; final String dataTemplate = getDataTemplate ( widths ) ; final String headerTemplate = getHeaderTemplate ( widths , headers ) ; final int totalWidth = IntStream . of ( widths ) . map ( w -> w + 5 ) . sum ( ) - 1 ; final int totalHeight = data . length + 1 ; int capacity = totalWidth * totalHeight ; if ( capacity < 0 ) { capacity = 0 ; } final StringBuilder text = new StringBuilder ( capacity ) ; if ( frame . name ( ) != null ) { text . append ( tableName ( frame , totalWidth ) ) . append ( System . lineSeparator ( ) ) ; } final String headerLine = String . format ( headerTemplate , ( Object [ ] ) headers ) ; text . append ( headerLine ) . append ( System . lineSeparator ( ) ) ; for ( int j = 0 ; j < totalWidth ; j ++ ) { text . append ( "-" ) ; } for ( String [ ] row : data ) { final String dataLine = String . format ( dataTemplate , ( Object [ ] ) row ) ; text . append ( System . lineSeparator ( ) ) ; text . append ( dataLine ) ; } final byte [ ] bytes = text . toString ( ) . getBytes ( ) ; this . stream . write ( bytes ) ; this . stream . flush ( ) ; } catch ( IOException ex ) { throw new IllegalStateException ( "Failed to print DataFrame" , ex ) ; } }
Prints the specified DataFrame to the stream bound to this printer
11,752
private String [ ] getHeaderTokens ( Relation frame ) { final int colCount = frame . columnCount ( ) ; final String [ ] header = new String [ colCount ] ; IntStream . range ( 0 , colCount ) . forEach ( colIndex -> { header [ colIndex ] = frame . column ( colIndex ) . name ( ) ; } ) ; return header ; }
Returns the header string tokens for the frame
11,753
private String [ ] [ ] getDataTokens ( Relation frame ) { if ( frame . rowCount ( ) == 0 ) return new String [ 0 ] [ 0 ] ; final int rowCount = Math . min ( maxRows , frame . rowCount ( ) ) ; final boolean truncated = frame . rowCount ( ) > maxRows ; final int colCount = frame . columnCount ( ) ; final String [ ] [ ] data ; if ( truncated ) { data = new String [ rowCount + 1 ] [ colCount ] ; int i ; for ( i = 0 ; i < Math . ceil ( ( double ) rowCount / 2 ) ; i ++ ) { for ( int j = 0 ; j < colCount ; j ++ ) { data [ i ] [ j ] = frame . getString ( i , j ) ; } } for ( int j = 0 ; j < colCount ; j ++ ) { data [ i ] [ j ] = "..." ; } for ( ++ i ; i <= rowCount ; i ++ ) { for ( int j = 0 ; j < colCount ; j ++ ) { data [ i ] [ j ] = frame . getString ( frame . rowCount ( ) - maxRows + i - 1 , j ) ; } } } else { data = new String [ rowCount ] [ colCount ] ; for ( int i = 0 ; i < rowCount ; i ++ ) { for ( int j = 0 ; j < colCount ; j ++ ) { String value = frame . getString ( i , j ) ; data [ i ] [ j ] = value == null ? "" : value ; } } } return data ; }
Returns the 2 - D array of data tokens from the frame specified
11,754
public Table fullOuter ( boolean allowDuplicateColumnNames , Table ... tables ) { Table joined = table ; for ( Table currT : tables ) { joined = fullOuter ( joined , currT , allowDuplicateColumnNames , columnNames ) ; } return joined ; }
Full outer join to the given tables assuming that they have a column of the name we re joining on
11,755
public Table fullOuter ( Table table2 , String col2Name ) { return fullOuter ( table , table2 , false , col2Name ) ; }
Full outer join the joiner to the table2 using the given column for the second table and returns the resulting table
11,756
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) private void withMissingLeftJoin ( Table destination , Table table1 ) { for ( int c = 0 ; c < destination . columnCount ( ) ; c ++ ) { if ( c < table1 . columnCount ( ) ) { Column t1Col = table1 . column ( c ) ; destination . column ( c ) . append ( t1Col ) ; } else { for ( int r1 = 0 ; r1 < table1 . rowCount ( ) ; r1 ++ ) { destination . column ( c ) . appendMissing ( ) ; } } } }
Adds rows to destination for each row in table1 with the columns from table2 added as missing values in each
11,757
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) private void withMissingRightJoin ( Table destination , List < Column < ? > > joinColumns , Table table2 ) { int t2StartCol = destination . columnCount ( ) - table2 . columnCount ( ) ; for ( int c = 0 ; c < destination . columnCount ( ) ; c ++ ) { boolean addedJoinColumns = false ; for ( Column joinColumn : joinColumns ) { if ( destination . column ( c ) . name ( ) . equalsIgnoreCase ( joinColumn . name ( ) ) ) { destination . column ( c ) . append ( joinColumn ) ; addedJoinColumns = true ; } } if ( ! addedJoinColumns ) { if ( c < t2StartCol ) { for ( int r2 = 0 ; r2 < table2 . rowCount ( ) ; r2 ++ ) { destination . column ( c ) . appendMissing ( ) ; } } else { Column t2Col = table2 . column ( c - t2StartCol ) ; destination . column ( c ) . append ( t2Col ) ; } } } }
Adds rows to destination for each row in the joinColumn and table2
11,758
public TeradataQuery < T > qualify ( Predicate predicate ) { predicate = ExpressionUtils . predicate ( SQLOps . QUALIFY , predicate ) ; return queryMixin . addFlag ( new QueryFlag ( QueryFlag . Position . BEFORE_ORDER , predicate ) ) ; }
Adds a qualify expression
11,759
private Path < ? > shorten ( Path < ? > path , boolean outer ) { if ( aliases . containsKey ( path ) ) { return aliases . get ( path ) ; } else if ( path . getMetadata ( ) . isRoot ( ) ) { return path ; } else if ( path . getMetadata ( ) . getParent ( ) . getMetadata ( ) . isRoot ( ) && outer ) { return path ; } else { Class < ? > type = JPAQueryMixin . getElementTypeOrType ( path ) ; Path < ? > parent = shorten ( path . getMetadata ( ) . getParent ( ) , false ) ; Path oldPath = ExpressionUtils . path ( path . getType ( ) , new PathMetadata ( parent , path . getMetadata ( ) . getElement ( ) , path . getMetadata ( ) . getPathType ( ) ) ) ; if ( oldPath . getMetadata ( ) . getParent ( ) . getMetadata ( ) . isRoot ( ) && outer ) { return oldPath ; } else { Path newPath = ExpressionUtils . path ( type , ExpressionUtils . createRootVariable ( oldPath ) ) ; aliases . put ( path , newPath ) ; metadata . addJoin ( JoinType . LEFTJOIN , ExpressionUtils . as ( oldPath , newPath ) ) ; return newPath ; } } }
Shorten the parent path to a length of max 2 elements
11,760
public static Object [ ] subarray ( Object [ ] array , int startIndexInclusive , int endIndexExclusive ) { int newSize = endIndexExclusive - startIndexInclusive ; Class < ? > type = array . getClass ( ) . getComponentType ( ) ; if ( newSize <= 0 ) { return ( Object [ ] ) Array . newInstance ( type , 0 ) ; } Object [ ] subarray = ( Object [ ] ) Array . newInstance ( type , newSize ) ; System . arraycopy ( array , startIndexInclusive , subarray , 0 , newSize ) ; return subarray ; }
originally licensed under ASL 2 . 0
11,761
public Q addFetchGroup ( String fetchGroupName ) { fetchGroups . add ( fetchGroupName ) ; return queryMixin . getSelf ( ) ; }
Add the fetch group to the set of active fetch groups .
11,762
private BooleanClause createBooleanClause ( Query query , Occur occur ) { if ( query instanceof BooleanQuery ) { BooleanClause [ ] clauses = ( ( BooleanQuery ) query ) . getClauses ( ) ; if ( clauses . length == 1 && clauses [ 0 ] . getOccur ( ) . equals ( Occur . MUST_NOT ) ) { return clauses [ 0 ] ; } } return new BooleanClause ( query , occur ) ; }
If the query is a BooleanQuery and it contains a single Occur . MUST_NOT clause it will be returned as is . Otherwise it will be wrapped in a BooleanClause with the given Occur .
11,763
protected String toField ( Path < ? > path ) { PathMetadata md = path . getMetadata ( ) ; if ( md . getPathType ( ) == PathType . COLLECTION_ANY ) { return toField ( md . getParent ( ) ) ; } else { String rv = md . getName ( ) ; if ( md . getParent ( ) != null ) { Path < ? > parent = md . getParent ( ) ; if ( parent . getMetadata ( ) . getPathType ( ) != PathType . VARIABLE ) { rv = toField ( parent ) + "." + rv ; } } return rv ; } }
template method override to customize
11,764
public Q forShare ( boolean fallbackToForUpdate ) { SQLTemplates sqlTemplates = configuration . getTemplates ( ) ; if ( sqlTemplates . isForShareSupported ( ) ) { QueryFlag forShareFlag = sqlTemplates . getForShareFlag ( ) ; return addFlag ( forShareFlag ) ; } if ( fallbackToForUpdate ) { return forUpdate ( ) ; } throw new QueryException ( "Using forShare() is not supported" ) ; }
FOR SHARE causes the rows retrieved by the SELECT statement to be locked as though for update .
11,765
protected void onException ( SQLListenerContextImpl context , Exception e ) { context . setException ( e ) ; listeners . exception ( context ) ; }
Called to make the call back to listeners when an exception happens
11,766
public NumberExpression < Double > area ( ) { if ( area == null ) { area = Expressions . numberOperation ( Double . class , SpatialOps . AREA , mixin ) ; } return area ; }
The area of this Surface as measured in the spatial reference system of this Surface .
11,767
public JTSPointExpression < Point > centroid ( ) { if ( centroid == null ) { centroid = JTSGeometryExpressions . pointOperation ( SpatialOps . CENTROID , mixin ) ; } return centroid ; }
The mathematical centroid for this Surface as a Point . The result is not guaranteed to be on this Surface .
11,768
public JTSPointExpression < Point > pointOnSurface ( ) { if ( pointOnSurface == null ) { pointOnSurface = JTSGeometryExpressions . pointOperation ( SpatialOps . POINT_ON_SURFACE , mixin ) ; } return pointOnSurface ; }
A Point guaranteed to be on this Surface .
11,769
public static Predicate anyOf ( Collection < Predicate > exprs ) { Predicate rv = null ; for ( Predicate b : exprs ) { if ( b != null ) { rv = rv == null ? b : ExpressionUtils . or ( rv , b ) ; } } return rv ; }
Create the union of the given arguments
11,770
public static < D > Expression < D > as ( Expression < D > source , Path < D > alias ) { return operation ( alias . getType ( ) , Ops . ALIAS , source , alias ) ; }
Create an alias expression with the given source and alias
11,771
@ SuppressWarnings ( "unchecked" ) public static Expression < String > likeToRegex ( Expression < String > expr , boolean matchStartAndEnd ) { if ( expr instanceof Constant < ? > ) { final String like = expr . toString ( ) ; final StringBuilder rv = new StringBuilder ( like . length ( ) + 4 ) ; if ( matchStartAndEnd && ! like . startsWith ( "%" ) ) { rv . append ( '^' ) ; } for ( int i = 0 ; i < like . length ( ) ; i ++ ) { char ch = like . charAt ( i ) ; if ( ch == '.' || ch == '*' || ch == '?' ) { rv . append ( '\\' ) ; } else if ( ch == '%' ) { rv . append ( ".*" ) ; continue ; } else if ( ch == '_' ) { rv . append ( '.' ) ; continue ; } rv . append ( ch ) ; } if ( matchStartAndEnd && ! like . endsWith ( "%" ) ) { rv . append ( '$' ) ; } if ( ! like . equals ( rv . toString ( ) ) ) { return ConstantImpl . create ( rv . toString ( ) ) ; } } else if ( expr instanceof Operation < ? > ) { Operation < ? > o = ( Operation < ? > ) expr ; if ( o . getOperator ( ) == Ops . CONCAT ) { Expression < String > lhs = likeToRegex ( ( Expression < String > ) o . getArg ( 0 ) , false ) ; Expression < String > rhs = likeToRegex ( ( Expression < String > ) o . getArg ( 1 ) , false ) ; if ( lhs != o . getArg ( 0 ) || rhs != o . getArg ( 1 ) ) { return operation ( String . class , Ops . CONCAT , lhs , rhs ) ; } } } return expr ; }
Convert the given like pattern to a regex pattern
11,772
@ SuppressWarnings ( "unchecked" ) public static Expression < String > regexToLike ( Expression < String > expr ) { if ( expr instanceof Constant < ? > ) { final String str = expr . toString ( ) ; final StringBuilder rv = new StringBuilder ( str . length ( ) + 2 ) ; boolean escape = false ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { final char ch = str . charAt ( i ) ; if ( ! escape && ch == '.' ) { if ( i < str . length ( ) - 1 && str . charAt ( i + 1 ) == '*' ) { rv . append ( '%' ) ; i ++ ; } else { rv . append ( '_' ) ; } continue ; } else if ( ! escape && ch == '\\' ) { escape = true ; continue ; } else if ( ! escape && ( ch == '[' || ch == ']' || ch == '^' || ch == '.' || ch == '*' ) ) { throw new QueryException ( "'" + str + "' can't be converted to like form" ) ; } else if ( escape && ( ch == 'd' || ch == 'D' || ch == 's' || ch == 'S' || ch == 'w' || ch == 'W' ) ) { throw new QueryException ( "'" + str + "' can't be converted to like form" ) ; } rv . append ( ch ) ; escape = false ; } if ( ! rv . toString ( ) . equals ( str ) ) { return ConstantImpl . create ( rv . toString ( ) ) ; } } else if ( expr instanceof Operation < ? > ) { Operation < ? > o = ( Operation < ? > ) expr ; if ( o . getOperator ( ) == Ops . CONCAT ) { Expression < String > lhs = regexToLike ( ( Expression < String > ) o . getArg ( 0 ) ) ; Expression < String > rhs = regexToLike ( ( Expression < String > ) o . getArg ( 1 ) ) ; if ( lhs != o . getArg ( 0 ) || rhs != o . getArg ( 1 ) ) { return operation ( String . class , Ops . CONCAT , lhs , rhs ) ; } } } return expr ; }
Convert the given expression from regex form to like
11,773
public static ImmutableList < Expression < ? > > distinctList ( Expression < ? > ... args ) { final ImmutableList . Builder < Expression < ? > > builder = ImmutableList . builder ( ) ; final Set < Expression < ? > > set = new HashSet < Expression < ? > > ( args . length ) ; for ( Expression < ? > arg : args ) { if ( set . add ( arg ) ) { builder . add ( arg ) ; } } return builder . build ( ) ; }
Create a distinct list of the given args
11,774
@ SuppressWarnings ( "unchecked" ) public static < T > Expression < T > extract ( Expression < T > expr ) { if ( expr != null ) { final Class < ? > clazz = expr . getClass ( ) ; if ( clazz == PathImpl . class || clazz == PredicateOperation . class || clazz == ConstantImpl . class ) { return expr ; } else { return ( Expression < T > ) expr . accept ( ExtractorVisitor . DEFAULT , null ) ; } } else { return null ; } }
Get the potentially wrapped expression
11,775
public static String createRootVariable ( Path < ? > path , int suffix ) { String variable = path . accept ( ToStringVisitor . DEFAULT , TEMPLATES ) ; return variable + "_" + suffix ; }
Create a new root variable based on the given path and suffix
11,776
public static Expression < ? > toExpression ( Object o ) { if ( o instanceof Expression ) { return ( Expression < ? > ) o ; } else { return ConstantImpl . create ( o ) ; } }
Converts the given object to an Expression
11,777
public static Expression < ? > orderBy ( List < OrderSpecifier < ? > > args ) { return operation ( Object . class , Ops . ORDER , ConstantImpl . create ( args ) ) ; }
Create an expression out of the given order specifiers
11,778
@ SuppressWarnings ( "unchecked" ) public < A > A createAliasForExpr ( Class < A > cl , Expression < ? extends A > expr ) { try { return ( A ) proxyCache . get ( Pair . < Class < ? > , Expression < ? > > of ( cl , expr ) ) ; } catch ( ExecutionException e ) { throw new QueryException ( e ) ; } }
Create an alias instance for the given class and Expression
11,779
public < A > A createAliasForProperty ( Class < A > cl , Expression < ? > path ) { return createProxy ( cl , path ) ; }
Create an alias instance for the given class parent and path
11,780
@ SuppressWarnings ( "unchecked" ) public < A > A createAliasForVariable ( Class < A > cl , String var ) { try { Expression < ? > path = pathCache . get ( Pair . < Class < ? > , String > of ( cl , var ) ) ; return ( A ) proxyCache . get ( Pair . < Class < ? > , Expression < ? > > of ( cl , path ) ) ; } catch ( ExecutionException e ) { throw new QueryException ( e ) ; } }
Create an alias instance for the given class and variable name
11,781
@ SuppressWarnings ( "unchecked" ) protected < A > A createProxy ( Class < A > cl , Expression < ? > path ) { Enhancer enhancer = new Enhancer ( ) ; enhancer . setClassLoader ( AliasFactory . class . getClassLoader ( ) ) ; if ( cl . isInterface ( ) ) { enhancer . setInterfaces ( new Class < ? > [ ] { cl , ManagedObject . class } ) ; } else { enhancer . setSuperclass ( cl ) ; enhancer . setInterfaces ( new Class < ? > [ ] { ManagedObject . class } ) ; } MethodInterceptor handler = new PropertyAccessInvocationHandler ( path , this , pathFactory , typeSystem ) ; enhancer . setCallback ( handler ) ; return ( A ) enhancer . create ( ) ; }
Create a proxy instance for the given class and path
11,782
public < A extends Expression < ? > > A getCurrentAndReset ( ) { A rv = this . getCurrent ( ) ; reset ( ) ; return rv ; }
Get the current thread bound expression and reset it
11,783
public StringExpression stringValue ( ) { if ( stringCast == null ) { stringCast = Expressions . stringOperation ( Ops . STRING_CAST , mixin ) ; } return stringCast ; }
Create a cast to String expression
11,784
public static < K > GroupByBuilder < K > groupBy ( Expression < K > key ) { return new GroupByBuilder < K > ( key ) ; }
Create a new GroupByBuilder for the given key expression
11,785
public static GroupByBuilder < List < ? > > groupBy ( Expression < ? > ... keys ) { return new GroupByBuilder < List < ? > > ( Projections . list ( keys ) ) ; }
Create a new GroupByBuilder for the given key expressions
11,786
public static < E extends Comparable < ? super E > > AbstractGroupExpression < E , E > min ( Expression < E > expression ) { return new GMin < E > ( expression ) ; }
Create a new aggregating min expression
11,787
public static < E extends Number > AbstractGroupExpression < E , E > sum ( Expression < E > expression ) { return new GSum < E > ( expression ) ; }
Create a new aggregating sum expression
11,788
public static < E extends Number > AbstractGroupExpression < E , E > avg ( Expression < E > expression ) { return new GAvg < E > ( expression ) ; }
Create a new aggregating avg expression
11,789
public static < E extends Comparable < ? super E > > AbstractGroupExpression < E , E > max ( Expression < E > expression ) { return new GMax < E > ( expression ) ; }
Create a new aggregating max expression
11,790
public static < K , V > AbstractGroupExpression < Pair < K , V > , SortedMap < K , V > > sortedMap ( Expression < K > key , Expression < V > value , Comparator < ? super K > comparator ) { return GMap . createSorted ( QPair . create ( key , value ) , comparator ) ; }
Create a new aggregating map expression using a backing TreeMap using the given comparator
11,791
@ SuppressWarnings ( "unchecked" ) public Q filter ( Filter filter ) { if ( filters . isEmpty ( ) ) { this . filter = filter ; filters = ImmutableList . of ( filter ) ; } else { this . filter = null ; if ( filters . size ( ) == 1 ) { filters = new ArrayList < Filter > ( ) ; } filters . add ( filter ) ; } return ( Q ) this ; }
Apply the given Lucene filter to the search results
11,792
@ WithBridgeMethods ( value = PostgreSQLQuery . class , castRequired = true ) public C noWait ( ) { QueryFlag noWaitFlag = configuration . getTemplates ( ) . getNoWaitFlag ( ) ; return addFlag ( noWaitFlag ) ; }
With NOWAIT the statement reports an error rather than waiting if a selected row cannot be locked immediately .
11,793
@ WithBridgeMethods ( value = PostgreSQLQuery . class , castRequired = true ) public C distinctOn ( Expression < ? > ... exprs ) { return addFlag ( Position . AFTER_SELECT , Expressions . template ( Object . class , "distinct on({0}) " , ExpressionUtils . list ( Object . class , exprs ) ) ) ; }
adds a DISTINCT ON clause
11,794
public static < T extends Comparable > TimeExpression < T > currentTime ( Class < T > cl ) { return Expressions . timeOperation ( cl , Ops . DateTimeOps . CURRENT_TIME ) ; }
Create an expression representing the current time as a TimeExpression instance
11,795
public NumberExpression < Integer > numGeometries ( ) { if ( numGeometries == null ) { numGeometries = Expressions . numberOperation ( Integer . class , SpatialOps . NUM_GEOMETRIES , mixin ) ; } return numGeometries ; }
Returns the number of geometries in this GeometryCollection .
11,796
public static < T > com . google . common . base . Predicate < T > wrap ( Predicate predicate ) { Path < ? > path = predicate . accept ( PathExtractor . DEFAULT , null ) ; if ( path != null ) { final Evaluator < Boolean > ev = createEvaluator ( path . getRoot ( ) , predicate ) ; return new com . google . common . base . Predicate < T > ( ) { public boolean apply ( T input ) { return ev . evaluate ( input ) ; } } ; } else { throw new IllegalArgumentException ( "No path in " + predicate ) ; } }
Wrap a Querydsl predicate into a Guava predicate
11,797
public static < F , T > Function < F , T > wrap ( Expression < T > projection ) { Path < ? > path = projection . accept ( PathExtractor . DEFAULT , null ) ; if ( path != null ) { final Evaluator < T > ev = createEvaluator ( path . getRoot ( ) , projection ) ; return new Function < F , T > ( ) { public T apply ( F input ) { return ev . evaluate ( input ) ; } } ; } else { throw new IllegalArgumentException ( "No path in " + projection ) ; } }
Wrap a Querydsl expression into a Guava function
11,798
public static BooleanExpression fuzzyLike ( Path < String > path , String value , int maxEdits ) { Term term = new Term ( path . getMetadata ( ) . getName ( ) , value ) ; return new QueryElement ( new FuzzyQuery ( term , maxEdits ) ) ; }
Create a fuzzy query
11,799
public static Class < ? > safeClassForName ( ClassLoader classLoader , String className ) { try { if ( className . startsWith ( "com.sun." ) || className . startsWith ( "com.apple." ) ) { return null ; } else { return Class . forName ( className , true , classLoader ) ; } } catch ( ClassNotFoundException e ) { return null ; } catch ( NoClassDefFoundError e ) { return null ; } }
Get the class for the given className via the given classLoader