idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
144,100 | private void parse ( String header ) { ArrayList < String > list = new ArrayList < String > ( 4 ) ; StringBuilder sb = new StringBuilder ( ) ; int index = 1 ; while ( index < header . length ( ) ) { char c = header . charAt ( index ++ ) ; if ( Character . isDigit ( c ) ) { sb . append ( c ) ; } else { if ( sb . length ( ) != 0 ) { list . add ( sb . toString ( ) ) ; sb . setLength ( 0 ) ; } } } if ( sb . length ( ) != 0 ) { list . add ( sb . toString ( ) ) ; } m_id = list . get ( 0 ) ; m_sequence = Integer . parseInt ( list . get ( 1 ) ) ; m_type = Integer . valueOf ( list . get ( 2 ) ) ; if ( list . size ( ) > 3 ) { m_subtype = Integer . parseInt ( list . get ( 3 ) ) ; } } | Parses values out of the header text . | 226 | 10 |
144,101 | public int getIndexByDate ( Date date ) { int result = - 1 ; int index = 0 ; for ( CostRateTableEntry entry : this ) { if ( DateHelper . compare ( date , entry . getEndDate ( ) ) < 0 ) { result = index ; break ; } ++ index ; } return result ; } | Retrieve the index of the table entry valid for the supplied date . | 69 | 14 |
144,102 | public static final int getInt ( String value ) { return ( value == null || value . length ( ) == 0 ? 0 : Integer . parseInt ( value ) ) ; } | This method retrieves an int value from a String instance . It returns zero by default if a null value or an empty string is supplied . | 37 | 28 |
144,103 | public static final double getDouble ( String value ) { return ( value == null || value . length ( ) == 0 ? 0 : Double . parseDouble ( value ) ) ; } | This method retrieves a double value from a String instance . It returns zero by default if a null value or an empty string is supplied . | 37 | 28 |
144,104 | public static final Integer getInteger ( Number value ) { Integer result = null ; if ( value != null ) { if ( value instanceof Integer ) { result = ( Integer ) value ; } else { result = Integer . valueOf ( ( int ) Math . round ( value . doubleValue ( ) ) ) ; } } return ( result ) ; } | Utility method used to convert an arbitrary Number into an Integer . | 72 | 13 |
144,105 | public static final Integer getInteger ( String value ) { Integer result ; try { result = Integer . valueOf ( Integer . parseInt ( value ) ) ; } catch ( Exception ex ) { result = null ; } return ( result ) ; } | Converts a string representation of an integer into an Integer object . Silently ignores any parse exceptions and returns null . | 50 | 23 |
144,106 | public static final BigInteger getBigInteger ( Number value ) { BigInteger result = null ; if ( value != null ) { if ( value instanceof BigInteger ) { result = ( BigInteger ) value ; } else { result = BigInteger . valueOf ( Math . round ( value . doubleValue ( ) ) ) ; } } return ( result ) ; } | Utility method used to convert a Number into a BigInteger . | 75 | 13 |
144,107 | public static final double round ( double value , double precision ) { precision = Math . pow ( 10 , precision ) ; return Math . round ( value * precision ) / precision ; } | Utility method used to round a double to the given precision . | 37 | 13 |
144,108 | public static final Integer parseInteger ( String value ) { return ( value == null || value . length ( ) == 0 ? null : Integer . valueOf ( Integer . parseInt ( value ) ) ) ; } | Utility method to convert a String to an Integer and handles null values . | 43 | 15 |
144,109 | public static int compare ( Integer n1 , Integer n2 ) { int result ; if ( n1 == null || n2 == null ) { result = ( n1 == null && n2 == null ? 0 : ( n1 == null ? 1 : - 1 ) ) ; } else { result = n1 . compareTo ( n2 ) ; } return ( result ) ; } | Compare two integers accounting for null values . | 80 | 8 |
144,110 | private final Object getObject ( String name ) { if ( m_map . containsKey ( name ) == false ) { throw new IllegalArgumentException ( "Invalid column name " + name ) ; } Object result = m_map . get ( name ) ; return ( result ) ; } | Retrieve a value from the map ensuring that a key exists in the map with the specified name . | 60 | 20 |
144,111 | public int nextToken ( ) throws IOException { int c ; int nextc = - 1 ; boolean quoted = false ; int result = m_next ; if ( m_next != 0 ) { m_next = 0 ; } m_buffer . setLength ( 0 ) ; while ( result == 0 ) { if ( nextc != - 1 ) { c = nextc ; nextc = - 1 ; } else { c = read ( ) ; } switch ( c ) { case TT_EOF : { if ( m_buffer . length ( ) != 0 ) { result = TT_WORD ; m_next = TT_EOF ; } else { result = TT_EOF ; } break ; } case TT_EOL : { int length = m_buffer . length ( ) ; if ( length != 0 && m_buffer . charAt ( length - 1 ) == ' ' ) { -- length ; m_buffer . setLength ( length ) ; } if ( length == 0 ) { result = TT_EOL ; } else { result = TT_WORD ; m_next = TT_EOL ; } break ; } default : { if ( c == m_quote ) { if ( quoted == false && startQuotedIsValid ( m_buffer ) ) { quoted = true ; } else { if ( quoted == false ) { m_buffer . append ( ( char ) c ) ; } else { nextc = read ( ) ; if ( nextc == m_quote ) { m_buffer . append ( ( char ) c ) ; nextc = - 1 ; } else { quoted = false ; } } } } else { if ( c == m_delimiter && quoted == false ) { result = TT_WORD ; } else { m_buffer . append ( ( char ) c ) ; } } } } } m_type = result ; return ( result ) ; } | This method retrieves the next token and returns a constant representing the type of token found . | 402 | 18 |
144,112 | public ResourceAssignmentWorkgroupFields addWorkgroupAssignment ( ) throws MPXJException { if ( m_workgroup != null ) { throw new MPXJException ( MPXJException . MAXIMUM_RECORDS ) ; } m_workgroup = new ResourceAssignmentWorkgroupFields ( ) ; return ( m_workgroup ) ; } | This method allows a resource assignment workgroup fields record to be added to the current resource assignment . A maximum of one of these records can be added to a resource assignment record . | 78 | 35 |
144,113 | public Date getStart ( ) { Date result = ( Date ) getCachedValue ( AssignmentField . START ) ; if ( result == null ) { result = getTask ( ) . getStart ( ) ; } return result ; } | Returns the start of this resource assignment . | 48 | 8 |
144,114 | public Date getFinish ( ) { Date result = ( Date ) getCachedValue ( AssignmentField . FINISH ) ; if ( result == null ) { result = getTask ( ) . getFinish ( ) ; } return result ; } | Returns the finish date for this resource assignment . | 49 | 9 |
144,115 | public List < TimephasedWork > getTimephasedOvertimeWork ( ) { if ( m_timephasedOvertimeWork == null && m_timephasedWork != null && getOvertimeWork ( ) != null ) { double perDayFactor = getRemainingOvertimeWork ( ) . getDuration ( ) / ( getRemainingWork ( ) . getDuration ( ) - getRemainingOvertimeWork ( ) . getDuration ( ) ) ; double totalFactor = getRemainingOvertimeWork ( ) . getDuration ( ) / getRemainingWork ( ) . getDuration ( ) ; perDayFactor = Double . isNaN ( perDayFactor ) ? 0 : perDayFactor ; totalFactor = Double . isNaN ( totalFactor ) ? 0 : totalFactor ; m_timephasedOvertimeWork = new DefaultTimephasedWorkContainer ( m_timephasedWork , perDayFactor , totalFactor ) ; } return m_timephasedOvertimeWork == null ? null : m_timephasedOvertimeWork . getData ( ) ; } | Retrieves the timephased breakdown of the planned overtime work for this resource assignment . | 237 | 18 |
144,116 | public List < TimephasedCost > getTimephasedCost ( ) { if ( m_timephasedCost == null ) { Resource r = getResource ( ) ; ResourceType type = r != null ? r . getType ( ) : ResourceType . WORK ; //for Work and Material resources, we will calculate in the normal way if ( type != ResourceType . COST ) { if ( m_timephasedWork != null && m_timephasedWork . hasData ( ) ) { if ( hasMultipleCostRates ( ) ) { m_timephasedCost = getTimephasedCostMultipleRates ( getTimephasedWork ( ) , getTimephasedOvertimeWork ( ) ) ; } else { m_timephasedCost = getTimephasedCostSingleRate ( getTimephasedWork ( ) , getTimephasedOvertimeWork ( ) ) ; } } } else { m_timephasedCost = getTimephasedCostFixedAmount ( ) ; } } return m_timephasedCost ; } | Retrieves the timephased breakdown of cost . | 223 | 11 |
144,117 | public List < TimephasedCost > getTimephasedActualCost ( ) { if ( m_timephasedActualCost == null ) { Resource r = getResource ( ) ; ResourceType type = r != null ? r . getType ( ) : ResourceType . WORK ; //for Work and Material resources, we will calculate in the normal way if ( type != ResourceType . COST ) { if ( m_timephasedActualWork != null && m_timephasedActualWork . hasData ( ) ) { if ( hasMultipleCostRates ( ) ) { m_timephasedActualCost = getTimephasedCostMultipleRates ( getTimephasedActualWork ( ) , getTimephasedActualOvertimeWork ( ) ) ; } else { m_timephasedActualCost = getTimephasedCostSingleRate ( getTimephasedActualWork ( ) , getTimephasedActualOvertimeWork ( ) ) ; } } } else { m_timephasedActualCost = getTimephasedActualCostFixedAmount ( ) ; } } return m_timephasedActualCost ; } | Retrieves the timephased breakdown of actual cost . | 249 | 12 |
144,118 | private List < TimephasedCost > getTimephasedCostMultipleRates ( List < TimephasedWork > standardWorkList , List < TimephasedWork > overtimeWorkList ) { List < TimephasedWork > standardWorkResult = new LinkedList < TimephasedWork > ( ) ; List < TimephasedWork > overtimeWorkResult = new LinkedList < TimephasedWork > ( ) ; CostRateTable table = getCostRateTable ( ) ; ProjectCalendar calendar = getCalendar ( ) ; Iterator < TimephasedWork > iter = overtimeWorkList . iterator ( ) ; for ( TimephasedWork standardWork : standardWorkList ) { TimephasedWork overtimeWork = iter . hasNext ( ) ? iter . next ( ) : null ; int startIndex = getCostRateTableEntryIndex ( standardWork . getStart ( ) ) ; int finishIndex = getCostRateTableEntryIndex ( standardWork . getFinish ( ) ) ; if ( startIndex == finishIndex ) { standardWorkResult . add ( standardWork ) ; if ( overtimeWork != null ) { overtimeWorkResult . add ( overtimeWork ) ; } } else { standardWorkResult . addAll ( splitWork ( table , calendar , standardWork , startIndex ) ) ; if ( overtimeWork != null ) { overtimeWorkResult . addAll ( splitWork ( table , calendar , overtimeWork , startIndex ) ) ; } } } return getTimephasedCostSingleRate ( standardWorkResult , overtimeWorkResult ) ; } | Generates timephased costs from timephased work where multiple cost rates apply to the assignment . | 320 | 20 |
144,119 | private List < TimephasedCost > getTimephasedCostFixedAmount ( ) { List < TimephasedCost > result = new LinkedList < TimephasedCost > ( ) ; ProjectCalendar cal = getCalendar ( ) ; double remainingCost = getRemainingCost ( ) . doubleValue ( ) ; if ( remainingCost > 0 ) { AccrueType accrueAt = getResource ( ) . getAccrueAt ( ) ; if ( accrueAt == AccrueType . START ) { result . add ( splitCostStart ( cal , remainingCost , getStart ( ) ) ) ; } else if ( accrueAt == AccrueType . END ) { result . add ( splitCostEnd ( cal , remainingCost , getFinish ( ) ) ) ; } else { //for prorated, we have to deal with it differently depending on whether or not //any actual has been entered, since we want to mimic the other timephased data //where planned and actual values do not overlap double numWorkingDays = cal . getWork ( getStart ( ) , getFinish ( ) , TimeUnit . DAYS ) . getDuration ( ) ; double standardAmountPerDay = getCost ( ) . doubleValue ( ) / numWorkingDays ; if ( getActualCost ( ) . intValue ( ) > 0 ) { //need to get three possible blocks of data: one for the possible partial amount //overlap with timephased actual cost; one with all the standard amount days //that happen after the actual cost stops; and one with any remaining //partial day cost amount int numActualDaysUsed = ( int ) Math . ceil ( getActualCost ( ) . doubleValue ( ) / standardAmountPerDay ) ; Date actualWorkFinish = cal . getDate ( getStart ( ) , Duration . getInstance ( numActualDaysUsed , TimeUnit . DAYS ) , false ) ; double partialDayActualAmount = getActualCost ( ) . doubleValue ( ) % standardAmountPerDay ; if ( partialDayActualAmount > 0 ) { double dayAmount = standardAmountPerDay < remainingCost ? standardAmountPerDay - partialDayActualAmount : remainingCost ; result . add ( splitCostEnd ( cal , dayAmount , actualWorkFinish ) ) ; remainingCost -= dayAmount ; } //see if there's anything left to work with if ( remainingCost > 0 ) { //have to split up the amount into standard prorated amount days and whatever is left result . addAll ( splitCostProrated ( cal , remainingCost , standardAmountPerDay , cal . getNextWorkStart ( actualWorkFinish ) ) ) ; } } else { //no actual cost to worry about, so just a standard split from the beginning of the assignment result . addAll ( splitCostProrated ( cal , remainingCost , standardAmountPerDay , getStart ( ) ) ) ; } } } return result ; } | Generates timephased costs from the assignment s cost value . Used for Cost type Resources . | 616 | 19 |
144,120 | private List < TimephasedCost > getTimephasedActualCostFixedAmount ( ) { List < TimephasedCost > result = new LinkedList < TimephasedCost > ( ) ; double actualCost = getActualCost ( ) . doubleValue ( ) ; if ( actualCost > 0 ) { AccrueType accrueAt = getResource ( ) . getAccrueAt ( ) ; if ( accrueAt == AccrueType . START ) { result . add ( splitCostStart ( getCalendar ( ) , actualCost , getActualStart ( ) ) ) ; } else if ( accrueAt == AccrueType . END ) { result . add ( splitCostEnd ( getCalendar ( ) , actualCost , getActualFinish ( ) ) ) ; } else { //for prorated, we have to deal with it differently; have to 'fill up' each //day with the standard amount before going to the next one double numWorkingDays = getCalendar ( ) . getWork ( getStart ( ) , getFinish ( ) , TimeUnit . DAYS ) . getDuration ( ) ; double standardAmountPerDay = getCost ( ) . doubleValue ( ) / numWorkingDays ; result . addAll ( splitCostProrated ( getCalendar ( ) , actualCost , standardAmountPerDay , getActualStart ( ) ) ) ; } } return result ; } | Generates timephased actual costs from the assignment s cost value . Used for Cost type Resources . | 297 | 20 |
144,121 | private List < TimephasedWork > splitWork ( CostRateTable table , ProjectCalendar calendar , TimephasedWork work , int rateIndex ) { List < TimephasedWork > result = new LinkedList < TimephasedWork > ( ) ; work . setTotalAmount ( Duration . getInstance ( 0 , work . getAmountPerDay ( ) . getUnits ( ) ) ) ; while ( true ) { CostRateTableEntry rate = table . get ( rateIndex ) ; Date splitDate = rate . getEndDate ( ) ; if ( splitDate . getTime ( ) >= work . getFinish ( ) . getTime ( ) ) { result . add ( work ) ; break ; } Date currentPeriodEnd = calendar . getPreviousWorkFinish ( splitDate ) ; TimephasedWork currentPeriod = new TimephasedWork ( work ) ; currentPeriod . setFinish ( currentPeriodEnd ) ; result . add ( currentPeriod ) ; Date nextPeriodStart = calendar . getNextWorkStart ( splitDate ) ; work . setStart ( nextPeriodStart ) ; ++ rateIndex ; } return result ; } | Splits timephased work segments in line with cost rates . Note that this is an approximation - where a rate changes during a working day the second rate is used for the whole day . | 241 | 38 |
144,122 | private boolean hasMultipleCostRates ( ) { boolean result = false ; CostRateTable table = getCostRateTable ( ) ; if ( table != null ) { // // We assume here that if there is just one entry in the cost rate // table, this is an open ended rate which covers any work, it won't // have specific dates attached to it. // if ( table . size ( ) > 1 ) { // // If we have multiple rates in the table, see if the same rate // is in force at the start and the end of the aaaignment. // CostRateTableEntry startEntry = table . getEntryByDate ( getStart ( ) ) ; CostRateTableEntry finishEntry = table . getEntryByDate ( getFinish ( ) ) ; result = ( startEntry != finishEntry ) ; } } return result ; } | Used to determine if multiple cost rates apply to this assignment . | 177 | 12 |
144,123 | private CostRateTableEntry getCostRateTableEntry ( Date date ) { CostRateTableEntry result ; CostRateTable table = getCostRateTable ( ) ; if ( table == null ) { Resource resource = getResource ( ) ; result = new CostRateTableEntry ( resource . getStandardRate ( ) , TimeUnit . HOURS , resource . getOvertimeRate ( ) , TimeUnit . HOURS , resource . getCostPerUse ( ) , null ) ; } else { if ( table . size ( ) == 1 ) { result = table . get ( 0 ) ; } else { result = table . getEntryByDate ( date ) ; } } return result ; } | Retrieves the cost rate table entry active on a given date . | 142 | 14 |
144,124 | private int getCostRateTableEntryIndex ( Date date ) { int result = - 1 ; CostRateTable table = getCostRateTable ( ) ; if ( table != null ) { if ( table . size ( ) == 1 ) { result = 0 ; } else { result = table . getIndexByDate ( date ) ; } } return result ; } | Retrieves the index of a cost rate table entry active on a given date . | 74 | 17 |
144,125 | public List < TimephasedWork > getTimephasedBaselineWork ( int index ) { return m_timephasedBaselineWork [ index ] == null ? null : m_timephasedBaselineWork [ index ] . getData ( ) ; } | Retrieve timephased baseline work . Note that index 0 represents Baseline index 1 represents Baseline1 and so on . | 55 | 25 |
144,126 | public List < TimephasedCost > getTimephasedBaselineCost ( int index ) { return m_timephasedBaselineCost [ index ] == null ? null : m_timephasedBaselineCost [ index ] . getData ( ) ; } | Retrieve timephased baseline cost . Note that index 0 represents Baseline index 1 represents Baseline1 and so on . | 55 | 25 |
144,127 | public ProjectCalendar getCalendar ( ) { ProjectCalendar calendar = null ; Resource resource = getResource ( ) ; if ( resource != null ) { calendar = resource . getResourceCalendar ( ) ; } Task task = getTask ( ) ; if ( calendar == null || task . getIgnoreResourceCalendar ( ) ) { calendar = task . getEffectiveCalendar ( ) ; } return calendar ; } | Retrieves the calendar used for this resource assignment . | 86 | 11 |
144,128 | public void setEnterpriseCost ( int index , Number value ) { set ( selectField ( AssignmentFieldLists . ENTERPRISE_COST , index ) , value ) ; } | Set an enterprise cost value . | 38 | 6 |
144,129 | public void setEnterpriseDate ( int index , Date value ) { set ( selectField ( AssignmentFieldLists . ENTERPRISE_DATE , index ) , value ) ; } | Set an enterprise date value . | 38 | 6 |
144,130 | public void setEnterpriseDuration ( int index , Duration value ) { set ( selectField ( AssignmentFieldLists . ENTERPRISE_DURATION , index ) , value ) ; } | Set an enterprise duration value . | 39 | 6 |
144,131 | public void setEnterpriseNumber ( int index , Number value ) { set ( selectField ( AssignmentFieldLists . ENTERPRISE_NUMBER , index ) , value ) ; } | Set an enterprise number value . | 38 | 6 |
144,132 | public void setEnterpriseText ( int index , String value ) { set ( selectField ( AssignmentFieldLists . ENTERPRISE_TEXT , index ) , value ) ; } | Set an enterprise text value . | 37 | 6 |
144,133 | public Number getOvertimeCost ( ) { Number cost = ( Number ) getCachedValue ( AssignmentField . OVERTIME_COST ) ; if ( cost == null ) { Number actual = getActualOvertimeCost ( ) ; Number remaining = getRemainingOvertimeCost ( ) ; if ( actual != null && remaining != null ) { cost = NumberHelper . getDouble ( actual . doubleValue ( ) + remaining . doubleValue ( ) ) ; set ( AssignmentField . OVERTIME_COST , cost ) ; } } return ( cost ) ; } | Returns the overtime cost of this resource assignment . | 122 | 9 |
144,134 | public Number getPercentageWorkComplete ( ) { Number pct = ( Number ) getCachedValue ( AssignmentField . PERCENT_WORK_COMPLETE ) ; if ( pct == null ) { Duration actualWork = getActualWork ( ) ; Duration work = getWork ( ) ; if ( actualWork != null && work != null && work . getDuration ( ) != 0 ) { pct = Double . valueOf ( ( actualWork . getDuration ( ) * 100 ) / work . convertUnits ( actualWork . getUnits ( ) , getParentFile ( ) . getProjectProperties ( ) ) . getDuration ( ) ) ; set ( AssignmentField . PERCENT_WORK_COMPLETE , pct ) ; } } return pct ; } | The % Work Complete field contains the current status of a task expressed as the percentage of the task s work that has been completed . You can enter percent work complete or you can have Microsoft Project calculate it for you based on actual work on the task . | 161 | 50 |
144,135 | public Duration getStartVariance ( ) { Duration variance = ( Duration ) getCachedValue ( AssignmentField . START_VARIANCE ) ; if ( variance == null ) { TimeUnit format = getParentFile ( ) . getProjectProperties ( ) . getDefaultDurationUnits ( ) ; variance = DateHelper . getVariance ( getTask ( ) , getBaselineStart ( ) , getStart ( ) , format ) ; set ( AssignmentField . START_VARIANCE , variance ) ; } return ( variance ) ; } | Calculate the start variance . | 114 | 7 |
144,136 | public Duration getFinishVariance ( ) { Duration variance = ( Duration ) getCachedValue ( AssignmentField . FINISH_VARIANCE ) ; if ( variance == null ) { TimeUnit format = getParentFile ( ) . getProjectProperties ( ) . getDefaultDurationUnits ( ) ; variance = DateHelper . getVariance ( getTask ( ) , getBaselineFinish ( ) , getFinish ( ) , format ) ; set ( AssignmentField . FINISH_VARIANCE , variance ) ; } return ( variance ) ; } | Calculate the finish variance . | 116 | 7 |
144,137 | public int getCostRateTableIndex ( ) { Integer value = ( Integer ) getCachedValue ( AssignmentField . COST_RATE_TABLE ) ; return value == null ? 0 : value . intValue ( ) ; } | Returns the cost rate table index for this assignment . | 48 | 10 |
144,138 | private AssignmentField selectField ( AssignmentField [ ] fields , int index ) { if ( index < 1 || index > fields . length ) { throw new IllegalArgumentException ( index + " is not a valid field index" ) ; } return ( fields [ index - 1 ] ) ; } | Maps a field index to an AssignmentField instance . | 60 | 10 |
144,139 | public void sort ( ChildTaskContainer container ) { // Do we have any tasks? List < Task > tasks = container . getChildTasks ( ) ; if ( ! tasks . isEmpty ( ) ) { for ( Task task : tasks ) { // // Sort child activities // sort ( task ) ; // // Sort Order: // 1. Activities come first // 2. WBS come last // 3. Activities ordered by activity ID // 4. WBS ordered by ID // Collections . sort ( tasks , new Comparator < Task > ( ) { @ Override public int compare ( Task t1 , Task t2 ) { boolean t1IsWbs = m_wbsTasks . contains ( t1 ) ; boolean t2IsWbs = m_wbsTasks . contains ( t2 ) ; // Both are WBS if ( t1IsWbs && t2IsWbs ) { return t1 . getID ( ) . compareTo ( t2 . getID ( ) ) ; } // Both are activities if ( ! t1IsWbs && ! t2IsWbs ) { String activityID1 = ( String ) t1 . getCurrentValue ( m_activityIDField ) ; String activityID2 = ( String ) t2 . getCurrentValue ( m_activityIDField ) ; if ( activityID1 == null || activityID2 == null ) { return ( activityID1 == null && activityID2 == null ? 0 : ( activityID1 == null ? 1 : - 1 ) ) ; } return activityID1 . compareTo ( activityID2 ) ; } // One activity one WBS return t1IsWbs ? 1 : - 1 ; } } ) ; } } } | Recursively sort the supplied child tasks . | 360 | 9 |
144,140 | public void read ( File file , Table table ) throws IOException { //System.out.println("Reading " + file.getName()); InputStream is = null ; try { is = new FileInputStream ( file ) ; read ( is , table ) ; } finally { StreamHelper . closeQuietly ( is ) ; } } | Read the table from the file and populate the supplied Table instance . | 70 | 13 |
144,141 | private void readPage ( byte [ ] buffer , Table table ) { int magicNumber = getShort ( buffer , 0 ) ; if ( magicNumber == 0x4400 ) { //System.out.println(ByteArrayHelper.hexdump(buffer, 0, 6, true, 16, "")); int recordSize = m_definition . getRecordSize ( ) ; RowValidator rowValidator = m_definition . getRowValidator ( ) ; String primaryKeyColumnName = m_definition . getPrimaryKeyColumnName ( ) ; int index = 6 ; while ( index + recordSize <= buffer . length ) { //System.out.println(ByteArrayHelper.hexdump(buffer, index, recordSize, true, 16, "")); int btrieveValue = getShort ( buffer , index ) ; if ( btrieveValue != 0 ) { Map < String , Object > row = new HashMap < String , Object > ( ) ; row . put ( "ROW_VERSION" , Integer . valueOf ( btrieveValue ) ) ; for ( ColumnDefinition column : m_definition . getColumns ( ) ) { Object value = column . read ( index , buffer ) ; //System.out.println(column.getName() + ": " + value); row . put ( column . getName ( ) , value ) ; } if ( rowValidator == null || rowValidator . validRow ( row ) ) { table . addRow ( primaryKeyColumnName , row ) ; } } index += recordSize ; } } } | Reads data from a single page of the database file . | 332 | 12 |
144,142 | private void populateMap ( byte [ ] data , Integer previousItemOffset , Integer previousItemKey , Integer itemOffset ) { if ( previousItemOffset != null ) { int itemSize = itemOffset . intValue ( ) - previousItemOffset . intValue ( ) ; byte [ ] itemData = new byte [ itemSize ] ; System . arraycopy ( data , previousItemOffset . intValue ( ) , itemData , 0 , itemSize ) ; m_map . put ( previousItemKey , itemData ) ; } } | Method used to extract data from the block of properties and insert the key value pair into a map . | 109 | 20 |
144,143 | public void viewDocument ( DocumentEntry entry ) { InputStream is = null ; try { is = new DocumentInputStream ( entry ) ; byte [ ] data = new byte [ is . available ( ) ] ; is . read ( data ) ; m_model . setData ( data ) ; updateTables ( ) ; } catch ( IOException ex ) { throw new RuntimeException ( ex ) ; } finally { StreamHelper . closeQuietly ( is ) ; } } | Command to select a document from the POIFS for viewing . | 98 | 13 |
144,144 | protected void updateTables ( ) { byte [ ] data = m_model . getData ( ) ; int columns = m_model . getColumns ( ) ; int rows = ( data . length / columns ) + 1 ; int offset = m_model . getOffset ( ) ; String [ ] [ ] hexData = new String [ rows ] [ columns ] ; String [ ] [ ] asciiData = new String [ rows ] [ columns ] ; int row = 0 ; int column = 0 ; StringBuilder hexValue = new StringBuilder ( ) ; for ( int index = offset ; index < data . length ; index ++ ) { int value = data [ index ] ; hexValue . setLength ( 0 ) ; hexValue . append ( HEX_DIGITS [ ( value & 0xF0 ) >> 4 ] ) ; hexValue . append ( HEX_DIGITS [ value & 0x0F ] ) ; char c = ( char ) value ; if ( ( c > 200 ) || ( c < 27 ) ) { c = ' ' ; } hexData [ row ] [ column ] = hexValue . toString ( ) ; asciiData [ row ] [ column ] = Character . toString ( c ) ; ++ column ; if ( column == columns ) { column = 0 ; ++ row ; } } String [ ] columnHeadings = new String [ columns ] ; TableModel hexTableModel = new DefaultTableModel ( hexData , columnHeadings ) { @ Override public boolean isCellEditable ( int r , int c ) { return false ; } } ; TableModel asciiTableModel = new DefaultTableModel ( asciiData , columnHeadings ) { @ Override public boolean isCellEditable ( int r , int c ) { return false ; } } ; m_model . setSizeValueLabel ( Integer . toString ( data . length ) ) ; m_model . setHexTableModel ( hexTableModel ) ; m_model . setAsciiTableModel ( asciiTableModel ) ; m_model . setCurrentSelectionIndex ( 0 ) ; m_model . setPreviousSelectionIndex ( 0 ) ; } | Update the content of the tables . | 462 | 7 |
144,145 | public static final FieldType getInstance ( int fieldID ) { FieldType result ; int prefix = fieldID & 0xFFFF0000 ; int index = fieldID & 0x0000FFFF ; switch ( prefix ) { case MPPTaskField . TASK_FIELD_BASE : { result = MPPTaskField . getInstance ( index ) ; if ( result == null ) { result = getPlaceholder ( TaskField . class , index ) ; } break ; } case MPPResourceField . RESOURCE_FIELD_BASE : { result = MPPResourceField . getInstance ( index ) ; if ( result == null ) { result = getPlaceholder ( ResourceField . class , index ) ; } break ; } case MPPAssignmentField . ASSIGNMENT_FIELD_BASE : { result = MPPAssignmentField . getInstance ( index ) ; if ( result == null ) { result = getPlaceholder ( AssignmentField . class , index ) ; } break ; } case MPPConstraintField . CONSTRAINT_FIELD_BASE : { result = MPPConstraintField . getInstance ( index ) ; if ( result == null ) { result = getPlaceholder ( ConstraintField . class , index ) ; } break ; } default : { result = getPlaceholder ( null , index ) ; break ; } } return result ; } | Retrieve a FieldType instance based on an ID value from an MPP9 or MPP12 file . | 292 | 22 |
144,146 | private static FieldType getPlaceholder ( final Class < ? > type , final int fieldID ) { return new FieldType ( ) { @ Override public FieldTypeClass getFieldTypeClass ( ) { return FieldTypeClass . UNKNOWN ; } @ Override public String name ( ) { return "UNKNOWN" ; } @ Override public int getValue ( ) { return fieldID ; } @ Override public String getName ( ) { return "Unknown " + ( type == null ? "" : type . getSimpleName ( ) + "(" + fieldID + ")" ) ; } @ Override public String getName ( Locale locale ) { return getName ( ) ; } @ Override public DataType getDataType ( ) { return null ; } @ Override public FieldType getUnitsType ( ) { return null ; } @ Override public String toString ( ) { return getName ( ) ; } } ; } | Generate a placeholder for an unknown type . | 196 | 9 |
144,147 | public static final boolean valueIsNotDefault ( FieldType type , Object value ) { boolean result = true ; if ( value == null ) { result = false ; } else { DataType dataType = type . getDataType ( ) ; switch ( dataType ) { case BOOLEAN : { result = ( ( Boolean ) value ) . booleanValue ( ) ; break ; } case CURRENCY : case NUMERIC : { result = ! NumberHelper . equals ( ( ( Number ) value ) . doubleValue ( ) , 0.0 , 0.00001 ) ; break ; } case DURATION : { result = ( ( ( Duration ) value ) . getDuration ( ) != 0 ) ; break ; } default : { break ; } } } return result ; } | Determines if this value is the default value for the given field type . | 162 | 16 |
144,148 | public List < ProjectFile > readAll ( InputStream is , boolean linkCrossProjectRelations ) throws MPXJException { try { m_tables = new HashMap < String , List < Row > > ( ) ; m_numberFormat = new DecimalFormat ( ) ; processFile ( is ) ; List < Row > rows = getRows ( "project" , null , null ) ; List < ProjectFile > result = new ArrayList < ProjectFile > ( rows . size ( ) ) ; List < ExternalPredecessorRelation > externalPredecessors = new ArrayList < ExternalPredecessorRelation > ( ) ; for ( Row row : rows ) { setProjectID ( row . getInt ( "proj_id" ) ) ; m_reader = new PrimaveraReader ( m_taskUdfCounters , m_resourceUdfCounters , m_assignmentUdfCounters , m_resourceFields , m_wbsFields , m_taskFields , m_assignmentFields , m_aliases , m_matchPrimaveraWBS ) ; ProjectFile project = m_reader . getProject ( ) ; project . getEventManager ( ) . addProjectListeners ( m_projectListeners ) ; processProjectProperties ( ) ; processUserDefinedFields ( ) ; processCalendars ( ) ; processResources ( ) ; processResourceRates ( ) ; processTasks ( ) ; processPredecessors ( ) ; processAssignments ( ) ; externalPredecessors . addAll ( m_reader . getExternalPredecessors ( ) ) ; m_reader = null ; project . updateStructure ( ) ; result . add ( project ) ; } if ( linkCrossProjectRelations ) { for ( ExternalPredecessorRelation externalRelation : externalPredecessors ) { Task predecessorTask ; // we could aggregate the project task id maps but that's likely more work // than just looping through the projects for ( ProjectFile proj : result ) { predecessorTask = proj . getTaskByUniqueID ( externalRelation . getSourceUniqueID ( ) ) ; if ( predecessorTask != null ) { Relation relation = externalRelation . getTargetTask ( ) . addPredecessor ( predecessorTask , externalRelation . getType ( ) , externalRelation . getLag ( ) ) ; relation . setUniqueID ( externalRelation . getUniqueID ( ) ) ; break ; } } // if predecessorTask not found the external task is outside of the file so ignore } } return result ; } finally { m_reader = null ; m_tables = null ; m_currentTableName = null ; m_currentTable = null ; m_currentFieldNames = null ; m_defaultCurrencyName = null ; m_currencyMap . clear ( ) ; m_numberFormat = null ; m_defaultCurrencyData = null ; } } | This is a convenience method which allows all projects in an XER file to be read in a single pass . | 620 | 22 |
144,149 | private void processFile ( InputStream is ) throws MPXJException { int line = 1 ; try { // // Test the header and extract the separator. If this is successful, // we reset the stream back as far as we can. The design of the // BufferedInputStream class means that we can't get back to character // zero, so the first record we will read will get "RMHDR" rather than // "ERMHDR" in the first field position. // BufferedInputStream bis = new BufferedInputStream ( is ) ; byte [ ] data = new byte [ 6 ] ; data [ 0 ] = ( byte ) bis . read ( ) ; bis . mark ( 1024 ) ; bis . read ( data , 1 , 5 ) ; if ( ! new String ( data ) . equals ( "ERMHDR" ) ) { throw new MPXJException ( MPXJException . INVALID_FILE ) ; } bis . reset ( ) ; InputStreamReader reader = new InputStreamReader ( bis , getCharset ( ) ) ; Tokenizer tk = new ReaderTokenizer ( reader ) ; tk . setDelimiter ( ' ' ) ; List < String > record = new ArrayList < String > ( ) ; while ( tk . getType ( ) != Tokenizer . TT_EOF ) { readRecord ( tk , record ) ; if ( ! record . isEmpty ( ) ) { if ( processRecord ( record ) ) { break ; } } ++ line ; } } catch ( Exception ex ) { throw new MPXJException ( MPXJException . READ_ERROR + " (failed at line " + line + ")" , ex ) ; } } | Reads the XER file table and row structure ready for processing . | 360 | 14 |
144,150 | private Charset getCharset ( ) { Charset result = m_charset ; if ( result == null ) { // We default to CP1252 as this seems to be the most common encoding result = m_encoding == null ? CharsetHelper . CP1252 : Charset . forName ( m_encoding ) ; } return result ; } | Retrieve the Charset used to read the file . | 81 | 12 |
144,151 | private void processProjectID ( ) { if ( m_projectID == null ) { List < Row > rows = getRows ( "project" , null , null ) ; if ( ! rows . isEmpty ( ) ) { Row row = rows . get ( 0 ) ; m_projectID = row . getInteger ( "proj_id" ) ; } } } | If the user has not specified a project ID this method retrieves the ID of the first project in the file . | 79 | 23 |
144,152 | private void processCurrency ( Row row ) { String currencyName = row . getString ( "curr_short_name" ) ; DecimalFormatSymbols symbols = new DecimalFormatSymbols ( ) ; symbols . setDecimalSeparator ( row . getString ( "decimal_symbol" ) . charAt ( 0 ) ) ; symbols . setGroupingSeparator ( row . getString ( "digit_group_symbol" ) . charAt ( 0 ) ) ; DecimalFormat nf = new DecimalFormat ( ) ; nf . setDecimalFormatSymbols ( symbols ) ; nf . applyPattern ( "#.#" ) ; m_currencyMap . put ( currencyName , nf ) ; if ( currencyName . equalsIgnoreCase ( m_defaultCurrencyName ) ) { m_numberFormat = nf ; m_defaultCurrencyData = row ; } } | Process a currency definition . | 198 | 5 |
144,153 | public Map < Integer , String > listProjects ( InputStream is ) throws MPXJException { try { m_tables = new HashMap < String , List < Row > > ( ) ; processFile ( is ) ; Map < Integer , String > result = new HashMap < Integer , String > ( ) ; List < Row > rows = getRows ( "project" , null , null ) ; for ( Row row : rows ) { Integer id = row . getInteger ( "proj_id" ) ; String name = row . getString ( "proj_short_name" ) ; result . put ( id , name ) ; } return result ; } finally { m_tables = null ; m_currentTable = null ; m_currentFieldNames = null ; } } | Populates a Map instance representing the IDs and names of projects available in the current file . | 168 | 18 |
144,154 | private void processScheduleOptions ( ) { List < Row > rows = getRows ( "schedoptions" , "proj_id" , m_projectID ) ; if ( rows . isEmpty ( ) == false ) { Row row = rows . get ( 0 ) ; Map < String , Object > customProperties = new HashMap < String , Object > ( ) ; customProperties . put ( "LagCalendar" , row . getString ( "sched_calendar_on_relationship_lag" ) ) ; customProperties . put ( "RetainedLogic" , Boolean . valueOf ( row . getBoolean ( "sched_retained_logic" ) ) ) ; customProperties . put ( "ProgressOverride" , Boolean . valueOf ( row . getBoolean ( "sched_progress_override" ) ) ) ; customProperties . put ( "IgnoreOtherProjectRelationships" , row . getString ( "sched_outer_depend_type" ) ) ; customProperties . put ( "StartToStartLagCalculationType" , Boolean . valueOf ( row . getBoolean ( "sched_lag_early_start_flag" ) ) ) ; m_reader . getProject ( ) . getProjectProperties ( ) . setCustomProperties ( customProperties ) ; } } | Process schedule options from SCHEDOPTIONS . This table only seems to exist in XER files not P6 databases . | 294 | 25 |
144,155 | private void readRecord ( Tokenizer tk , List < String > record ) throws IOException { record . clear ( ) ; while ( tk . nextToken ( ) == Tokenizer . TT_WORD ) { record . add ( tk . getToken ( ) ) ; } } | Reads each token from a single record and adds it to a list . | 60 | 15 |
144,156 | private boolean processRecord ( List < String > record ) throws MPXJException { boolean done = false ; XerRecordType type = RECORD_TYPE_MAP . get ( record . get ( 0 ) ) ; if ( type == null ) { throw new MPXJException ( MPXJException . INVALID_FORMAT ) ; } switch ( type ) { case HEADER : { processHeader ( record ) ; break ; } case TABLE : { m_currentTableName = record . get ( 1 ) . toLowerCase ( ) ; m_skipTable = ! REQUIRED_TABLES . contains ( m_currentTableName ) ; if ( m_skipTable ) { m_currentTable = null ; } else { m_currentTable = new LinkedList < Row > ( ) ; m_tables . put ( m_currentTableName , m_currentTable ) ; } break ; } case FIELDS : { if ( m_skipTable ) { m_currentFieldNames = null ; } else { m_currentFieldNames = record . toArray ( new String [ record . size ( ) ] ) ; for ( int loop = 0 ; loop < m_currentFieldNames . length ; loop ++ ) { m_currentFieldNames [ loop ] = m_currentFieldNames [ loop ] . toLowerCase ( ) ; } } break ; } case DATA : { if ( ! m_skipTable ) { Map < String , Object > map = new HashMap < String , Object > ( ) ; for ( int loop = 1 ; loop < record . size ( ) ; loop ++ ) { String fieldName = m_currentFieldNames [ loop ] ; String fieldValue = record . get ( loop ) ; XerFieldType fieldType = FIELD_TYPE_MAP . get ( fieldName ) ; if ( fieldType == null ) { fieldType = XerFieldType . STRING ; } Object objectValue ; if ( fieldValue . length ( ) == 0 ) { objectValue = null ; } else { switch ( fieldType ) { case DATE : { try { objectValue = m_df . parseObject ( fieldValue ) ; } catch ( ParseException ex ) { objectValue = fieldValue ; } break ; } case CURRENCY : case DOUBLE : case DURATION : { try { objectValue = Double . valueOf ( m_numberFormat . parse ( fieldValue . trim ( ) ) . doubleValue ( ) ) ; } catch ( ParseException ex ) { objectValue = fieldValue ; } break ; } case INTEGER : { objectValue = Integer . valueOf ( fieldValue . trim ( ) ) ; break ; } default : { objectValue = fieldValue ; break ; } } } map . put ( fieldName , objectValue ) ; } Row currentRow = new MapRow ( map ) ; m_currentTable . add ( currentRow ) ; // // Special case - we need to know the default currency format // ahead of time, so process each row as we get it so that // we can correctly parse currency values in later tables. // if ( m_currentTableName . equals ( "currtype" ) ) { processCurrency ( currentRow ) ; } } break ; } case END : { done = true ; break ; } default : { break ; } } return done ; } | Handles a complete record at a time stores it in a form ready for further processing . | 705 | 18 |
144,157 | private List < Row > getRows ( String tableName , String columnName , Integer id ) { List < Row > result ; List < Row > table = m_tables . get ( tableName ) ; if ( table == null ) { result = Collections . < Row > emptyList ( ) ; } else { if ( columnName == null ) { result = table ; } else { result = new LinkedList < Row > ( ) ; for ( Row row : table ) { if ( NumberHelper . equals ( id , row . getInteger ( columnName ) ) ) { result . add ( row ) ; } } } } return result ; } | Filters a list of rows from the named table . If a column name and a value are supplied then use this to filter the rows . If no column name is supplied then return all rows . | 136 | 39 |
144,158 | protected Object getTypedValue ( int type , byte [ ] value ) { Object result ; switch ( type ) { case 4 : // Date { result = MPPUtility . getTimestamp ( value , 0 ) ; break ; } case 6 : // Duration { TimeUnit units = MPPUtility . getDurationTimeUnits ( MPPUtility . getShort ( value , 4 ) , m_properties . getDefaultDurationUnits ( ) ) ; result = MPPUtility . getAdjustedDuration ( m_properties , MPPUtility . getInt ( value , 0 ) , units ) ; break ; } case 9 : // Cost { result = Double . valueOf ( MPPUtility . getDouble ( value , 0 ) / 100 ) ; break ; } case 15 : // Number { result = Double . valueOf ( MPPUtility . getDouble ( value , 0 ) ) ; break ; } case 36058 : case 21 : // Text { result = MPPUtility . getUnicodeString ( value , 0 ) ; break ; } default : { result = value ; break ; } } return result ; } | Convert raw value as read from the MPP file into a Java type . | 239 | 16 |
144,159 | public void addRow ( String primaryKeyColumnName , Map < String , Object > map ) { Integer rowNumber = Integer . valueOf ( m_rowNumber ++ ) ; map . put ( "ROW_NUMBER" , rowNumber ) ; Object primaryKey = null ; if ( primaryKeyColumnName != null ) { primaryKey = map . get ( primaryKeyColumnName ) ; } if ( primaryKey == null ) { primaryKey = rowNumber ; } MapRow newRow = new MapRow ( map ) ; MapRow oldRow = m_rows . get ( primaryKey ) ; if ( oldRow == null ) { m_rows . put ( primaryKey , newRow ) ; } else { int oldVersion = oldRow . getInteger ( "ROW_VERSION" ) . intValue ( ) ; int newVersion = newRow . getInteger ( "ROW_VERSION" ) . intValue ( ) ; if ( newVersion > oldVersion ) { m_rows . put ( primaryKey , newRow ) ; } } } | Add a row to the table . We have a limited understanding of the way Btrieve handles outdated rows so we use what we think is a version number to try to ensure that we only have the latest rows . | 219 | 43 |
144,160 | public static List < List < RTFEmbeddedObject > > getEmbeddedObjects ( String text ) { List < List < RTFEmbeddedObject >> objects = null ; List < RTFEmbeddedObject > objectData ; int offset = text . indexOf ( OBJDATA ) ; if ( offset != - 1 ) { objects = new LinkedList < List < RTFEmbeddedObject > > ( ) ; while ( offset != - 1 ) { objectData = new LinkedList < RTFEmbeddedObject > ( ) ; objects . add ( objectData ) ; offset = readObjectData ( offset , text , objectData ) ; offset = text . indexOf ( OBJDATA , offset ) ; } } return ( objects ) ; } | This method generates a list of lists . Each list represents the data for an embedded object and contains set set of RTFEmbeddedObject instances that make up the embedded object . This method will return null if there are no embedded objects in the RTF document . | 157 | 52 |
144,161 | private int getInt ( List < byte [ ] > blocks ) { int result ; if ( blocks . isEmpty ( ) == false ) { byte [ ] data = blocks . remove ( 0 ) ; result = MPPUtility . getInt ( data , 0 ) ; } else { result = 0 ; } return ( result ) ; } | Internal method used to retrieve a integer from an embedded data block . | 70 | 13 |
144,162 | private byte [ ] getData ( List < byte [ ] > blocks , int length ) { byte [ ] result ; if ( blocks . isEmpty ( ) == false ) { if ( length < 4 ) { length = 4 ; } result = new byte [ length ] ; int offset = 0 ; byte [ ] data ; while ( offset < length ) { data = blocks . remove ( 0 ) ; System . arraycopy ( data , 0 , result , offset , data . length ) ; offset += data . length ; } } else { result = null ; } return ( result ) ; } | Internal method used to retrieve a byte array from one or more embedded data blocks . Consecutive data blocks may need to be concatenated by this method in order to retrieve the complete set of data . | 121 | 41 |
144,163 | private static int readObjectData ( int offset , String text , List < RTFEmbeddedObject > objects ) { LinkedList < byte [ ] > blocks = new LinkedList < byte [ ] > ( ) ; offset += ( OBJDATA . length ( ) ) ; offset = skipEndOfLine ( text , offset ) ; int length ; int lastOffset = offset ; while ( offset != - 1 ) { length = getBlockLength ( text , offset ) ; lastOffset = readDataBlock ( text , offset , length , blocks ) ; offset = skipEndOfLine ( text , lastOffset ) ; } RTFEmbeddedObject headerObject ; RTFEmbeddedObject dataObject ; while ( blocks . isEmpty ( ) == false ) { headerObject = new RTFEmbeddedObject ( blocks , 2 ) ; objects . add ( headerObject ) ; if ( blocks . isEmpty ( ) == false ) { dataObject = new RTFEmbeddedObject ( blocks , headerObject . getTypeFlag2 ( ) ) ; objects . add ( dataObject ) ; } } return ( lastOffset ) ; } | This method extracts byte arrays from the embedded object data and converts them into RTFEmbeddedObject instances which it then adds to the supplied list . | 231 | 29 |
144,164 | private static int skipEndOfLine ( String text , int offset ) { char c ; boolean finished = false ; while ( finished == false ) { c = text . charAt ( offset ) ; switch ( c ) { case ' ' : // found that OBJDATA could be followed by a space the EOL case ' ' : case ' ' : { ++ offset ; break ; } case ' ' : { offset = - 1 ; finished = true ; break ; } default : { finished = true ; break ; } } } return ( offset ) ; } | This method skips the end - of - line markers in the RTF document . It also indicates if the end of the embedded object has been reached . | 114 | 31 |
144,165 | private static int getBlockLength ( String text , int offset ) { int startIndex = offset ; boolean finished = false ; char c ; while ( finished == false ) { c = text . charAt ( offset ) ; switch ( c ) { case ' ' : case ' ' : case ' ' : { finished = true ; break ; } default : { ++ offset ; break ; } } } int length = offset - startIndex ; return ( length ) ; } | Calculates the length of the next block of RTF data . | 95 | 14 |
144,166 | private static int readDataBlock ( String text , int offset , int length , List < byte [ ] > blocks ) { int bytes = length / 2 ; byte [ ] data = new byte [ bytes ] ; for ( int index = 0 ; index < bytes ; index ++ ) { data [ index ] = ( byte ) Integer . parseInt ( text . substring ( offset , offset + 2 ) , 16 ) ; offset += 2 ; } blocks . add ( data ) ; return ( offset ) ; } | Reads a data block and adds it to the list of blocks . | 104 | 14 |
144,167 | private void readRecord ( byte [ ] buffer , Table table ) { //System.out.println(ByteArrayHelper.hexdump(buffer, true, 16, "")); int deletedFlag = getShort ( buffer , 0 ) ; if ( deletedFlag != 0 ) { Map < String , Object > row = new HashMap < String , Object > ( ) ; for ( ColumnDefinition column : m_definition . getColumns ( ) ) { Object value = column . read ( 0 , buffer ) ; //System.out.println(column.getName() + ": " + value); row . put ( column . getName ( ) , value ) ; } table . addRow ( m_definition . getPrimaryKeyColumnName ( ) , row ) ; } } | Reads a single record from the table . | 162 | 9 |
144,168 | public static final void decodeBuffer ( byte [ ] data , byte encryptionCode ) { for ( int i = 0 ; i < data . length ; i ++ ) { data [ i ] = ( byte ) ( data [ i ] ^ encryptionCode ) ; } } | This method decodes a byte array with the given encryption code using XOR encryption . | 54 | 17 |
144,169 | public static final String decodePassword ( byte [ ] data , byte encryptionCode ) { String result ; if ( data . length < MINIMUM_PASSWORD_DATA_LENGTH ) { result = null ; } else { MPPUtility . decodeBuffer ( data , encryptionCode ) ; StringBuilder buffer = new StringBuilder ( ) ; char c ; for ( int i = 0 ; i < PASSWORD_MASK . length ; i ++ ) { int index = PASSWORD_MASK [ i ] ; c = ( char ) data [ index ] ; if ( c == 0 ) { break ; } buffer . append ( c ) ; } result = buffer . toString ( ) ; } return ( result ) ; } | Decode the password from the given data . Will decode the data block as well . | 153 | 17 |
144,170 | public static final void getByteArray ( byte [ ] data , int offset , int size , byte [ ] buffer , int bufferOffset ) { System . arraycopy ( data , offset , buffer , bufferOffset , size ) ; } | This method extracts a portion of a byte array and writes it into another byte array . | 47 | 17 |
144,171 | public static final long getLong6 ( byte [ ] data , int offset ) { long result = 0 ; int i = offset ; for ( int shiftBy = 0 ; shiftBy < 48 ; shiftBy += 8 ) { result |= ( ( long ) ( data [ i ] & 0xff ) ) << shiftBy ; ++ i ; } return result ; } | This method reads a six byte long from the input array . | 75 | 12 |
144,172 | public static final Date getTime ( byte [ ] data , int offset ) { int time = getShort ( data , offset ) / 10 ; Calendar cal = DateHelper . popCalendar ( EPOCH_DATE ) ; cal . set ( Calendar . HOUR_OF_DAY , ( time / 60 ) ) ; cal . set ( Calendar . MINUTE , ( time % 60 ) ) ; cal . set ( Calendar . SECOND , 0 ) ; cal . set ( Calendar . MILLISECOND , 0 ) ; DateHelper . pushCalendar ( cal ) ; return ( cal . getTime ( ) ) ; } | Reads a time value . The time is represented as tenths of a minute since midnight . | 130 | 19 |
144,173 | public static final Date getTimestamp ( byte [ ] data , int offset ) { Date result ; long days = getShort ( data , offset + 2 ) ; if ( days < 100 ) { // We are seeing some files which have very small values for the number of days. // When the relevant field is shown in MS Project it appears as NA. // We try to mimic this behaviour here. days = 0 ; } if ( days == 0 || days == 65535 ) { result = null ; } else { long time = getShort ( data , offset ) ; if ( time == 65535 ) { time = 0 ; } result = DateHelper . getTimestampFromLong ( ( EPOCH + ( days * DateHelper . MS_PER_DAY ) + ( ( time * DateHelper . MS_PER_MINUTE ) / 10 ) ) ) ; } return ( result ) ; } | Reads a combined date and time value . | 185 | 9 |
144,174 | public static final Date getTimestampFromTenths ( byte [ ] data , int offset ) { long ms = ( ( long ) getInt ( data , offset ) ) * 6000 ; return ( DateHelper . getTimestampFromLong ( EPOCH + ms ) ) ; } | Reads a combined date and time value expressed in tenths of a minute . | 59 | 16 |
144,175 | public static final String getUnicodeString ( byte [ ] data , int offset ) { int length = getUnicodeStringLengthInBytes ( data , offset ) ; return length == 0 ? "" : new String ( data , offset , length , CharsetHelper . UTF16LE ) ; } | Reads a string of two byte characters from the input array . This method assumes that the string finishes either at the end of the array or when char zero is encountered . The value starts at the position specified by the offset parameter . | 63 | 46 |
144,176 | private static final int getUnicodeStringLengthInBytes ( byte [ ] data , int offset ) { int result ; if ( data == null || offset >= data . length ) { result = 0 ; } else { result = data . length - offset ; for ( int loop = offset ; loop < ( data . length - 1 ) ; loop += 2 ) { if ( data [ loop ] == 0 && data [ loop + 1 ] == 0 ) { result = loop - offset ; break ; } } } return result ; } | Determine the length of a nul terminated UTF16LE string in bytes . | 109 | 17 |
144,177 | public static final String getString ( byte [ ] data , int offset ) { StringBuilder buffer = new StringBuilder ( ) ; char c ; for ( int loop = 0 ; offset + loop < data . length ; loop ++ ) { c = ( char ) data [ offset + loop ] ; if ( c == 0 ) { break ; } buffer . append ( c ) ; } return ( buffer . toString ( ) ) ; } | Reads a string of single byte characters from the input array . This method assumes that the string finishes either at the end of the array or when char zero is encountered . Reading begins at the supplied offset into the array . | 89 | 44 |
144,178 | public static final Color getColor ( byte [ ] data , int offset ) { Color result = null ; if ( getByte ( data , offset + 3 ) == 0 ) { int r = getByte ( data , offset ) ; int g = getByte ( data , offset + 1 ) ; int b = getByte ( data , offset + 2 ) ; result = new Color ( r , g , b ) ; } return result ; } | Reads a color value represented by three bytes for R G and B components plus a flag byte indicating if this is an automatic color . Returns null if the color type is Automatic . | 90 | 36 |
144,179 | public static final String removeAmpersands ( String name ) { if ( name != null ) { if ( name . indexOf ( ' ' ) != - 1 ) { StringBuilder sb = new StringBuilder ( ) ; int index = 0 ; char c ; while ( index < name . length ( ) ) { c = name . charAt ( index ) ; if ( c != ' ' ) { sb . append ( c ) ; } ++ index ; } name = sb . toString ( ) ; } } return ( name ) ; } | Utility method to remove ampersands embedded in names . | 115 | 12 |
144,180 | public static final Double getPercentage ( byte [ ] data , int offset ) { int value = MPPUtility . getShort ( data , offset ) ; Double result = null ; if ( value >= 0 && value <= 100 ) { result = NumberHelper . getDouble ( value ) ; } return result ; } | Utility method to read a percentage value . | 65 | 9 |
144,181 | public static final byte [ ] cloneSubArray ( byte [ ] data , int offset , int size ) { byte [ ] newData = new byte [ size ] ; System . arraycopy ( data , offset , newData , 0 , size ) ; return ( newData ) ; } | This method allows a subsection of a byte array to be copied . | 58 | 13 |
144,182 | public static void dumpBlockData ( int headerSize , int blockSize , byte [ ] data ) { if ( data != null ) { System . out . println ( ByteArrayHelper . hexdump ( data , 0 , headerSize , false ) ) ; int index = headerSize ; while ( index < data . length ) { System . out . println ( ByteArrayHelper . hexdump ( data , index , blockSize , false ) ) ; index += blockSize ; } } } | Dumps the contents of a structured block made up from a header and fixed sized records . | 99 | 18 |
144,183 | @ Deprecated public Duration getDuration ( Date startDate , Date endDate ) throws MPXJException { return ( getDuration ( "Standard" , startDate , endDate ) ) ; } | This method is used to calculate the duration of work between two fixed dates according to the work schedule defined in the named calendar . The calendar used is the Standard calendar . If this calendar does not exist and exception will be thrown . | 40 | 45 |
144,184 | @ Deprecated public Duration getDuration ( String calendarName , Date startDate , Date endDate ) throws MPXJException { ProjectCalendar calendar = getCalendarByName ( calendarName ) ; if ( calendar == null ) { throw new MPXJException ( MPXJException . CALENDAR_ERROR + ": " + calendarName ) ; } return ( calendar . getDuration ( startDate , endDate ) ) ; } | This method is used to calculate the duration of work between two fixed dates according to the work schedule defined in the named calendar . The name of the calendar to be used is passed as an argument . | 91 | 39 |
144,185 | public Date getStartDate ( ) { Date startDate = null ; for ( Task task : m_tasks ) { // // If a hidden "summary" task is present we ignore it // if ( NumberHelper . getInt ( task . getUniqueID ( ) ) == 0 ) { continue ; } // // Select the actual or forecast start date. Note that the // behaviour is different for milestones. The milestone end date // is always correct, the milestone start date may be different // to reflect a missed deadline. // Date taskStartDate ; if ( task . getMilestone ( ) == true ) { taskStartDate = task . getActualFinish ( ) ; if ( taskStartDate == null ) { taskStartDate = task . getFinish ( ) ; } } else { taskStartDate = task . getActualStart ( ) ; if ( taskStartDate == null ) { taskStartDate = task . getStart ( ) ; } } if ( taskStartDate != null ) { if ( startDate == null ) { startDate = taskStartDate ; } else { if ( taskStartDate . getTime ( ) < startDate . getTime ( ) ) { startDate = taskStartDate ; } } } } return ( startDate ) ; } | Find the earliest task start date . We treat this as the start date for the project . | 262 | 18 |
144,186 | public Date getFinishDate ( ) { Date finishDate = null ; for ( Task task : m_tasks ) { // // If a hidden "summary" task is present we ignore it // if ( NumberHelper . getInt ( task . getUniqueID ( ) ) == 0 ) { continue ; } // // Select the actual or forecast start date // Date taskFinishDate ; taskFinishDate = task . getActualFinish ( ) ; if ( taskFinishDate == null ) { taskFinishDate = task . getFinish ( ) ; } if ( taskFinishDate != null ) { if ( finishDate == null ) { finishDate = taskFinishDate ; } else { if ( taskFinishDate . getTime ( ) > finishDate . getTime ( ) ) { finishDate = taskFinishDate ; } } } } return ( finishDate ) ; } | Find the latest task finish date . We treat this as the finish date for the project . | 177 | 18 |
144,187 | public ProjectCalendar getDefaultCalendar ( ) { String calendarName = m_properties . getDefaultCalendarName ( ) ; ProjectCalendar calendar = getCalendarByName ( calendarName ) ; if ( calendar == null ) { if ( m_calendars . isEmpty ( ) ) { calendar = addDefaultBaseCalendar ( ) ; } else { calendar = m_calendars . get ( 0 ) ; } } return calendar ; } | Retrieves the default calendar for this project based on the calendar name given in the project properties . If a calendar of this name cannot be found then the first calendar listed for the project will be returned . If the project contains no calendars then a default calendar is added . | 93 | 54 |
144,188 | public ProjectCalendar getBaselineCalendar ( ) { // // Attempt to locate the calendar normally used by baselines // If this isn't present, fall back to using the default // project calendar. // ProjectCalendar result = getCalendarByName ( "Used for Microsoft Project 98 Baseline Calendar" ) ; if ( result == null ) { result = getDefaultCalendar ( ) ; } return result ; } | Retrieve the calendar used internally for timephased baseline calculation . | 86 | 13 |
144,189 | public void process ( CustomFieldContainer indicators , ProjectProperties properties , Props props ) { m_container = indicators ; m_properties = properties ; m_data = props . getByteArray ( Props . TASK_FIELD_ATTRIBUTES ) ; if ( m_data != null ) { int columnsCount = MPPUtility . getInt ( m_data , 4 ) ; m_headerOffset = 8 ; for ( int loop = 0 ; loop < columnsCount ; loop ++ ) { processColumns ( ) ; } } } | The main entry point for processing graphical indicator definitions . | 117 | 10 |
144,190 | private void processColumns ( ) { int fieldID = MPPUtility . getInt ( m_data , m_headerOffset ) ; m_headerOffset += 4 ; m_dataOffset = MPPUtility . getInt ( m_data , m_headerOffset ) ; m_headerOffset += 4 ; FieldType type = FieldTypeHelper . getInstance ( fieldID ) ; if ( type . getDataType ( ) != null ) { processKnownType ( type ) ; } } | Processes graphical indicator definitions for each column . | 104 | 9 |
144,191 | private void processKnownType ( FieldType type ) { //System.out.println("Header: " + type); //System.out.println(ByteArrayHelper.hexdump(m_data, m_dataOffset, 36, false, 16, "")); GraphicalIndicator indicator = m_container . getCustomField ( type ) . getGraphicalIndicator ( ) ; indicator . setFieldType ( type ) ; int flags = m_data [ m_dataOffset ] ; indicator . setProjectSummaryInheritsFromSummaryRows ( ( flags & 0x08 ) != 0 ) ; indicator . setSummaryRowsInheritFromNonSummaryRows ( ( flags & 0x04 ) != 0 ) ; indicator . setDisplayGraphicalIndicators ( ( flags & 0x02 ) != 0 ) ; indicator . setShowDataValuesInToolTips ( ( flags & 0x01 ) != 0 ) ; m_dataOffset += 20 ; int nonSummaryRowOffset = MPPUtility . getInt ( m_data , m_dataOffset ) - 36 ; m_dataOffset += 4 ; int summaryRowOffset = MPPUtility . getInt ( m_data , m_dataOffset ) - 36 ; m_dataOffset += 4 ; int projectSummaryOffset = MPPUtility . getInt ( m_data , m_dataOffset ) - 36 ; m_dataOffset += 4 ; int dataSize = MPPUtility . getInt ( m_data , m_dataOffset ) - 36 ; m_dataOffset += 4 ; //System.out.println("Data"); //System.out.println(ByteArrayHelper.hexdump(m_data, m_dataOffset, dataSize, false, 16, "")); int maxNonSummaryRowOffset = m_dataOffset + summaryRowOffset ; int maxSummaryRowOffset = m_dataOffset + projectSummaryOffset ; int maxProjectSummaryOffset = m_dataOffset + dataSize ; m_dataOffset += nonSummaryRowOffset ; while ( m_dataOffset + 2 < maxNonSummaryRowOffset ) { indicator . addNonSummaryRowCriteria ( processCriteria ( type ) ) ; } while ( m_dataOffset + 2 < maxSummaryRowOffset ) { indicator . addSummaryRowCriteria ( processCriteria ( type ) ) ; } while ( m_dataOffset + 2 < maxProjectSummaryOffset ) { indicator . addProjectSummaryCriteria ( processCriteria ( type ) ) ; } } | Process a graphical indicator definition for a known type . | 527 | 10 |
144,192 | private GraphicalIndicatorCriteria processCriteria ( FieldType type ) { GraphicalIndicatorCriteria criteria = new GraphicalIndicatorCriteria ( m_properties ) ; criteria . setLeftValue ( type ) ; int indicatorType = MPPUtility . getInt ( m_data , m_dataOffset ) ; m_dataOffset += 4 ; criteria . setIndicator ( indicatorType ) ; if ( m_dataOffset + 4 < m_data . length ) { int operatorValue = MPPUtility . getInt ( m_data , m_dataOffset ) ; m_dataOffset += 4 ; TestOperator operator = ( operatorValue == 0 ? TestOperator . IS_ANY_VALUE : TestOperator . getInstance ( operatorValue - 0x3E7 ) ) ; criteria . setOperator ( operator ) ; if ( operator != TestOperator . IS_ANY_VALUE ) { processOperandValue ( 0 , type , criteria ) ; if ( operator == TestOperator . IS_WITHIN || operator == TestOperator . IS_NOT_WITHIN ) { processOperandValue ( 1 , type , criteria ) ; } } } return ( criteria ) ; } | Process the graphical indicator criteria for a single column . | 255 | 10 |
144,193 | private void processOperandValue ( int index , FieldType type , GraphicalIndicatorCriteria criteria ) { boolean valueFlag = ( MPPUtility . getInt ( m_data , m_dataOffset ) == 1 ) ; m_dataOffset += 4 ; if ( valueFlag == false ) { int fieldID = MPPUtility . getInt ( m_data , m_dataOffset ) ; criteria . setRightValue ( index , FieldTypeHelper . getInstance ( fieldID ) ) ; m_dataOffset += 4 ; } else { //int dataTypeValue = MPPUtility.getShort(m_data, m_dataOffset); m_dataOffset += 2 ; switch ( type . getDataType ( ) ) { case DURATION : // 0x03 { Duration value = MPPUtility . getAdjustedDuration ( m_properties , MPPUtility . getInt ( m_data , m_dataOffset ) , MPPUtility . getDurationTimeUnits ( MPPUtility . getShort ( m_data , m_dataOffset + 4 ) ) ) ; m_dataOffset += 6 ; criteria . setRightValue ( index , value ) ; break ; } case NUMERIC : // 0x05 { Double value = Double . valueOf ( MPPUtility . getDouble ( m_data , m_dataOffset ) ) ; m_dataOffset += 8 ; criteria . setRightValue ( index , value ) ; break ; } case CURRENCY : // 0x06 { Double value = Double . valueOf ( MPPUtility . getDouble ( m_data , m_dataOffset ) / 100 ) ; m_dataOffset += 8 ; criteria . setRightValue ( index , value ) ; break ; } case STRING : // 0x08 { String value = MPPUtility . getUnicodeString ( m_data , m_dataOffset ) ; m_dataOffset += ( ( value . length ( ) + 1 ) * 2 ) ; criteria . setRightValue ( index , value ) ; break ; } case BOOLEAN : // 0x0B { int value = MPPUtility . getShort ( m_data , m_dataOffset ) ; m_dataOffset += 2 ; criteria . setRightValue ( index , value == 1 ? Boolean . TRUE : Boolean . FALSE ) ; break ; } case DATE : // 0x13 { Date value = MPPUtility . getTimestamp ( m_data , m_dataOffset ) ; m_dataOffset += 4 ; criteria . setRightValue ( index , value ) ; break ; } default : { break ; } } } } | Process an operand value used in the definition of the graphical indicator criteria . | 565 | 15 |
144,194 | private GridLines getGridLines ( byte [ ] data , int offset ) { Color normalLineColor = ColorType . getInstance ( data [ offset ] ) . getColor ( ) ; LineStyle normalLineStyle = LineStyle . getInstance ( data [ offset + 3 ] ) ; int intervalNumber = data [ offset + 4 ] ; LineStyle intervalLineStyle = LineStyle . getInstance ( data [ offset + 5 ] ) ; Color intervalLineColor = ColorType . getInstance ( data [ offset + 6 ] ) . getColor ( ) ; return new GridLines ( normalLineColor , normalLineStyle , intervalNumber , intervalLineStyle , intervalLineColor ) ; } | Creates a new GridLines instance . | 142 | 9 |
144,195 | public byte [ ] getByteArray ( Integer offset ) { byte [ ] result = null ; if ( offset != null ) { result = m_map . get ( offset ) ; } return ( result ) ; } | This method retrieves a byte array containing the data at the given offset in the block . If no data is found at the given offset this method returns null . | 44 | 32 |
144,196 | public byte [ ] getByteArray ( Integer id , Integer type ) { return ( getByteArray ( m_meta . getOffset ( id , type ) ) ) ; } | This method retrieves a byte array of the specified type belonging to the item with the specified unique ID . | 36 | 21 |
144,197 | public String getUnicodeString ( Integer id , Integer type ) { return ( getUnicodeString ( m_meta . getOffset ( id , type ) ) ) ; } | This method retrieves a String of the specified type belonging to the item with the specified unique ID . | 38 | 20 |
144,198 | public String getString ( Integer offset ) { String result = null ; if ( offset != null ) { byte [ ] value = m_map . get ( offset ) ; if ( value != null ) { result = MPPUtility . getString ( value , 0 ) ; } } return ( result ) ; } | This method retrieves the data at the given offset and returns it as a String assuming the underlying data is composed of single byte characters . | 65 | 27 |
144,199 | public String getString ( Integer id , Integer type ) { return ( getString ( m_meta . getOffset ( id , type ) ) ) ; } | This method retrieves a string of the specified type belonging to the item with the specified unique ID . | 32 | 20 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.