idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
144,200
public int getShort ( Integer id , Integer type ) { int result = 0 ; Integer offset = m_meta . getOffset ( id , type ) ; if ( offset != null ) { byte [ ] value = m_map . get ( offset ) ; if ( value != null && value . length >= 2 ) { result = MPPUtility . getShort ( value , 0 ) ; } } return ( result ) ; }
This method retrieves an integer of the specified type belonging to the item with the specified unique ID .
89
20
144,201
public double getDouble ( Integer id , Integer type ) { double result = Double . longBitsToDouble ( getLong ( id , type ) ) ; if ( Double . isNaN ( result ) ) { result = 0 ; } return result ; }
This method retrieves a double of the specified type belonging to the item with the specified unique ID .
53
20
144,202
public DateRange getRange ( int index ) { DateRange result ; if ( index >= 0 && index < m_ranges . size ( ) ) { result = m_ranges . get ( index ) ; } else { result = DateRange . EMPTY_RANGE ; } return ( result ) ; }
Retrieve the date range at the specified index . The index is zero based and this method will return null if the requested date range does not exist .
65
30
144,203
public GenericCriteria process ( ProjectProperties properties , byte [ ] data , int dataOffset , int entryOffset , List < GenericCriteriaPrompt > prompts , List < FieldType > fields , boolean [ ] criteriaType ) { m_properties = properties ; m_prompts = prompts ; m_fields = fields ; m_criteriaType = criteriaType ; m_dataOffset = dataOffset ; if ( m_criteriaType != null ) { m_criteriaType [ 0 ] = true ; m_criteriaType [ 1 ] = true ; } m_criteriaBlockMap . clear ( ) ; m_criteriaData = data ; m_criteriaTextStart = MPPUtility . getShort ( m_criteriaData , m_dataOffset + getCriteriaTextStartOffset ( ) ) ; // // Populate the map // int criteriaStartOffset = getCriteriaStartOffset ( ) ; int criteriaBlockSize = getCriteriaBlockSize ( ) ; //System.out.println(); //System.out.println(ByteArrayHelper.hexdump(data, dataOffset, criteriaStartOffset, false)); if ( m_criteriaData . length <= m_criteriaTextStart ) { return null ; // bad data } while ( criteriaStartOffset + criteriaBlockSize <= m_criteriaTextStart ) { byte [ ] block = new byte [ criteriaBlockSize ] ; System . arraycopy ( m_criteriaData , m_dataOffset + criteriaStartOffset , block , 0 , criteriaBlockSize ) ; m_criteriaBlockMap . put ( Integer . valueOf ( criteriaStartOffset ) , block ) ; //System.out.println(Integer.toHexString(criteriaStartOffset) + ": " + ByteArrayHelper.hexdump(block, false)); criteriaStartOffset += criteriaBlockSize ; } if ( entryOffset == - 1 ) { entryOffset = getCriteriaStartOffset ( ) ; } List < GenericCriteria > list = new LinkedList < GenericCriteria > ( ) ; processBlock ( list , m_criteriaBlockMap . get ( Integer . valueOf ( entryOffset ) ) ) ; GenericCriteria criteria ; if ( list . isEmpty ( ) ) { criteria = null ; } else { criteria = list . get ( 0 ) ; } return criteria ; }
Main entry point to read criteria data .
494
8
144,204
private void processBlock ( List < GenericCriteria > list , byte [ ] block ) { if ( block != null ) { if ( MPPUtility . getShort ( block , 0 ) > 0x3E6 ) { addCriteria ( list , block ) ; } else { switch ( block [ 0 ] ) { case ( byte ) 0x0B : { processBlock ( list , getChildBlock ( block ) ) ; break ; } case ( byte ) 0x06 : { processBlock ( list , getListNextBlock ( block ) ) ; break ; } case ( byte ) 0xED : // EQUALS { addCriteria ( list , block ) ; break ; } case ( byte ) 0x19 : // AND case ( byte ) 0x1B : { addBlock ( list , block , TestOperator . AND ) ; break ; } case ( byte ) 0x1A : // OR case ( byte ) 0x1C : { addBlock ( list , block , TestOperator . OR ) ; break ; } } } } }
Process a single criteria block .
223
6
144,205
private void addCriteria ( List < GenericCriteria > list , byte [ ] block ) { byte [ ] leftBlock = getChildBlock ( block ) ; byte [ ] rightBlock1 = getListNextBlock ( leftBlock ) ; byte [ ] rightBlock2 = getListNextBlock ( rightBlock1 ) ; TestOperator operator = TestOperator . getInstance ( MPPUtility . getShort ( block , 0 ) - 0x3E7 ) ; FieldType leftValue = getFieldType ( leftBlock ) ; Object rightValue1 = getValue ( leftValue , rightBlock1 ) ; Object rightValue2 = rightBlock2 == null ? null : getValue ( leftValue , rightBlock2 ) ; GenericCriteria criteria = new GenericCriteria ( m_properties ) ; criteria . setLeftValue ( leftValue ) ; criteria . setOperator ( operator ) ; criteria . setRightValue ( 0 , rightValue1 ) ; criteria . setRightValue ( 1 , rightValue2 ) ; list . add ( criteria ) ; if ( m_criteriaType != null ) { m_criteriaType [ 0 ] = leftValue . getFieldTypeClass ( ) == FieldTypeClass . TASK ; m_criteriaType [ 1 ] = ! m_criteriaType [ 0 ] ; } if ( m_fields != null ) { m_fields . add ( leftValue ) ; } processBlock ( list , getListNextBlock ( block ) ) ; }
Adds a basic LHS OPERATOR RHS block .
311
11
144,206
private void addBlock ( List < GenericCriteria > list , byte [ ] block , TestOperator operator ) { GenericCriteria result = new GenericCriteria ( m_properties ) ; result . setOperator ( operator ) ; list . add ( result ) ; processBlock ( result . getCriteriaList ( ) , getChildBlock ( block ) ) ; processBlock ( list , getListNextBlock ( block ) ) ; }
Adds a logical operator block .
90
6
144,207
private Object getValue ( FieldType field , byte [ ] block ) { Object result = null ; switch ( block [ 0 ] ) { case 0x07 : // Field { result = getFieldType ( block ) ; break ; } case 0x01 : // Constant value { result = getConstantValue ( field , block ) ; break ; } case 0x00 : // Prompt { result = getPromptValue ( field , block ) ; break ; } } return result ; }
Retrieves the value component of a criteria expression .
100
11
144,208
private Object getConstantValue ( FieldType type , byte [ ] block ) { Object value ; DataType dataType = type . getDataType ( ) ; if ( dataType == null ) { value = null ; } else { switch ( dataType ) { case DURATION : { value = MPPUtility . getAdjustedDuration ( m_properties , MPPUtility . getInt ( block , getValueOffset ( ) ) , MPPUtility . getDurationTimeUnits ( MPPUtility . getShort ( block , getTimeUnitsOffset ( ) ) ) ) ; break ; } case NUMERIC : { value = Double . valueOf ( MPPUtility . getDouble ( block , getValueOffset ( ) ) ) ; break ; } case PERCENTAGE : { value = Double . valueOf ( MPPUtility . getShort ( block , getValueOffset ( ) ) ) ; break ; } case CURRENCY : { value = Double . valueOf ( MPPUtility . getDouble ( block , getValueOffset ( ) ) / 100 ) ; break ; } case STRING : { int textOffset = getTextOffset ( block ) ; value = MPPUtility . getUnicodeString ( m_criteriaData , m_dataOffset + m_criteriaTextStart + textOffset ) ; break ; } case BOOLEAN : { int intValue = MPPUtility . getShort ( block , getValueOffset ( ) ) ; value = ( intValue == 1 ? Boolean . TRUE : Boolean . FALSE ) ; break ; } case DATE : { value = MPPUtility . getTimestamp ( block , getValueOffset ( ) ) ; break ; } default : { value = null ; break ; } } } return value ; }
Retrieves a constant value .
378
7
144,209
private GenericCriteriaPrompt getPromptValue ( FieldType field , byte [ ] block ) { int textOffset = getPromptOffset ( block ) ; String value = MPPUtility . getUnicodeString ( m_criteriaData , m_criteriaTextStart + textOffset ) ; GenericCriteriaPrompt prompt = new GenericCriteriaPrompt ( field . getDataType ( ) , value ) ; if ( m_prompts != null ) { m_prompts . add ( prompt ) ; } return prompt ; }
Retrieves a prompt value .
116
7
144,210
private RelationType getRelationType ( int type ) { RelationType result ; if ( type > 0 && type < RELATION_TYPES . length ) { result = RELATION_TYPES [ type ] ; } else { result = RelationType . FINISH_START ; } return result ; }
Convert an integer to a RelationType instance .
68
11
144,211
public byte [ ] getByteArrayValue ( int index ) { byte [ ] result = null ; if ( m_array [ index ] != null ) { result = ( byte [ ] ) m_array [ index ] ; } return ( result ) ; }
This method retrieves a byte array containing the data at the given index in the block . If no data is found at the given index this method returns null .
53
32
144,212
public byte getByte ( Integer type ) { byte result = 0 ; byte [ ] item = m_map . get ( type ) ; if ( item != null ) { result = item [ 0 ] ; } return ( result ) ; }
Retrieves a byte value from the property data .
49
11
144,213
public Date getTime ( Integer type ) { Date result = null ; byte [ ] item = m_map . get ( type ) ; if ( item != null ) { result = MPPUtility . getTime ( item , 0 ) ; } return ( result ) ; }
Retrieves a timestamp from the property data .
57
10
144,214
public String getUnicodeString ( Integer type ) { String result = null ; byte [ ] item = m_map . get ( type ) ; if ( item != null ) { result = MPPUtility . getUnicodeString ( item , 0 ) ; } return ( result ) ; }
Retrieves a string value from the property data .
63
11
144,215
public void writeStartObject ( String name ) throws IOException { writeComma ( ) ; writeNewLineIndent ( ) ; if ( name != null ) { writeName ( name ) ; writeNewLineIndent ( ) ; } m_writer . write ( "{" ) ; increaseIndent ( ) ; }
Begin writing a named object attribute .
66
7
144,216
public void writeStartList ( String name ) throws IOException { writeComma ( ) ; writeNewLineIndent ( ) ; writeName ( name ) ; writeNewLineIndent ( ) ; m_writer . write ( "[" ) ; increaseIndent ( ) ; }
Begin writing a named list attribute .
58
7
144,217
public void writeNameValuePair ( String name , String value ) throws IOException { internalWriteNameValuePair ( name , escapeString ( value ) ) ; }
Write a string attribute .
35
5
144,218
public void writeNameValuePair ( String name , int value ) throws IOException { internalWriteNameValuePair ( name , Integer . toString ( value ) ) ; }
Write an int attribute .
37
5
144,219
public void writeNameValuePair ( String name , long value ) throws IOException { internalWriteNameValuePair ( name , Long . toString ( value ) ) ; }
Write a long attribute .
37
5
144,220
public void writeNameValuePair ( String name , double value ) throws IOException { internalWriteNameValuePair ( name , Double . toString ( value ) ) ; }
Write a double attribute .
37
5
144,221
public void writeNameValuePair ( String name , Date value ) throws IOException { internalWriteNameValuePair ( name , m_format . format ( value ) ) ; }
Write a Date attribute .
38
5
144,222
private void internalWriteNameValuePair ( String name , String value ) throws IOException { writeComma ( ) ; writeNewLineIndent ( ) ; writeName ( name ) ; if ( m_pretty ) { m_writer . write ( ' ' ) ; } m_writer . write ( value ) ; }
Core write attribute implementation .
67
5
144,223
private String escapeString ( String value ) { m_buffer . setLength ( 0 ) ; m_buffer . append ( ' ' ) ; for ( int index = 0 ; index < value . length ( ) ; index ++ ) { char c = value . charAt ( index ) ; switch ( c ) { case ' ' : { m_buffer . append ( "\\\"" ) ; break ; } case ' ' : { m_buffer . append ( "\\\\" ) ; break ; } case ' ' : { m_buffer . append ( "\\/" ) ; break ; } case ' ' : { m_buffer . append ( "\\b" ) ; break ; } case ' ' : { m_buffer . append ( "\\f" ) ; break ; } case ' ' : { m_buffer . append ( "\\n" ) ; break ; } case ' ' : { m_buffer . append ( "\\r" ) ; break ; } case ' ' : { m_buffer . append ( "\\t" ) ; break ; } default : { // Append if it's not a control character (0x00 to 0x1f) if ( c > 0x1f ) { m_buffer . append ( c ) ; } break ; } } } m_buffer . append ( ' ' ) ; return m_buffer . toString ( ) ; }
Escape text to ensure valid JSON .
291
8
144,224
private void writeComma ( ) throws IOException { if ( m_firstNameValuePair . peek ( ) . booleanValue ( ) ) { m_firstNameValuePair . pop ( ) ; m_firstNameValuePair . push ( Boolean . FALSE ) ; } else { m_writer . write ( ' ' ) ; } }
Write a comma to the output stream if required .
73
10
144,225
private void writeNewLineIndent ( ) throws IOException { if ( m_pretty ) { if ( ! m_indent . isEmpty ( ) ) { m_writer . write ( ' ' ) ; m_writer . write ( m_indent ) ; } } }
Write a new line and indent .
59
7
144,226
private void writeName ( String name ) throws IOException { m_writer . write ( ' ' ) ; m_writer . write ( name ) ; m_writer . write ( ' ' ) ; m_writer . write ( ":" ) ; }
Write an attribute name .
52
5
144,227
private void decreaseIndent ( ) throws IOException { if ( m_pretty ) { m_writer . write ( ' ' ) ; m_indent = m_indent . substring ( 0 , m_indent . length ( ) - INDENT . length ( ) ) ; m_writer . write ( m_indent ) ; } m_firstNameValuePair . pop ( ) ; }
Decrease the indent level .
86
6
144,228
public void process ( AvailabilityTable table , byte [ ] data ) { if ( data != null ) { Calendar cal = DateHelper . popCalendar ( ) ; int items = MPPUtility . getShort ( data , 0 ) ; int offset = 12 ; for ( int loop = 0 ; loop < items ; loop ++ ) { double unitsValue = MPPUtility . getDouble ( data , offset + 4 ) ; if ( unitsValue != 0 ) { Date startDate = MPPUtility . getTimestampFromTenths ( data , offset ) ; Date endDate = MPPUtility . getTimestampFromTenths ( data , offset + 20 ) ; cal . setTime ( endDate ) ; cal . add ( Calendar . MINUTE , - 1 ) ; endDate = cal . getTime ( ) ; Double units = NumberHelper . getDouble ( unitsValue / 100 ) ; Availability item = new Availability ( startDate , endDate , units ) ; table . add ( item ) ; } offset += 20 ; } DateHelper . pushCalendar ( cal ) ; Collections . sort ( table ) ; } }
Populates a resource availability table .
236
7
144,229
public static final Object getObject ( Locale locale , String key ) { ResourceBundle bundle = ResourceBundle . getBundle ( LocaleData . class . getName ( ) , locale ) ; return ( bundle . getObject ( key ) ) ; }
Convenience method for retrieving an Object resource .
54
10
144,230
@ SuppressWarnings ( "rawtypes" ) public static final Map getMap ( Locale locale , String key ) { ResourceBundle bundle = ResourceBundle . getBundle ( LocaleData . class . getName ( ) , locale ) ; return ( ( Map ) bundle . getObject ( key ) ) ; }
Convenience method for retrieving a Map resource .
69
10
144,231
public static final Integer getInteger ( Locale locale , String key ) { ResourceBundle bundle = ResourceBundle . getBundle ( LocaleData . class . getName ( ) , locale ) ; return ( ( Integer ) bundle . getObject ( key ) ) ; }
Convenience method for retrieving an Integer resource .
57
10
144,232
public static final char getChar ( Locale locale , String key ) { ResourceBundle bundle = ResourceBundle . getBundle ( LocaleData . class . getName ( ) , locale ) ; return ( bundle . getString ( key ) . charAt ( 0 ) ) ; }
Convenience method for retrieving a char resource .
60
10
144,233
public boolean getOverAllocated ( ) { Boolean overallocated = ( Boolean ) getCachedValue ( ResourceField . OVERALLOCATED ) ; if ( overallocated == null ) { Number peakUnits = getPeakUnits ( ) ; Number maxUnits = getMaxUnits ( ) ; overallocated = Boolean . valueOf ( NumberHelper . getDouble ( peakUnits ) > NumberHelper . getDouble ( maxUnits ) ) ; set ( ResourceField . OVERALLOCATED , overallocated ) ; } return ( overallocated . booleanValue ( ) ) ; }
Retrieves the overallocated flag .
121
8
144,234
public Date getStart ( ) { Date result = null ; for ( ResourceAssignment assignment : m_assignments ) { if ( result == null || DateHelper . compare ( result , assignment . getStart ( ) ) > 0 ) { result = assignment . getStart ( ) ; } } return ( result ) ; }
Retrieves the earliest start date for all assigned tasks .
67
12
144,235
public Duration getWorkVariance ( ) { Duration variance = ( Duration ) getCachedValue ( ResourceField . WORK_VARIANCE ) ; if ( variance == null ) { Duration work = getWork ( ) ; Duration baselineWork = getBaselineWork ( ) ; if ( work != null && baselineWork != null ) { variance = Duration . getInstance ( work . getDuration ( ) - baselineWork . convertUnits ( work . getUnits ( ) , getParentFile ( ) . getProjectProperties ( ) ) . getDuration ( ) , work . getUnits ( ) ) ; set ( ResourceField . WORK_VARIANCE , variance ) ; } } return ( variance ) ; }
Retrieves the work variance .
149
7
144,236
public String getNotes ( ) { String notes = ( String ) getCachedValue ( ResourceField . NOTES ) ; return ( notes == null ? "" : notes ) ; }
Retrieves the notes text for this resource .
37
10
144,237
public void setResourceCalendar ( ProjectCalendar calendar ) { set ( ResourceField . CALENDAR , calendar ) ; if ( calendar == null ) { setResourceCalendarUniqueID ( null ) ; } else { calendar . setResource ( this ) ; setResourceCalendarUniqueID ( calendar . getUniqueID ( ) ) ; } }
This method allows a pre - existing resource calendar to be attached to a resource .
71
16
144,238
public ProjectCalendar addResourceCalendar ( ) throws MPXJException { if ( getResourceCalendar ( ) != null ) { throw new MPXJException ( MPXJException . MAXIMUM_RECORDS ) ; } ProjectCalendar calendar = new ProjectCalendar ( getParentFile ( ) ) ; setResourceCalendar ( calendar ) ; return calendar ; }
This method allows a resource calendar to be added to a resource .
79
13
144,239
public void setBaseCalendar ( String val ) { set ( ResourceField . BASE_CALENDAR , val == null || val . length ( ) == 0 ? "Standard" : val ) ; }
Sets the Base Calendar field indicates which calendar is the base calendar for a resource calendar . The list includes the three built - in calendars as well as any new base calendars you have created in the Change Working Time dialog box .
43
45
144,240
@ Override public void setID ( Integer val ) { ProjectFile parent = getParentFile ( ) ; Integer previous = getID ( ) ; if ( previous != null ) { parent . getResources ( ) . unmapID ( previous ) ; } parent . getResources ( ) . mapID ( val , this ) ; set ( ResourceField . ID , val ) ; }
Sets ID field value .
78
6
144,241
public boolean getFlag ( int index ) { return BooleanHelper . getBoolean ( ( Boolean ) getCachedValue ( selectField ( ResourceFieldLists . CUSTOM_FLAG , index ) ) ) ; }
Retrieve a flag value .
45
6
144,242
private ResourceField selectField ( ResourceField [ ] 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 a ResourceField instance .
60
10
144,243
protected void mergeSameWork ( LinkedList < TimephasedWork > list ) { LinkedList < TimephasedWork > result = new LinkedList < TimephasedWork > ( ) ; TimephasedWork previousAssignment = null ; for ( TimephasedWork assignment : list ) { if ( previousAssignment == null ) { assignment . setAmountPerDay ( assignment . getTotalAmount ( ) ) ; result . add ( assignment ) ; } else { Duration previousAssignmentWork = previousAssignment . getAmountPerDay ( ) ; Duration assignmentWork = assignment . getTotalAmount ( ) ; if ( NumberHelper . equals ( previousAssignmentWork . getDuration ( ) , assignmentWork . getDuration ( ) , 0.01 ) ) { Date assignmentStart = previousAssignment . getStart ( ) ; Date assignmentFinish = assignment . getFinish ( ) ; double total = previousAssignment . getTotalAmount ( ) . getDuration ( ) ; total += assignmentWork . getDuration ( ) ; Duration totalWork = Duration . getInstance ( total , TimeUnit . MINUTES ) ; TimephasedWork merged = new TimephasedWork ( ) ; merged . setStart ( assignmentStart ) ; merged . setFinish ( assignmentFinish ) ; merged . setAmountPerDay ( assignmentWork ) ; merged . setTotalAmount ( totalWork ) ; result . removeLast ( ) ; assignment = merged ; } else { assignment . setAmountPerDay ( assignment . getTotalAmount ( ) ) ; } result . add ( assignment ) ; } previousAssignment = assignment ; } list . clear ( ) ; list . addAll ( result ) ; }
Merges individual days together into time spans where the same work is undertaken each day .
343
17
144,244
protected void convertToHours ( LinkedList < TimephasedWork > list ) { for ( TimephasedWork assignment : list ) { Duration totalWork = assignment . getTotalAmount ( ) ; Duration workPerDay = assignment . getAmountPerDay ( ) ; totalWork = Duration . getInstance ( totalWork . getDuration ( ) / 60 , TimeUnit . HOURS ) ; workPerDay = Duration . getInstance ( workPerDay . getDuration ( ) / 60 , TimeUnit . HOURS ) ; assignment . setTotalAmount ( totalWork ) ; assignment . setAmountPerDay ( workPerDay ) ; } }
Converts assignment duration values from minutes to hours .
131
10
144,245
public void addColumn ( FastTrackColumn column ) { FastTrackField type = column . getType ( ) ; Object [ ] data = column . getData ( ) ; for ( int index = 0 ; index < data . length ; index ++ ) { MapRow row = getRow ( index ) ; row . getMap ( ) . put ( type , data [ index ] ) ; } }
Add data for a column to this table .
81
9
144,246
private MapRow getRow ( int index ) { MapRow result ; if ( index == m_rows . size ( ) ) { result = new MapRow ( this , new HashMap < FastTrackField , Object > ( ) ) ; m_rows . add ( result ) ; } else { result = m_rows . get ( index ) ; } return result ; }
Retrieve a specific row by index number creating a blank row if this row does not exist .
77
19
144,247
private void setRecordNumber ( LinkedList < String > list ) { try { String number = list . remove ( 0 ) ; m_recordNumber = Integer . valueOf ( number ) ; } catch ( NumberFormatException ex ) { // Malformed MPX file: the record number isn't a valid integer // Catch the exception here, leaving m_recordNumber as null // so we will skip this record entirely. } }
Pop the record number from the front of the list and parse it to ensure that it is a valid integer .
88
22
144,248
public String getString ( int field ) { String result ; if ( field < m_fields . length ) { result = m_fields [ field ] ; if ( result != null ) { result = result . replace ( MPXConstants . EOL_PLACEHOLDER , ' ' ) ; } } else { result = null ; } return ( result ) ; }
Accessor method used to retrieve a String object representing the contents of an individual field . If the field does not exist in the record null is returned .
78
30
144,249
public Character getCharacter ( int field ) { Character result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = Character . valueOf ( m_fields [ field ] . charAt ( 0 ) ) ; } else { result = null ; } return ( result ) ; }
Accessor method used to retrieve a char representing the contents of an individual field . If the field does not exist in the record the default character is returned .
75
31
144,250
public Number getFloat ( int field ) throws MPXJException { try { Number result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = m_formats . getDecimalFormat ( ) . parse ( m_fields [ field ] ) ; } else { result = null ; } return ( result ) ; } catch ( ParseException ex ) { throw new MPXJException ( "Failed to parse float" , ex ) ; } }
Accessor method used to retrieve a Float object representing the contents of an individual field . If the field does not exist in the record null is returned .
113
30
144,251
public boolean getNumericBoolean ( int field ) { boolean result = false ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = Integer . parseInt ( m_fields [ field ] ) == 1 ; } return ( result ) ; }
Accessor method used to retrieve a Boolean object representing the contents of an individual field . If the field does not exist in the record null is returned .
69
30
144,252
public Rate getRate ( int field ) throws MPXJException { Rate result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { try { String rate = m_fields [ field ] ; int index = rate . indexOf ( ' ' ) ; double amount ; TimeUnit units ; if ( index == - 1 ) { amount = m_formats . getCurrencyFormat ( ) . parse ( rate ) . doubleValue ( ) ; units = TimeUnit . HOURS ; } else { amount = m_formats . getCurrencyFormat ( ) . parse ( rate . substring ( 0 , index ) ) . doubleValue ( ) ; units = TimeUnitUtility . getInstance ( rate . substring ( index + 1 ) , m_locale ) ; } result = new Rate ( amount , units ) ; } catch ( ParseException ex ) { throw new MPXJException ( "Failed to parse rate" , ex ) ; } } else { result = null ; } return ( result ) ; }
Accessor method used to retrieve an Rate object representing the contents of an individual field . If the field does not exist in the record null is returned .
230
30
144,253
public Duration getDuration ( int field ) throws MPXJException { Duration result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = DurationUtility . getInstance ( m_fields [ field ] , m_formats . getDurationDecimalFormat ( ) , m_locale ) ; } else { result = null ; } return ( result ) ; }
Accessor method used to retrieve an Duration object representing the contents of an individual field . If the field does not exist in the record null is returned .
94
30
144,254
public Number getUnits ( int field ) throws MPXJException { Number result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { try { result = Double . valueOf ( m_formats . getUnitsDecimalFormat ( ) . parse ( m_fields [ field ] ) . doubleValue ( ) * 100 ) ; } catch ( ParseException ex ) { throw new MPXJException ( "Failed to parse units" , ex ) ; } } else { result = null ; } return ( result ) ; }
Accessor method used to retrieve a Number instance representing the contents of an individual field . If the field does not exist in the record null is returned .
129
30
144,255
public CodePage getCodePage ( int field ) { CodePage result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = CodePage . getInstance ( m_fields [ field ] ) ; } else { result = CodePage . getInstance ( null ) ; } return ( result ) ; }
Retrieves a CodePage instance . Defaults to ANSI .
80
14
144,256
public AccrueType getAccrueType ( int field ) { AccrueType result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = AccrueTypeUtility . getInstance ( m_fields [ field ] , m_locale ) ; } else { result = null ; } return ( result ) ; }
Accessor method to retrieve an accrue type instance .
84
11
144,257
public Boolean getBoolean ( int field , String falseText ) { Boolean result ; if ( ( field < m_fields . length ) && ( m_fields [ field ] . length ( ) != 0 ) ) { result = ( ( m_fields [ field ] . equalsIgnoreCase ( falseText ) == true ) ? Boolean . FALSE : Boolean . TRUE ) ; } else { result = null ; } return ( result ) ; }
Accessor method to retrieve a Boolean instance .
91
9
144,258
public int getIndexFromOffset ( int offset ) { int result = - 1 ; for ( int loop = 0 ; loop < m_offset . length ; loop ++ ) { if ( m_offset [ loop ] == offset ) { result = loop ; break ; } } return ( result ) ; }
This method converts an offset value into an array index which in turn allows the data present in the fixed block to be retrieved . Note that if the requested offset is not found then this method returns - 1 .
62
41
144,259
public byte [ ] getByteArray ( int offset ) { byte [ ] result = null ; if ( offset > 0 && offset < m_data . length ) { int nextBlockOffset = MPPUtility . getInt ( m_data , offset ) ; offset += 4 ; int itemSize = MPPUtility . getInt ( m_data , offset ) ; offset += 4 ; if ( itemSize > 0 && itemSize < m_data . length ) { int blockRemainingSize = 28 ; if ( nextBlockOffset != - 1 || itemSize <= blockRemainingSize ) { int itemRemainingSize = itemSize ; result = new byte [ itemSize ] ; int resultOffset = 0 ; while ( nextBlockOffset != - 1 ) { MPPUtility . getByteArray ( m_data , offset , blockRemainingSize , result , resultOffset ) ; resultOffset += blockRemainingSize ; offset += blockRemainingSize ; itemRemainingSize -= blockRemainingSize ; if ( offset != nextBlockOffset ) { offset = nextBlockOffset ; } nextBlockOffset = MPPUtility . getInt ( m_data , offset ) ; offset += 4 ; blockRemainingSize = 32 ; } MPPUtility . getByteArray ( m_data , offset , itemRemainingSize , result , resultOffset ) ; } } } return ( result ) ; }
Retrieve a byte array of containing the data starting at the supplied offset in the FixDeferFix file . Note that this method will return null if the requested data is not found for some reason .
291
40
144,260
public List < ResourceRequestType . ResourceRequestCriterion > getResourceRequestCriterion ( ) { if ( resourceRequestCriterion == null ) { resourceRequestCriterion = new ArrayList < ResourceRequestType . ResourceRequestCriterion > ( ) ; } return this . resourceRequestCriterion ; }
Gets the value of the resourceRequestCriterion property .
61
12
144,261
private Map < UUID , FieldType > populateCustomFieldMap ( ) { byte [ ] data = m_taskProps . getByteArray ( Props . CUSTOM_FIELDS ) ; int length = MPPUtility . getInt ( data , 0 ) ; int index = length + 36 ; // 4 byte record count int recordCount = MPPUtility . getInt ( data , index ) ; index += 4 ; // 8 bytes per record index += ( 8 * recordCount ) ; Map < UUID , FieldType > map = new HashMap < UUID , FieldType > ( ) ; while ( index < data . length ) { int blockLength = MPPUtility . getInt ( data , index ) ; if ( blockLength <= 0 || index + blockLength > data . length ) { break ; } int fieldID = MPPUtility . getInt ( data , index + 4 ) ; FieldType field = FieldTypeHelper . getInstance ( fieldID ) ; UUID guid = MPPUtility . getGUID ( data , index + 160 ) ; map . put ( guid , field ) ; index += blockLength ; } return map ; }
Generate a map of UUID values to field types .
248
12
144,262
public static final void deleteQuietly ( File file ) { if ( file != null ) { if ( file . isDirectory ( ) ) { File [ ] children = file . listFiles ( ) ; if ( children != null ) { for ( File child : children ) { deleteQuietly ( child ) ; } } } file . delete ( ) ; } }
Delete a file ignoring failures .
76
6
144,263
private void extractFile ( InputStream stream , File dir ) throws IOException { byte [ ] header = new byte [ 8 ] ; byte [ ] fileName = new byte [ 13 ] ; byte [ ] dataSize = new byte [ 4 ] ; stream . read ( header ) ; stream . read ( fileName ) ; stream . read ( dataSize ) ; int dataSizeValue = getInt ( dataSize , 0 ) ; String fileNameValue = getString ( fileName , 0 ) ; File file = new File ( dir , fileNameValue ) ; if ( dataSizeValue == 0 ) { FileHelper . createNewFile ( file ) ; } else { OutputStream os = new FileOutputStream ( file ) ; FixedLengthInputStream inputStream = new FixedLengthInputStream ( stream , dataSizeValue ) ; Blast blast = new Blast ( ) ; blast . blast ( inputStream , os ) ; os . close ( ) ; } }
Extracts the data for a single file from the input stream and writes it to a target directory .
195
21
144,264
private boolean matchesFingerprint ( byte [ ] buffer , byte [ ] fingerprint ) { return Arrays . equals ( fingerprint , Arrays . copyOf ( buffer , fingerprint . length ) ) ; }
Determine if the start of the buffer matches a fingerprint byte array .
41
15
144,265
private boolean matchesFingerprint ( byte [ ] buffer , Pattern fingerprint ) { return fingerprint . matcher ( m_charset == null ? new String ( buffer ) : new String ( buffer , m_charset ) ) . matches ( ) ; }
Determine if the buffer when expressed as text matches a fingerprint regular expression .
54
16
144,266
private ProjectFile readProjectFile ( ProjectReader reader , InputStream stream ) throws MPXJException { addListeners ( reader ) ; return reader . read ( stream ) ; }
Adds listeners and reads from a stream .
37
8
144,267
private ProjectFile readProjectFile ( ProjectReader reader , File file ) throws MPXJException { addListeners ( reader ) ; return reader . read ( file ) ; }
Adds listeners and reads from a file .
36
8
144,268
private ProjectFile handleOleCompoundDocument ( InputStream stream ) throws Exception { POIFSFileSystem fs = new POIFSFileSystem ( POIFSFileSystem . createNonClosingInputStream ( stream ) ) ; String fileFormat = MPPReader . getFileFormat ( fs ) ; if ( fileFormat != null && fileFormat . startsWith ( "MSProject" ) ) { MPPReader reader = new MPPReader ( ) ; addListeners ( reader ) ; return reader . read ( fs ) ; } return null ; }
We have an OLE compound document ... but is it an MPP file?
118
16
144,269
private ProjectFile handleMDBFile ( InputStream stream ) throws Exception { File file = InputStreamHelper . writeStreamToTempFile ( stream , ".mdb" ) ; try { Class . forName ( "sun.jdbc.odbc.JdbcOdbcDriver" ) ; String url = "jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb);DBQ=" + file . getCanonicalPath ( ) ; Set < String > tableNames = populateTableNames ( url ) ; if ( tableNames . contains ( "MSP_PROJECTS" ) ) { return readProjectFile ( new MPDDatabaseReader ( ) , file ) ; } if ( tableNames . contains ( "EXCEPTIONN" ) ) { return readProjectFile ( new AstaDatabaseReader ( ) , file ) ; } return null ; } finally { FileHelper . deleteQuietly ( file ) ; } }
We have identified that we have an MDB file . This could be a Microsoft Project database or an Asta database . Open the database and use the table names present to determine which type this is .
202
40
144,270
private ProjectFile handleSQLiteFile ( InputStream stream ) throws Exception { File file = InputStreamHelper . writeStreamToTempFile ( stream , ".sqlite" ) ; try { Class . forName ( "org.sqlite.JDBC" ) ; String url = "jdbc:sqlite:" + file . getCanonicalPath ( ) ; Set < String > tableNames = populateTableNames ( url ) ; if ( tableNames . contains ( "EXCEPTIONN" ) ) { return readProjectFile ( new AstaDatabaseFileReader ( ) , file ) ; } if ( tableNames . contains ( "PROJWBS" ) ) { Connection connection = null ; try { Properties props = new Properties ( ) ; props . setProperty ( "date_string_format" , "yyyy-MM-dd HH:mm:ss" ) ; connection = DriverManager . getConnection ( url , props ) ; PrimaveraDatabaseReader reader = new PrimaveraDatabaseReader ( ) ; reader . setConnection ( connection ) ; addListeners ( reader ) ; return reader . read ( ) ; } finally { if ( connection != null ) { connection . close ( ) ; } } } if ( tableNames . contains ( "ZSCHEDULEITEM" ) ) { return readProjectFile ( new MerlinReader ( ) , file ) ; } return null ; } finally { FileHelper . deleteQuietly ( file ) ; } }
We have identified that we have a SQLite file . This could be a Primavera Project database or an Asta database . Open the database and use the table names present to determine which type this is .
308
43
144,271
private ProjectFile handleZipFile ( InputStream stream ) throws Exception { File dir = null ; try { dir = InputStreamHelper . writeZipStreamToTempDir ( stream ) ; ProjectFile result = handleDirectory ( dir ) ; if ( result != null ) { return result ; } } finally { FileHelper . deleteQuietly ( dir ) ; } return null ; }
We have identified that we have a zip file . Extract the contents into a temporary directory and process .
77
20
144,272
private ProjectFile handleDirectory ( File directory ) throws Exception { ProjectFile result = handleDatabaseInDirectory ( directory ) ; if ( result == null ) { result = handleFileInDirectory ( directory ) ; } return result ; }
We have a directory . Determine if this contains a multi - file database we understand if so process it . If it does not contain a database test each file within the directory structure to determine if it contains a file whose format we understand .
46
48
144,273
private ProjectFile handleDatabaseInDirectory ( File directory ) throws Exception { byte [ ] buffer = new byte [ BUFFER_SIZE ] ; File [ ] files = directory . listFiles ( ) ; if ( files != null ) { for ( File file : files ) { if ( file . isDirectory ( ) ) { continue ; } FileInputStream fis = new FileInputStream ( file ) ; int bytesRead = fis . read ( buffer ) ; fis . close ( ) ; // // If the file is smaller than the buffer we are peeking into, // it's probably not a valid schedule file. // if ( bytesRead != BUFFER_SIZE ) { continue ; } if ( matchesFingerprint ( buffer , BTRIEVE_FINGERPRINT ) ) { return handleP3BtrieveDatabase ( directory ) ; } if ( matchesFingerprint ( buffer , STW_FINGERPRINT ) ) { return handleSureTrakDatabase ( directory ) ; } } } return null ; }
Given a directory determine if it contains a multi - file database whose format we can process .
214
18
144,274
private ProjectFile handleByteOrderMark ( InputStream stream , int length , Charset charset ) throws Exception { UniversalProjectReader reader = new UniversalProjectReader ( ) ; reader . setSkipBytes ( length ) ; reader . setCharset ( charset ) ; return reader . read ( stream ) ; }
The file we are working with has a byte order mark . Skip this and try again to read the file .
65
22
144,275
private ProjectFile handleDosExeFile ( InputStream stream ) throws Exception { File file = InputStreamHelper . writeStreamToTempFile ( stream , ".tmp" ) ; InputStream is = null ; try { is = new FileInputStream ( file ) ; if ( is . available ( ) > 1350 ) { StreamHelper . skip ( is , 1024 ) ; // Bytes at offset 1024 byte [ ] data = new byte [ 2 ] ; is . read ( data ) ; if ( matchesFingerprint ( data , WINDOWS_NE_EXE_FINGERPRINT ) ) { StreamHelper . skip ( is , 286 ) ; // Bytes at offset 1312 data = new byte [ 34 ] ; is . read ( data ) ; if ( matchesFingerprint ( data , PRX_FINGERPRINT ) ) { is . close ( ) ; is = null ; return readProjectFile ( new P3PRXFileReader ( ) , file ) ; } } if ( matchesFingerprint ( data , STX_FINGERPRINT ) ) { StreamHelper . skip ( is , 31742 ) ; // Bytes at offset 32768 data = new byte [ 4 ] ; is . read ( data ) ; if ( matchesFingerprint ( data , PRX3_FINGERPRINT ) ) { is . close ( ) ; is = null ; return readProjectFile ( new SureTrakSTXFileReader ( ) , file ) ; } } } return null ; } finally { StreamHelper . closeQuietly ( is ) ; FileHelper . deleteQuietly ( file ) ; } }
This could be a self - extracting archive . If we understand the format expand it and check the content for files we can read .
345
26
144,276
private ProjectFile handleXerFile ( InputStream stream ) throws Exception { PrimaveraXERFileReader reader = new PrimaveraXERFileReader ( ) ; reader . setCharset ( m_charset ) ; List < ProjectFile > projects = reader . readAll ( stream ) ; ProjectFile project = null ; for ( ProjectFile file : projects ) { if ( file . getProjectProperties ( ) . getExportFlag ( ) ) { project = file ; break ; } } if ( project == null && ! projects . isEmpty ( ) ) { project = projects . get ( 0 ) ; } return project ; }
XER files can contain multiple projects when there are cross - project dependencies . As the UniversalProjectReader is designed just to read a single project we need to select one project from those available in the XER file . The original project selected for export by the user will have its export flag set to true . We ll return the first project we find where the export flag is set to true otherwise we ll just return the first project we find in the file .
136
91
144,277
private Set < String > populateTableNames ( String url ) throws SQLException { Set < String > tableNames = new HashSet < String > ( ) ; Connection connection = null ; ResultSet rs = null ; try { connection = DriverManager . getConnection ( url ) ; DatabaseMetaData dmd = connection . getMetaData ( ) ; rs = dmd . getTables ( null , null , null , null ) ; while ( rs . next ( ) ) { tableNames . add ( rs . getString ( "TABLE_NAME" ) . toUpperCase ( ) ) ; } } finally { if ( rs != null ) { rs . close ( ) ; } if ( connection != null ) { connection . close ( ) ; } } return tableNames ; }
Open a database and build a set of table names .
162
11
144,278
public static void skip ( InputStream stream , long skip ) throws IOException { long count = skip ; while ( count > 0 ) { count -= stream . skip ( count ) ; } }
The documentation for InputStream . skip indicates that it can bail out early and not skip the requested number of bytes . I ve encountered this in practice hence this helper method .
39
34
144,279
private void processCustomValueLists ( ) throws IOException { CustomFieldValueReader9 reader = new CustomFieldValueReader9 ( m_projectDir , m_file . getProjectProperties ( ) , m_projectProps , m_file . getCustomFields ( ) ) ; reader . process ( ) ; }
Retrieve any task field value lists defined in the MPP file .
68
14
144,280
private void processFieldNameAliases ( Map < Integer , FieldType > map , byte [ ] data ) { if ( data != null ) { int offset = 0 ; int index = 0 ; CustomFieldContainer fields = m_file . getCustomFields ( ) ; while ( offset < data . length ) { String alias = MPPUtility . getUnicodeString ( data , offset ) ; if ( ! alias . isEmpty ( ) ) { FieldType field = map . get ( Integer . valueOf ( index ) ) ; if ( field != null ) { fields . getCustomField ( field ) . setAlias ( alias ) ; } } offset += ( alias . length ( ) + 1 ) * 2 ; index ++ ; } } }
Retrieve any resource field aliases defined in the MPP file .
156
13
144,281
private TreeMap < Integer , Integer > createResourceMap ( FieldMap fieldMap , FixedMeta rscFixedMeta , FixedData rscFixedData ) { TreeMap < Integer , Integer > resourceMap = new TreeMap < Integer , Integer > ( ) ; int itemCount = rscFixedMeta . getAdjustedItemCount ( ) ; for ( int loop = 0 ; loop < itemCount ; loop ++ ) { byte [ ] data = rscFixedData . getByteArrayValue ( loop ) ; if ( data == null || data . length < fieldMap . getMaxFixedDataSize ( 0 ) ) { continue ; } Integer uniqueID = Integer . valueOf ( MPPUtility . getShort ( data , 0 ) ) ; resourceMap . put ( uniqueID , Integer . valueOf ( loop ) ) ; } return ( resourceMap ) ; }
This method maps the resource unique identifiers to their index number within the FixedData block .
178
17
144,282
private void postProcessTasks ( ) { List < Task > allTasks = m_file . getTasks ( ) ; if ( allTasks . size ( ) > 1 ) { Collections . sort ( allTasks ) ; int taskID = - 1 ; int lastTaskID = - 1 ; for ( int i = 0 ; i < allTasks . size ( ) ; i ++ ) { Task task = allTasks . get ( i ) ; taskID = NumberHelper . getInt ( task . getID ( ) ) ; // In Project the tasks IDs are always contiguous so we can spot invalid tasks by making sure all // IDs are represented. if ( ! task . getNull ( ) && lastTaskID != - 1 && taskID > lastTaskID + 1 ) { // This task looks to be invalid. task . setNull ( true ) ; } else { lastTaskID = taskID ; } } } }
This method is called to try to catch any invalid tasks that may have sneaked past all our other checks . This is done by validating the tasks by task ID .
195
34
144,283
public void process ( String name ) throws Exception { ProjectFile file = new UniversalProjectReader ( ) . read ( name ) ; for ( Task task : file . getTasks ( ) ) { if ( ! task . getSummary ( ) ) { System . out . print ( task . getWBS ( ) ) ; System . out . print ( "\t" ) ; System . out . print ( task . getName ( ) ) ; System . out . print ( "\t" ) ; System . out . print ( format ( task . getStart ( ) ) ) ; System . out . print ( "\t" ) ; System . out . print ( format ( task . getActualStart ( ) ) ) ; System . out . print ( "\t" ) ; System . out . print ( format ( task . getFinish ( ) ) ) ; System . out . print ( "\t" ) ; System . out . print ( format ( task . getActualFinish ( ) ) ) ; System . out . println ( ) ; } } }
Dump data for all non - summary tasks to stdout .
218
13
144,284
private void readProjectProperties ( Document cdp ) { WorkspaceProperties props = cdp . getWorkspaceProperties ( ) ; ProjectProperties mpxjProps = m_projectFile . getProjectProperties ( ) ; mpxjProps . setSymbolPosition ( props . getCurrencyPosition ( ) ) ; mpxjProps . setCurrencyDigits ( props . getCurrencyDigits ( ) ) ; mpxjProps . setCurrencySymbol ( props . getCurrencySymbol ( ) ) ; mpxjProps . setDaysPerMonth ( props . getDaysPerMonth ( ) ) ; mpxjProps . setMinutesPerDay ( props . getHoursPerDay ( ) ) ; mpxjProps . setMinutesPerWeek ( props . getHoursPerWeek ( ) ) ; m_workHoursPerDay = mpxjProps . getMinutesPerDay ( ) . doubleValue ( ) / 60.0 ; }
Extracts project properties from a ConceptDraw PROJECT file .
213
13
144,285
private void readCalendars ( Document cdp ) { for ( Calendar calendar : cdp . getCalendars ( ) . getCalendar ( ) ) { readCalendar ( calendar ) ; } for ( Calendar calendar : cdp . getCalendars ( ) . getCalendar ( ) ) { ProjectCalendar child = m_calendarMap . get ( calendar . getID ( ) ) ; ProjectCalendar parent = m_calendarMap . get ( calendar . getBaseCalendarID ( ) ) ; if ( parent == null ) { m_projectFile . setDefaultCalendar ( child ) ; } else { child . setParent ( parent ) ; } } }
Extracts calendar data from a ConceptDraw PROJECT file .
140
13
144,286
private void readWeekDay ( ProjectCalendar mpxjCalendar , WeekDay day ) { if ( day . isIsDayWorking ( ) ) { ProjectCalendarHours hours = mpxjCalendar . addCalendarHours ( day . getDay ( ) ) ; for ( Document . Calendars . Calendar . WeekDays . WeekDay . TimePeriods . TimePeriod period : day . getTimePeriods ( ) . getTimePeriod ( ) ) { hours . addRange ( new DateRange ( period . getFrom ( ) , period . getTo ( ) ) ) ; } } }
Reads a single day for a calendar .
128
9
144,287
private void readExceptionDay ( ProjectCalendar mpxjCalendar , ExceptedDay day ) { ProjectCalendarException mpxjException = mpxjCalendar . addCalendarException ( day . getDate ( ) , day . getDate ( ) ) ; if ( day . isIsDayWorking ( ) ) { for ( Document . Calendars . Calendar . ExceptedDays . ExceptedDay . TimePeriods . TimePeriod period : day . getTimePeriods ( ) . getTimePeriod ( ) ) { mpxjException . addRange ( new DateRange ( period . getFrom ( ) , period . getTo ( ) ) ) ; } } }
Read an exception day for a calendar .
144
8
144,288
private void readResources ( Document cdp ) { for ( Document . Resources . Resource resource : cdp . getResources ( ) . getResource ( ) ) { readResource ( resource ) ; } }
Reads resource data from a ConceptDraw PROJECT file .
41
12
144,289
private void readResource ( Document . Resources . Resource resource ) { Resource mpxjResource = m_projectFile . addResource ( ) ; mpxjResource . setName ( resource . getName ( ) ) ; mpxjResource . setResourceCalendar ( m_calendarMap . get ( resource . getCalendarID ( ) ) ) ; mpxjResource . setStandardRate ( new Rate ( resource . getCost ( ) , resource . getCostTimeUnit ( ) ) ) ; mpxjResource . setEmailAddress ( resource . getEMail ( ) ) ; mpxjResource . setGroup ( resource . getGroup ( ) ) ; //resource.getHyperlinks() mpxjResource . setUniqueID ( resource . getID ( ) ) ; //resource.getMarkerID() mpxjResource . setNotes ( resource . getNote ( ) ) ; mpxjResource . setID ( Integer . valueOf ( resource . getOutlineNumber ( ) ) ) ; //resource.getStyleProject() mpxjResource . setType ( resource . getSubType ( ) == null ? resource . getType ( ) : resource . getSubType ( ) ) ; }
Reads a single resource from a ConceptDraw PROJECT file .
252
13
144,290
private void readTasks ( Document cdp ) { // // Sort the projects into the correct order // List < Project > projects = new ArrayList < Project > ( cdp . getProjects ( ) . getProject ( ) ) ; final AlphanumComparator comparator = new AlphanumComparator ( ) ; Collections . sort ( projects , new Comparator < Project > ( ) { @ Override public int compare ( Project o1 , Project o2 ) { return comparator . compare ( o1 . getOutlineNumber ( ) , o2 . getOutlineNumber ( ) ) ; } } ) ; for ( Project project : cdp . getProjects ( ) . getProject ( ) ) { readProject ( project ) ; } }
Read the projects from a ConceptDraw PROJECT file as top level tasks .
157
15
144,291
private void readProject ( Project project ) { Task mpxjTask = m_projectFile . addTask ( ) ; //project.getAuthor() mpxjTask . setBaselineCost ( project . getBaselineCost ( ) ) ; mpxjTask . setBaselineFinish ( project . getBaselineFinishDate ( ) ) ; mpxjTask . setBaselineStart ( project . getBaselineStartDate ( ) ) ; //project.getBudget(); //project.getCompany() mpxjTask . setFinish ( project . getFinishDate ( ) ) ; //project.getGoal() //project.getHyperlinks() //project.getMarkerID() mpxjTask . setName ( project . getName ( ) ) ; mpxjTask . setNotes ( project . getNote ( ) ) ; mpxjTask . setPriority ( project . getPriority ( ) ) ; // project.getSite() mpxjTask . setStart ( project . getStartDate ( ) ) ; // project.getStyleProject() // project.getTask() // project.getTimeScale() // project.getViewProperties() String projectIdentifier = project . getID ( ) . toString ( ) ; mpxjTask . setGUID ( UUID . nameUUIDFromBytes ( projectIdentifier . getBytes ( ) ) ) ; // // Sort the tasks into the correct order // List < Document . Projects . Project . Task > tasks = new ArrayList < Document . Projects . Project . Task > ( project . getTask ( ) ) ; final AlphanumComparator comparator = new AlphanumComparator ( ) ; Collections . sort ( tasks , new Comparator < Document . Projects . Project . Task > ( ) { @ Override public int compare ( Document . Projects . Project . Task o1 , Document . Projects . Project . Task o2 ) { return comparator . compare ( o1 . getOutlineNumber ( ) , o2 . getOutlineNumber ( ) ) ; } } ) ; Map < String , Task > map = new HashMap < String , Task > ( ) ; map . put ( "" , mpxjTask ) ; for ( Document . Projects . Project . Task task : tasks ) { readTask ( projectIdentifier , map , task ) ; } }
Read a project from a ConceptDraw PROJECT file .
491
11
144,292
private void readTask ( String projectIdentifier , Map < String , Task > map , Document . Projects . Project . Task task ) { Task parentTask = map . get ( getParentOutlineNumber ( task . getOutlineNumber ( ) ) ) ; Task mpxjTask = parentTask . addTask ( ) ; TimeUnit units = task . getBaseDurationTimeUnit ( ) ; mpxjTask . setCost ( task . getActualCost ( ) ) ; mpxjTask . setDuration ( getDuration ( units , task . getActualDuration ( ) ) ) ; mpxjTask . setFinish ( task . getActualFinishDate ( ) ) ; mpxjTask . setStart ( task . getActualStartDate ( ) ) ; mpxjTask . setBaselineDuration ( getDuration ( units , task . getBaseDuration ( ) ) ) ; mpxjTask . setBaselineFinish ( task . getBaseFinishDate ( ) ) ; mpxjTask . setBaselineCost ( task . getBaselineCost ( ) ) ; // task.getBaselineFinishDate() // task.getBaselineFinishTemplateOffset() // task.getBaselineStartDate() // task.getBaselineStartTemplateOffset() mpxjTask . setBaselineStart ( task . getBaseStartDate ( ) ) ; // task.getCallouts() mpxjTask . setPercentageComplete ( task . getComplete ( ) ) ; mpxjTask . setDeadline ( task . getDeadlineDate ( ) ) ; // task.getDeadlineTemplateOffset() // task.getHyperlinks() // task.getMarkerID() mpxjTask . setName ( task . getName ( ) ) ; mpxjTask . setNotes ( task . getNote ( ) ) ; mpxjTask . setPriority ( task . getPriority ( ) ) ; // task.getRecalcBase1() // task.getRecalcBase2() mpxjTask . setType ( task . getSchedulingType ( ) ) ; // task.getStyleProject() // task.getTemplateOffset() // task.getValidatedByProject() if ( task . isIsMilestone ( ) ) { mpxjTask . setMilestone ( true ) ; mpxjTask . setDuration ( Duration . getInstance ( 0 , TimeUnit . HOURS ) ) ; mpxjTask . setBaselineDuration ( Duration . getInstance ( 0 , TimeUnit . HOURS ) ) ; } String taskIdentifier = projectIdentifier + "." + task . getID ( ) ; m_taskIdMap . put ( task . getID ( ) , mpxjTask ) ; mpxjTask . setGUID ( UUID . nameUUIDFromBytes ( taskIdentifier . getBytes ( ) ) ) ; map . put ( task . getOutlineNumber ( ) , mpxjTask ) ; for ( Document . Projects . Project . Task . ResourceAssignments . ResourceAssignment assignment : task . getResourceAssignments ( ) . getResourceAssignment ( ) ) { readResourceAssignment ( mpxjTask , assignment ) ; } }
Read a task from a ConceptDraw PROJECT file .
678
11
144,293
private void readRelationships ( Document cdp ) { for ( Link link : cdp . getLinks ( ) . getLink ( ) ) { readRelationship ( link ) ; } }
Read all task relationships from a ConceptDraw PROJECT file .
39
12
144,294
private void readRelationship ( Link link ) { Task sourceTask = m_taskIdMap . get ( link . getSourceTaskID ( ) ) ; Task destinationTask = m_taskIdMap . get ( link . getDestinationTaskID ( ) ) ; if ( sourceTask != null && destinationTask != null ) { Duration lag = getDuration ( link . getLagUnit ( ) , link . getLag ( ) ) ; RelationType type = link . getType ( ) ; Relation relation = destinationTask . addPredecessor ( sourceTask , type , lag ) ; relation . setUniqueID ( link . getID ( ) ) ; } }
Read a task relationship .
140
5
144,295
private Duration getDuration ( TimeUnit units , Double duration ) { Duration result = null ; if ( duration != null ) { double durationValue = duration . doubleValue ( ) * 100.0 ; switch ( units ) { case MINUTES : { durationValue *= MINUTES_PER_DAY ; break ; } case HOURS : { durationValue *= HOURS_PER_DAY ; break ; } case DAYS : { durationValue *= 3.0 ; break ; } case WEEKS : { durationValue *= 0.6 ; break ; } case MONTHS : { durationValue *= 0.15 ; break ; } default : { throw new IllegalArgumentException ( "Unsupported time units " + units ) ; } } durationValue = Math . round ( durationValue ) / 100.0 ; result = Duration . getInstance ( durationValue , units ) ; } return result ; }
Read a duration .
190
4
144,296
private String getParentOutlineNumber ( String outlineNumber ) { String result ; int index = outlineNumber . lastIndexOf ( ' ' ) ; if ( index == - 1 ) { result = "" ; } else { result = outlineNumber . substring ( 0 , index ) ; } return result ; }
Return the parent outline number or an empty string if we have a root task .
63
16
144,297
public static ConstraintField getInstance ( int value ) { ConstraintField result = null ; if ( value >= 0 && value < FIELD_ARRAY . length ) { result = FIELD_ARRAY [ value ] ; } return ( result ) ; }
Retrieve an instance of the ConstraintField class based on the data read from an MS Project file .
56
22
144,298
public void update ( ) { ProjectProperties properties = m_projectFile . getProjectProperties ( ) ; char decimalSeparator = properties . getDecimalSeparator ( ) ; char thousandsSeparator = properties . getThousandsSeparator ( ) ; m_unitsDecimalFormat . applyPattern ( "#.##" , null , decimalSeparator , thousandsSeparator ) ; m_decimalFormat . applyPattern ( "0.00#" , null , decimalSeparator , thousandsSeparator ) ; m_durationDecimalFormat . applyPattern ( "#.##" , null , decimalSeparator , thousandsSeparator ) ; m_percentageDecimalFormat . applyPattern ( "##0.##" , null , decimalSeparator , thousandsSeparator ) ; updateCurrencyFormats ( properties , decimalSeparator , thousandsSeparator ) ; updateDateTimeFormats ( properties ) ; }
Called to update the cached formats when something changes .
201
11
144,299
private void updateCurrencyFormats ( ProjectProperties properties , char decimalSeparator , char thousandsSeparator ) { String prefix = "" ; String suffix = "" ; String currencySymbol = quoteFormatCharacters ( properties . getCurrencySymbol ( ) ) ; switch ( properties . getSymbolPosition ( ) ) { case AFTER : { suffix = currencySymbol ; break ; } case BEFORE : { prefix = currencySymbol ; break ; } case AFTER_WITH_SPACE : { suffix = " " + currencySymbol ; break ; } case BEFORE_WITH_SPACE : { prefix = currencySymbol + " " ; break ; } } StringBuilder pattern = new StringBuilder ( prefix ) ; pattern . append ( "#0" ) ; int digits = properties . getCurrencyDigits ( ) . intValue ( ) ; if ( digits > 0 ) { pattern . append ( ' ' ) ; for ( int i = 0 ; i < digits ; i ++ ) { pattern . append ( "0" ) ; } } pattern . append ( suffix ) ; String primaryPattern = pattern . toString ( ) ; String [ ] alternativePatterns = new String [ 7 ] ; alternativePatterns [ 0 ] = primaryPattern + ";(" + primaryPattern + ")" ; pattern . insert ( prefix . length ( ) , "#,#" ) ; String secondaryPattern = pattern . toString ( ) ; alternativePatterns [ 1 ] = secondaryPattern ; alternativePatterns [ 2 ] = secondaryPattern + ";(" + secondaryPattern + ")" ; pattern . setLength ( 0 ) ; pattern . append ( "#0" ) ; if ( digits > 0 ) { pattern . append ( ' ' ) ; for ( int i = 0 ; i < digits ; i ++ ) { pattern . append ( "0" ) ; } } String noSymbolPrimaryPattern = pattern . toString ( ) ; alternativePatterns [ 3 ] = noSymbolPrimaryPattern ; alternativePatterns [ 4 ] = noSymbolPrimaryPattern + ";(" + noSymbolPrimaryPattern + ")" ; pattern . insert ( 0 , "#,#" ) ; String noSymbolSecondaryPattern = pattern . toString ( ) ; alternativePatterns [ 5 ] = noSymbolSecondaryPattern ; alternativePatterns [ 6 ] = noSymbolSecondaryPattern + ";(" + noSymbolSecondaryPattern + ")" ; m_currencyFormat . applyPattern ( primaryPattern , alternativePatterns , decimalSeparator , thousandsSeparator ) ; }
Update the currency format .
533
5