idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
143,900
private boolean moreDates ( Calendar calendar , List < Date > dates ) { boolean result ; if ( m_finishDate == null ) { int occurrences = NumberHelper . getInt ( m_occurrences ) ; if ( occurrences < 1 ) { occurrences = 1 ; } result = dates . size ( ) < occurrences ; } else { result = calendar . getTimeInMillis ( ) <= m_finishDate . getTime ( ) ; } return result ; }
Determines if we need to calculate more dates . If we do not have a finish date this method falls back on using the occurrences attribute . If we have a finish date we ll use that instead . We re assuming that the recurring data has one or other of those values .
99
56
143,901
private void getDailyDates ( Calendar calendar , int frequency , List < Date > dates ) { while ( moreDates ( calendar , dates ) ) { dates . add ( calendar . getTime ( ) ) ; calendar . add ( Calendar . DAY_OF_YEAR , frequency ) ; } }
Calculate start dates for a daily recurrence .
62
11
143,902
private void getWeeklyDates ( Calendar calendar , int frequency , List < Date > dates ) { int currentDay = calendar . get ( Calendar . DAY_OF_WEEK ) ; while ( moreDates ( calendar , dates ) ) { int offset = 0 ; for ( int dayIndex = 0 ; dayIndex < 7 ; dayIndex ++ ) { if ( getWeeklyDay ( Day . getInstance ( currentDay ) ) ) { if ( offset != 0 ) { calendar . add ( Calendar . DAY_OF_YEAR , offset ) ; offset = 0 ; } if ( ! moreDates ( calendar , dates ) ) { break ; } dates . add ( calendar . getTime ( ) ) ; } ++ offset ; ++ currentDay ; if ( currentDay > 7 ) { currentDay = 1 ; } } if ( frequency > 1 ) { offset += ( 7 * ( frequency - 1 ) ) ; } calendar . add ( Calendar . DAY_OF_YEAR , offset ) ; } }
Calculate start dates for a weekly recurrence .
209
11
143,903
private void getMonthlyDates ( Calendar calendar , int frequency , List < Date > dates ) { if ( m_relative ) { getMonthlyRelativeDates ( calendar , frequency , dates ) ; } else { getMonthlyAbsoluteDates ( calendar , frequency , dates ) ; } }
Calculate start dates for a monthly recurrence .
63
11
143,904
private void getMonthlyRelativeDates ( Calendar calendar , int frequency , List < Date > dates ) { long startDate = calendar . getTimeInMillis ( ) ; calendar . set ( Calendar . DAY_OF_MONTH , 1 ) ; int dayNumber = NumberHelper . getInt ( m_dayNumber ) ; while ( moreDates ( calendar , dates ) ) { if ( dayNumber > 4 ) { setCalendarToLastRelativeDay ( calendar ) ; } else { setCalendarToOrdinalRelativeDay ( calendar , dayNumber ) ; } if ( calendar . getTimeInMillis ( ) > startDate ) { dates . add ( calendar . getTime ( ) ) ; if ( ! moreDates ( calendar , dates ) ) { break ; } } calendar . set ( Calendar . DAY_OF_MONTH , 1 ) ; calendar . add ( Calendar . MONTH , frequency ) ; } }
Calculate start dates for a monthly relative recurrence .
196
12
143,905
private void getMonthlyAbsoluteDates ( Calendar calendar , int frequency , List < Date > dates ) { int currentDayNumber = calendar . get ( Calendar . DAY_OF_MONTH ) ; calendar . set ( Calendar . DAY_OF_MONTH , 1 ) ; int requiredDayNumber = NumberHelper . getInt ( m_dayNumber ) ; if ( requiredDayNumber < currentDayNumber ) { calendar . add ( Calendar . MONTH , 1 ) ; } while ( moreDates ( calendar , dates ) ) { int useDayNumber = requiredDayNumber ; int maxDayNumber = calendar . getActualMaximum ( Calendar . DAY_OF_MONTH ) ; if ( useDayNumber > maxDayNumber ) { useDayNumber = maxDayNumber ; } calendar . set ( Calendar . DAY_OF_MONTH , useDayNumber ) ; dates . add ( calendar . getTime ( ) ) ; calendar . set ( Calendar . DAY_OF_MONTH , 1 ) ; calendar . add ( Calendar . MONTH , frequency ) ; } }
Calculate start dates for a monthly absolute recurrence .
222
12
143,906
private void getYearlyDates ( Calendar calendar , List < Date > dates ) { if ( m_relative ) { getYearlyRelativeDates ( calendar , dates ) ; } else { getYearlyAbsoluteDates ( calendar , dates ) ; } }
Calculate start dates for a yearly recurrence .
56
11
143,907
private void getYearlyRelativeDates ( Calendar calendar , List < Date > dates ) { long startDate = calendar . getTimeInMillis ( ) ; calendar . set ( Calendar . DAY_OF_MONTH , 1 ) ; calendar . set ( Calendar . MONTH , NumberHelper . getInt ( m_monthNumber ) - 1 ) ; int dayNumber = NumberHelper . getInt ( m_dayNumber ) ; while ( moreDates ( calendar , dates ) ) { if ( dayNumber > 4 ) { setCalendarToLastRelativeDay ( calendar ) ; } else { setCalendarToOrdinalRelativeDay ( calendar , dayNumber ) ; } if ( calendar . getTimeInMillis ( ) > startDate ) { dates . add ( calendar . getTime ( ) ) ; if ( ! moreDates ( calendar , dates ) ) { break ; } } calendar . set ( Calendar . DAY_OF_MONTH , 1 ) ; calendar . add ( Calendar . YEAR , 1 ) ; } }
Calculate start dates for a yearly relative recurrence .
216
12
143,908
private void getYearlyAbsoluteDates ( Calendar calendar , List < Date > dates ) { long startDate = calendar . getTimeInMillis ( ) ; calendar . set ( Calendar . DAY_OF_MONTH , 1 ) ; calendar . set ( Calendar . MONTH , NumberHelper . getInt ( m_monthNumber ) - 1 ) ; int requiredDayNumber = NumberHelper . getInt ( m_dayNumber ) ; while ( moreDates ( calendar , dates ) ) { int useDayNumber = requiredDayNumber ; int maxDayNumber = calendar . getActualMaximum ( Calendar . DAY_OF_MONTH ) ; if ( useDayNumber > maxDayNumber ) { useDayNumber = maxDayNumber ; } calendar . set ( Calendar . DAY_OF_MONTH , useDayNumber ) ; if ( calendar . getTimeInMillis ( ) < startDate ) { calendar . add ( Calendar . YEAR , 1 ) ; } dates . add ( calendar . getTime ( ) ) ; calendar . set ( Calendar . DAY_OF_MONTH , 1 ) ; calendar . add ( Calendar . YEAR , 1 ) ; } }
Calculate start dates for a yearly absolute recurrence .
241
12
143,909
private void setCalendarToOrdinalRelativeDay ( Calendar calendar , int dayNumber ) { int currentDayOfWeek = calendar . get ( Calendar . DAY_OF_WEEK ) ; int requiredDayOfWeek = getDayOfWeek ( ) . getValue ( ) ; int dayOfWeekOffset = 0 ; if ( requiredDayOfWeek > currentDayOfWeek ) { dayOfWeekOffset = requiredDayOfWeek - currentDayOfWeek ; } else { if ( requiredDayOfWeek < currentDayOfWeek ) { dayOfWeekOffset = 7 - ( currentDayOfWeek - requiredDayOfWeek ) ; } } if ( dayOfWeekOffset != 0 ) { calendar . add ( Calendar . DAY_OF_YEAR , dayOfWeekOffset ) ; } if ( dayNumber > 1 ) { calendar . add ( Calendar . DAY_OF_YEAR , ( 7 * ( dayNumber - 1 ) ) ) ; } }
Moves a calendar to the nth named day of the month .
196
14
143,910
private void setCalendarToLastRelativeDay ( Calendar calendar ) { calendar . set ( Calendar . DAY_OF_MONTH , calendar . getActualMaximum ( Calendar . DAY_OF_MONTH ) ) ; int currentDayOfWeek = calendar . get ( Calendar . DAY_OF_WEEK ) ; int requiredDayOfWeek = getDayOfWeek ( ) . getValue ( ) ; int dayOfWeekOffset = 0 ; if ( currentDayOfWeek > requiredDayOfWeek ) { dayOfWeekOffset = requiredDayOfWeek - currentDayOfWeek ; } else { if ( currentDayOfWeek < requiredDayOfWeek ) { dayOfWeekOffset = - 7 + ( requiredDayOfWeek - currentDayOfWeek ) ; } } if ( dayOfWeekOffset != 0 ) { calendar . add ( Calendar . DAY_OF_YEAR , dayOfWeekOffset ) ; } }
Moves a calendar to the last named day of the month .
189
13
143,911
public void setYearlyAbsoluteFromDate ( Date date ) { if ( date != null ) { Calendar cal = DateHelper . popCalendar ( date ) ; m_dayNumber = Integer . valueOf ( cal . get ( Calendar . DAY_OF_MONTH ) ) ; m_monthNumber = Integer . valueOf ( cal . get ( Calendar . MONTH ) + 1 ) ; DateHelper . pushCalendar ( cal ) ; } }
Sets the yearly absolute date .
94
7
143,912
private String getOrdinal ( Integer value ) { String result ; int index = value . intValue ( ) ; if ( index >= ORDINAL . length ) { result = "every " + index + "th" ; } else { result = ORDINAL [ index ] ; } return result ; }
Retrieve the ordinal text for a given integer .
63
11
143,913
public static Priority getInstance ( Locale locale , String priority ) { int index = DEFAULT_PRIORITY_INDEX ; if ( priority != null ) { String [ ] priorityTypes = LocaleData . getStringArray ( locale , LocaleData . PRIORITY_TYPES ) ; for ( int loop = 0 ; loop < priorityTypes . length ; loop ++ ) { if ( priorityTypes [ loop ] . equalsIgnoreCase ( priority ) == true ) { index = loop ; break ; } } } return ( Priority . getInstance ( ( index + 1 ) * 100 ) ) ; }
This method takes the textual version of a priority and returns an appropriate instance of this class . Note that unrecognised values are treated as medium priority .
127
29
143,914
public static Duration add ( Duration a , Duration b , ProjectProperties defaults ) { if ( a == null && b == null ) { return null ; } if ( a == null ) { return b ; } if ( b == null ) { return a ; } TimeUnit unit = a . getUnits ( ) ; if ( b . getUnits ( ) != unit ) { b = b . convertUnits ( unit , defaults ) ; } return Duration . getInstance ( a . getDuration ( ) + b . getDuration ( ) , unit ) ; }
If a and b are not null returns a new duration of a + b . If a is null and b is not null returns b . If a is not null and b is null returns a . If a and b are null returns null . If needed b is converted to a s time unit using the project properties .
117
64
143,915
public static ProjectReader getProjectReader ( String name ) throws MPXJException { int index = name . lastIndexOf ( ' ' ) ; if ( index == - 1 ) { throw new IllegalArgumentException ( "Filename has no extension: " + name ) ; } String extension = name . substring ( index + 1 ) . toUpperCase ( ) ; Class < ? extends ProjectReader > fileClass = READER_MAP . get ( extension ) ; if ( fileClass == null ) { throw new IllegalArgumentException ( "Cannot read files of type: " + extension ) ; } try { ProjectReader file = fileClass . newInstance ( ) ; return ( file ) ; } catch ( Exception ex ) { throw new MPXJException ( "Failed to load project reader" , ex ) ; } }
Retrieves a ProjectReader instance which can read a file of the type specified by the supplied file name .
173
22
143,916
private void processCalendars ( ) throws SQLException { for ( ResultSetRow row : getRows ( "SELECT * FROM MSP_CALENDARS WHERE PROJ_ID=?" , m_projectID ) ) { processCalendar ( row ) ; } updateBaseCalendarNames ( ) ; processCalendarData ( m_project . getCalendars ( ) ) ; }
Select calendar data from the database .
83
7
143,917
private void processCalendarData ( List < ProjectCalendar > calendars ) throws SQLException { for ( ProjectCalendar calendar : calendars ) { processCalendarData ( calendar , getRows ( "SELECT * FROM MSP_CALENDAR_DATA WHERE PROJ_ID=? AND CAL_UID=?" , m_projectID , calendar . getUniqueID ( ) ) ) ; } }
Process calendar hours and exception data from the database .
86
10
143,918
private void processCalendarData ( ProjectCalendar calendar , List < ResultSetRow > calendarData ) { for ( ResultSetRow row : calendarData ) { processCalendarData ( calendar , row ) ; } }
Process the hours and exceptions for an individual calendar .
45
10
143,919
private void processSubProjects ( ) { int subprojectIndex = 1 ; for ( Task task : m_project . getTasks ( ) ) { String subProjectFileName = task . getSubprojectName ( ) ; if ( subProjectFileName != null ) { String fileName = subProjectFileName ; int offset = 0x01000000 + ( subprojectIndex * 0x00400000 ) ; int index = subProjectFileName . lastIndexOf ( ' ' ) ; if ( index != - 1 ) { fileName = subProjectFileName . substring ( index + 1 ) ; } SubProject sp = new SubProject ( ) ; sp . setFileName ( fileName ) ; sp . setFullPath ( subProjectFileName ) ; sp . setUniqueIDOffset ( Integer . valueOf ( offset ) ) ; sp . setTaskUniqueID ( task . getUniqueID ( ) ) ; task . setSubProject ( sp ) ; ++ subprojectIndex ; } } }
The only indication that a task is a SubProject is the contents of the subproject file name field . We test these here then add a skeleton subproject structure to match the way we do things with MPP files .
208
44
143,920
private void processOutlineCodeFields ( Row parentRow ) throws SQLException { Integer entityID = parentRow . getInteger ( "CODE_REF_UID" ) ; Integer outlineCodeEntityID = parentRow . getInteger ( "CODE_UID" ) ; for ( ResultSetRow row : getRows ( "SELECT * FROM MSP_OUTLINE_CODES WHERE CODE_UID=?" , outlineCodeEntityID ) ) { processOutlineCodeField ( entityID , row ) ; } }
Process a single outline code .
111
6
143,921
private void allocateConnection ( ) throws SQLException { if ( m_connection == null ) { m_connection = m_dataSource . getConnection ( ) ; m_allocatedConnection = true ; queryDatabaseMetaData ( ) ; } }
Allocates a database connection .
52
7
143,922
private void queryDatabaseMetaData ( ) { ResultSet rs = null ; try { Set < String > tables = new HashSet < String > ( ) ; DatabaseMetaData dmd = m_connection . getMetaData ( ) ; rs = dmd . getTables ( null , null , null , null ) ; while ( rs . next ( ) ) { tables . add ( rs . getString ( "TABLE_NAME" ) ) ; } m_hasResourceBaselines = tables . contains ( "MSP_RESOURCE_BASELINES" ) ; m_hasTaskBaselines = tables . contains ( "MSP_TASK_BASELINES" ) ; m_hasAssignmentBaselines = tables . contains ( "MSP_ASSIGNMENT_BASELINES" ) ; } catch ( Exception ex ) { // Ignore errors when reading meta data } finally { if ( rs != null ) { try { rs . close ( ) ; } catch ( SQLException ex ) { // Ignore errors when closing result set } rs = null ; } } }
Queries database meta data to check for the existence of specific tables .
231
14
143,923
public static final UUID parseUUID ( String value ) { UUID result = null ; if ( value != null && ! value . isEmpty ( ) ) { if ( value . charAt ( 0 ) == ' ' ) { // PMXML representation: <GUID>{0AB9133E-A09A-9648-B98A-B2384894AC44}</GUID> result = UUID . fromString ( value . substring ( 1 , value . length ( ) - 1 ) ) ; } else { // XER representation: CrkTPqCalki5irI4SJSsRA byte [ ] data = javax . xml . bind . DatatypeConverter . parseBase64Binary ( value + "==" ) ; long msb = 0 ; long lsb = 0 ; for ( int i = 0 ; i < 8 ; i ++ ) { msb = ( msb << 8 ) | ( data [ i ] & 0xff ) ; } for ( int i = 8 ; i < 16 ; i ++ ) { lsb = ( lsb << 8 ) | ( data [ i ] & 0xff ) ; } result = new UUID ( msb , lsb ) ; } } return result ; }
Convert the Primavera string representation of a UUID into a Java UUID instance .
271
20
143,924
public static String printUUID ( UUID guid ) { return guid == null ? null : "{" + guid . toString ( ) . toUpperCase ( ) + "}" ; }
Retrieve a UUID in the form required by Primavera PMXML .
40
18
143,925
public static final String printTime ( Date value ) { return ( value == null ? null : TIME_FORMAT . get ( ) . format ( value ) ) ; }
Print a time value .
35
5
143,926
public void renumberUniqueIDs ( ) { int uid = firstUniqueID ( ) ; for ( T entity : this ) { entity . setUniqueID ( Integer . valueOf ( uid ++ ) ) ; } }
Renumbers all entity unique IDs .
46
7
143,927
public void validateUniqueIDsForMicrosoftProject ( ) { if ( ! isEmpty ( ) ) { for ( T entity : this ) { if ( NumberHelper . getInt ( entity . getUniqueID ( ) ) > MS_PROJECT_MAX_UNIQUE_ID ) { renumberUniqueIDs ( ) ; break ; } } } }
Validate that the Unique IDs for the entities in this container are valid for MS Project . If they are not valid i . e one or more of them are too large renumber them .
72
38
143,928
private void readDefinitions ( ) { for ( MapRow row : m_tables . get ( "TTL" ) ) { Integer id = row . getInteger ( "DEFINITION_ID" ) ; List < MapRow > list = m_definitions . get ( id ) ; if ( list == null ) { list = new ArrayList < MapRow > ( ) ; m_definitions . put ( id , list ) ; } list . add ( row ) ; } List < MapRow > rows = m_definitions . get ( WBS_FORMAT_ID ) ; if ( rows != null ) { m_wbsFormat = new SureTrakWbsFormat ( rows . get ( 0 ) ) ; } }
Extract definition records from the table and divide into groups .
156
12
143,929
private void readCalendars ( ) { Table cal = m_tables . get ( "CAL" ) ; for ( MapRow row : cal ) { ProjectCalendar calendar = m_projectFile . addCalendar ( ) ; m_calendarMap . put ( row . getInteger ( "CALENDAR_ID" ) , calendar ) ; Integer [ ] days = { row . getInteger ( "SUNDAY_HOURS" ) , row . getInteger ( "MONDAY_HOURS" ) , row . getInteger ( "TUESDAY_HOURS" ) , row . getInteger ( "WEDNESDAY_HOURS" ) , row . getInteger ( "THURSDAY_HOURS" ) , row . getInteger ( "FRIDAY_HOURS" ) , row . getInteger ( "SATURDAY_HOURS" ) } ; calendar . setName ( row . getString ( "NAME" ) ) ; readHours ( calendar , Day . SUNDAY , days [ 0 ] ) ; readHours ( calendar , Day . MONDAY , days [ 1 ] ) ; readHours ( calendar , Day . TUESDAY , days [ 2 ] ) ; readHours ( calendar , Day . WEDNESDAY , days [ 3 ] ) ; readHours ( calendar , Day . THURSDAY , days [ 4 ] ) ; readHours ( calendar , Day . FRIDAY , days [ 5 ] ) ; readHours ( calendar , Day . SATURDAY , days [ 6 ] ) ; int workingDaysPerWeek = 0 ; for ( Day day : Day . values ( ) ) { if ( calendar . isWorkingDay ( day ) ) { ++ workingDaysPerWeek ; } } Integer workingHours = null ; for ( int index = 0 ; index < 7 ; index ++ ) { if ( days [ index ] . intValue ( ) != 0 ) { workingHours = days [ index ] ; break ; } } if ( workingHours != null ) { int workingHoursPerDay = countHours ( workingHours ) ; int minutesPerDay = workingHoursPerDay * 60 ; int minutesPerWeek = minutesPerDay * workingDaysPerWeek ; int minutesPerMonth = 4 * minutesPerWeek ; int minutesPerYear = 52 * minutesPerWeek ; calendar . setMinutesPerDay ( Integer . valueOf ( minutesPerDay ) ) ; calendar . setMinutesPerWeek ( Integer . valueOf ( minutesPerWeek ) ) ; calendar . setMinutesPerMonth ( Integer . valueOf ( minutesPerMonth ) ) ; calendar . setMinutesPerYear ( Integer . valueOf ( minutesPerYear ) ) ; } } }
Read project calendars .
562
4
143,930
private void readHours ( ProjectCalendar calendar , Day day , Integer hours ) { int value = hours . intValue ( ) ; int startHour = 0 ; ProjectCalendarHours calendarHours = null ; Calendar cal = DateHelper . popCalendar ( ) ; cal . set ( Calendar . HOUR_OF_DAY , 0 ) ; cal . set ( Calendar . MINUTE , 0 ) ; cal . set ( Calendar . SECOND , 0 ) ; cal . set ( Calendar . MILLISECOND , 0 ) ; calendar . setWorkingDay ( day , false ) ; while ( value != 0 ) { // Move forward until we find a working hour while ( startHour < 24 && ( value & 0x1 ) == 0 ) { value = value >> 1 ; ++ startHour ; } // No more working hours, bail out if ( startHour >= 24 ) { break ; } // Move forward until we find the end of the working hours int endHour = startHour ; while ( endHour < 24 && ( value & 0x1 ) != 0 ) { value = value >> 1 ; ++ endHour ; } cal . set ( Calendar . HOUR_OF_DAY , startHour ) ; Date startDate = cal . getTime ( ) ; cal . set ( Calendar . HOUR_OF_DAY , endHour ) ; Date endDate = cal . getTime ( ) ; if ( calendarHours == null ) { calendarHours = calendar . addCalendarHours ( day ) ; calendar . setWorkingDay ( day , true ) ; } calendarHours . addRange ( new DateRange ( startDate , endDate ) ) ; startHour = endHour ; } DateHelper . pushCalendar ( cal ) ; }
Reads the integer representation of calendar hours for a given day and populates the calendar .
356
18
143,931
private int countHours ( Integer hours ) { int value = hours . intValue ( ) ; int hoursPerDay = 0 ; int hour = 0 ; while ( value > 0 ) { // Move forward until we find a working hour while ( hour < 24 ) { if ( ( value & 0x1 ) != 0 ) { ++ hoursPerDay ; } value = value >> 1 ; ++ hour ; } } return hoursPerDay ; }
Count the number of working hours in a day based in the integer representation of the working hours .
90
19
143,932
private void readHolidays ( ) { for ( MapRow row : m_tables . get ( "HOL" ) ) { ProjectCalendar calendar = m_calendarMap . get ( row . getInteger ( "CALENDAR_ID" ) ) ; if ( calendar != null ) { Date date = row . getDate ( "DATE" ) ; ProjectCalendarException exception = calendar . addCalendarException ( date , date ) ; if ( row . getBoolean ( "ANNUAL" ) ) { RecurringData recurring = new RecurringData ( ) ; recurring . setRecurrenceType ( RecurrenceType . YEARLY ) ; recurring . setYearlyAbsoluteFromDate ( date ) ; recurring . setStartDate ( date ) ; exception . setRecurring ( recurring ) ; // TODO set end date based on project end date } } } }
Read holidays from the database and create calendar exceptions .
185
10
143,933
private void readActivities ( ) { List < MapRow > items = new ArrayList < MapRow > ( ) ; for ( MapRow row : m_tables . get ( "ACT" ) ) { items . add ( row ) ; } final AlphanumComparator comparator = new AlphanumComparator ( ) ; Collections . sort ( items , new Comparator < MapRow > ( ) { @ Override public int compare ( MapRow o1 , MapRow o2 ) { return comparator . compare ( o1 . getString ( "ACTIVITY_ID" ) , o2 . getString ( "ACTIVITY_ID" ) ) ; } } ) ; for ( MapRow row : items ) { String activityID = row . getString ( "ACTIVITY_ID" ) ; String wbs ; if ( m_wbsFormat == null ) { wbs = null ; } else { m_wbsFormat . parseRawValue ( row . getString ( "WBS" ) ) ; wbs = m_wbsFormat . getFormattedValue ( ) ; } ChildTaskContainer parent = m_wbsMap . get ( wbs ) ; if ( parent == null ) { parent = m_projectFile ; } Task task = parent . addTask ( ) ; setFields ( TASK_FIELDS , row , task ) ; task . setStart ( task . getEarlyStart ( ) ) ; task . setFinish ( task . getEarlyFinish ( ) ) ; task . setMilestone ( task . getDuration ( ) . getDuration ( ) == 0 ) ; task . setWBS ( wbs ) ; Duration duration = task . getDuration ( ) ; Duration remainingDuration = task . getRemainingDuration ( ) ; task . setActualDuration ( Duration . getInstance ( duration . getDuration ( ) - remainingDuration . getDuration ( ) , TimeUnit . HOURS ) ) ; m_activityMap . put ( activityID , task ) ; } }
Read activities .
425
3
143,934
public void process ( Resource resource , int index , byte [ ] data ) { CostRateTable result = new CostRateTable ( ) ; if ( data != null ) { for ( int i = 16 ; i + 44 <= data . length ; i += 44 ) { Rate standardRate = new Rate ( MPPUtility . getDouble ( data , i ) , TimeUnit . HOURS ) ; TimeUnit standardRateFormat = getFormat ( MPPUtility . getShort ( data , i + 8 ) ) ; Rate overtimeRate = new Rate ( MPPUtility . getDouble ( data , i + 16 ) , TimeUnit . HOURS ) ; TimeUnit overtimeRateFormat = getFormat ( MPPUtility . getShort ( data , i + 24 ) ) ; Double costPerUse = NumberHelper . getDouble ( MPPUtility . getDouble ( data , i + 32 ) / 100.0 ) ; Date endDate = MPPUtility . getTimestampFromTenths ( data , i + 40 ) ; CostRateTableEntry entry = new CostRateTableEntry ( standardRate , standardRateFormat , overtimeRate , overtimeRateFormat , costPerUse , endDate ) ; result . add ( entry ) ; } Collections . sort ( result ) ; } else { // // MS Project economises by not actually storing the first cost rate // table if it doesn't need to, so we take this into account here. // if ( index == 0 ) { Rate standardRate = resource . getStandardRate ( ) ; Rate overtimeRate = resource . getOvertimeRate ( ) ; Number costPerUse = resource . getCostPerUse ( ) ; CostRateTableEntry entry = new CostRateTableEntry ( standardRate , standardRate . getUnits ( ) , overtimeRate , overtimeRate . getUnits ( ) , costPerUse , CostRateTableEntry . DEFAULT_ENTRY . getEndDate ( ) ) ; result . add ( entry ) ; } else { result . add ( CostRateTableEntry . DEFAULT_ENTRY ) ; } } resource . setCostRateTable ( index , result ) ; }
Creates a CostRateTable instance from a block of data .
446
13
143,935
private TimeUnit getFormat ( int format ) { TimeUnit result ; if ( format == 0xFFFF ) { result = TimeUnit . HOURS ; } else { result = MPPUtility . getWorkTimeUnits ( format ) ; } return result ; }
Converts an integer into a time format .
55
9
143,936
public static ConstraintType getInstance ( Locale locale , String type ) { int index = 0 ; String [ ] constraintTypes = LocaleData . getStringArray ( locale , LocaleData . CONSTRAINT_TYPES ) ; for ( int loop = 0 ; loop < constraintTypes . length ; loop ++ ) { if ( constraintTypes [ loop ] . equalsIgnoreCase ( type ) == true ) { index = loop ; break ; } } return ( ConstraintType . getInstance ( index ) ) ; }
This method takes the textual version of a constraint name and returns an appropriate class instance . Note that unrecognised values are treated as As Soon As Possible constraints .
112
31
143,937
private static void query ( String filename ) throws Exception { ProjectFile mpx = new UniversalProjectReader ( ) . read ( filename ) ; listProjectProperties ( mpx ) ; listResources ( mpx ) ; listTasks ( mpx ) ; listAssignments ( mpx ) ; listAssignmentsByTask ( mpx ) ; listAssignmentsByResource ( mpx ) ; listHierarchy ( mpx ) ; listTaskNotes ( mpx ) ; listResourceNotes ( mpx ) ; listRelationships ( mpx ) ; listSlack ( mpx ) ; listCalendars ( mpx ) ; }
This method performs a set of queries to retrieve information from the an MPP or an MPX file .
133
21
143,938
private static void listProjectProperties ( ProjectFile file ) { SimpleDateFormat df = new SimpleDateFormat ( "dd/MM/yyyy HH:mm z" ) ; ProjectProperties properties = file . getProjectProperties ( ) ; Date startDate = properties . getStartDate ( ) ; Date finishDate = properties . getFinishDate ( ) ; String formattedStartDate = startDate == null ? "(none)" : df . format ( startDate ) ; String formattedFinishDate = finishDate == null ? "(none)" : df . format ( finishDate ) ; System . out . println ( "MPP file type: " + properties . getMppFileType ( ) ) ; System . out . println ( "Project Properties: StartDate=" + formattedStartDate + " FinishDate=" + formattedFinishDate ) ; System . out . println ( ) ; }
Reads basic summary details from the project properties .
181
10
143,939
private static void listResources ( ProjectFile file ) { for ( Resource resource : file . getResources ( ) ) { System . out . println ( "Resource: " + resource . getName ( ) + " (Unique ID=" + resource . getUniqueID ( ) + ") Start=" + resource . getStart ( ) + " Finish=" + resource . getFinish ( ) ) ; } System . out . println ( ) ; }
This method lists all resources defined in the file .
90
10
143,940
private static void listTasks ( ProjectFile file ) { SimpleDateFormat df = new SimpleDateFormat ( "dd/MM/yyyy HH:mm z" ) ; for ( Task task : file . getTasks ( ) ) { Date date = task . getStart ( ) ; String text = task . getStartText ( ) ; String startDate = text != null ? text : ( date != null ? df . format ( date ) : "(no start date supplied)" ) ; date = task . getFinish ( ) ; text = task . getFinishText ( ) ; String finishDate = text != null ? text : ( date != null ? df . format ( date ) : "(no finish date supplied)" ) ; Duration dur = task . getDuration ( ) ; text = task . getDurationText ( ) ; String duration = text != null ? text : ( dur != null ? dur . toString ( ) : "(no duration supplied)" ) ; dur = task . getActualDuration ( ) ; String actualDuration = dur != null ? dur . toString ( ) : "(no actual duration supplied)" ; String baselineDuration = task . getBaselineDurationText ( ) ; if ( baselineDuration == null ) { dur = task . getBaselineDuration ( ) ; if ( dur != null ) { baselineDuration = dur . toString ( ) ; } else { baselineDuration = "(no duration supplied)" ; } } System . out . println ( "Task: " + task . getName ( ) + " ID=" + task . getID ( ) + " Unique ID=" + task . getUniqueID ( ) + " (Start Date=" + startDate + " Finish Date=" + finishDate + " Duration=" + duration + " Actual Duration" + actualDuration + " Baseline Duration=" + baselineDuration + " Outline Level=" + task . getOutlineLevel ( ) + " Outline Number=" + task . getOutlineNumber ( ) + " Recurring=" + task . getRecurring ( ) + ")" ) ; } System . out . println ( ) ; }
This method lists all tasks defined in the file .
434
10
143,941
private static void listHierarchy ( ProjectFile file ) { for ( Task task : file . getChildTasks ( ) ) { System . out . println ( "Task: " + task . getName ( ) + "\t" + task . getStart ( ) + "\t" + task . getFinish ( ) ) ; listHierarchy ( task , " " ) ; } System . out . println ( ) ; }
This method lists all tasks defined in the file in a hierarchical format reflecting the parent - child relationships between them .
90
22
143,942
private static void listHierarchy ( Task task , String indent ) { for ( Task child : task . getChildTasks ( ) ) { System . out . println ( indent + "Task: " + child . getName ( ) + "\t" + child . getStart ( ) + "\t" + child . getFinish ( ) ) ; listHierarchy ( child , indent + " " ) ; } }
Helper method called recursively to list child tasks .
88
11
143,943
private static void listAssignments ( ProjectFile file ) { Task task ; Resource resource ; String taskName ; String resourceName ; for ( ResourceAssignment assignment : file . getResourceAssignments ( ) ) { task = assignment . getTask ( ) ; if ( task == null ) { taskName = "(null task)" ; } else { taskName = task . getName ( ) ; } resource = assignment . getResource ( ) ; if ( resource == null ) { resourceName = "(null resource)" ; } else { resourceName = resource . getName ( ) ; } System . out . println ( "Assignment: Task=" + taskName + " Resource=" + resourceName ) ; if ( task != null ) { listTimephasedWork ( assignment ) ; } } System . out . println ( ) ; }
This method lists all resource assignments defined in the file .
172
11
143,944
private static void listTimephasedWork ( ResourceAssignment assignment ) { Task task = assignment . getTask ( ) ; int days = ( int ) ( ( task . getFinish ( ) . getTime ( ) - task . getStart ( ) . getTime ( ) ) / ( 1000 * 60 * 60 * 24 ) ) + 1 ; if ( days > 1 ) { SimpleDateFormat df = new SimpleDateFormat ( "dd/MM/yy" ) ; TimescaleUtility timescale = new TimescaleUtility ( ) ; ArrayList < DateRange > dates = timescale . createTimescale ( task . getStart ( ) , TimescaleUnits . DAYS , days ) ; TimephasedUtility timephased = new TimephasedUtility ( ) ; ArrayList < Duration > durations = timephased . segmentWork ( assignment . getCalendar ( ) , assignment . getTimephasedWork ( ) , TimescaleUnits . DAYS , dates ) ; for ( DateRange range : dates ) { System . out . print ( df . format ( range . getStart ( ) ) + "\t" ) ; } System . out . println ( ) ; for ( Duration duration : durations ) { System . out . print ( duration . toString ( ) + " " . substring ( 0 , 7 ) + "\t" ) ; } System . out . println ( ) ; } }
Dump timephased work for an assignment .
297
10
143,945
private static void listAssignmentsByTask ( ProjectFile file ) { for ( Task task : file . getTasks ( ) ) { System . out . println ( "Assignments for task " + task . getName ( ) + ":" ) ; for ( ResourceAssignment assignment : task . getResourceAssignments ( ) ) { Resource resource = assignment . getResource ( ) ; String resourceName ; if ( resource == null ) { resourceName = "(null resource)" ; } else { resourceName = resource . getName ( ) ; } System . out . println ( " " + resourceName ) ; } } System . out . println ( ) ; }
This method displays the resource assignments for each task . This time rather than just iterating through the list of all assignments in the file we extract the assignments on a task - by - task basis .
139
39
143,946
private static void listAssignmentsByResource ( ProjectFile file ) { for ( Resource resource : file . getResources ( ) ) { System . out . println ( "Assignments for resource " + resource . getName ( ) + ":" ) ; for ( ResourceAssignment assignment : resource . getTaskAssignments ( ) ) { Task task = assignment . getTask ( ) ; System . out . println ( " " + task . getName ( ) ) ; } } System . out . println ( ) ; }
This method displays the resource assignments for each resource . This time rather than just iterating through the list of all assignments in the file we extract the assignments on a resource - by - resource basis .
109
39
143,947
private static void listTaskNotes ( ProjectFile file ) { for ( Task task : file . getTasks ( ) ) { String notes = task . getNotes ( ) ; if ( notes . length ( ) != 0 ) { System . out . println ( "Notes for " + task . getName ( ) + ": " + notes ) ; } } System . out . println ( ) ; }
This method lists any notes attached to tasks .
83
9
143,948
private static void listResourceNotes ( ProjectFile file ) { for ( Resource resource : file . getResources ( ) ) { String notes = resource . getNotes ( ) ; if ( notes . length ( ) != 0 ) { System . out . println ( "Notes for " + resource . getName ( ) + ": " + notes ) ; } } System . out . println ( ) ; }
This method lists any notes attached to resources .
82
9
143,949
private static void listRelationships ( ProjectFile file ) { for ( Task task : file . getTasks ( ) ) { System . out . print ( task . getID ( ) ) ; System . out . print ( ' ' ) ; System . out . print ( task . getName ( ) ) ; System . out . print ( ' ' ) ; dumpRelationList ( task . getPredecessors ( ) ) ; System . out . print ( ' ' ) ; dumpRelationList ( task . getSuccessors ( ) ) ; System . out . println ( ) ; } }
This method lists task predecessor and successor relationships .
123
9
143,950
private static void dumpRelationList ( List < Relation > relations ) { if ( relations != null && relations . isEmpty ( ) == false ) { if ( relations . size ( ) > 1 ) { System . out . print ( ' ' ) ; } boolean first = true ; for ( Relation relation : relations ) { if ( ! first ) { System . out . print ( ' ' ) ; } first = false ; System . out . print ( relation . getTargetTask ( ) . getID ( ) ) ; Duration lag = relation . getLag ( ) ; if ( relation . getType ( ) != RelationType . FINISH_START || lag . getDuration ( ) != 0 ) { System . out . print ( relation . getType ( ) ) ; } if ( lag . getDuration ( ) != 0 ) { if ( lag . getDuration ( ) > 0 ) { System . out . print ( "+" ) ; } System . out . print ( lag ) ; } } if ( relations . size ( ) > 1 ) { System . out . print ( ' ' ) ; } } }
Internal utility to dump relationship lists in a structured format that can easily be compared with the tabular data in MS Project .
234
24
143,951
private static void listSlack ( ProjectFile file ) { for ( Task task : file . getTasks ( ) ) { System . out . println ( task . getName ( ) + " Total Slack=" + task . getTotalSlack ( ) + " Start Slack=" + task . getStartSlack ( ) + " Finish Slack=" + task . getFinishSlack ( ) ) ; } }
List the slack values for each task .
84
8
143,952
private static void listCalendars ( ProjectFile file ) { for ( ProjectCalendar cal : file . getCalendars ( ) ) { System . out . println ( cal . toString ( ) ) ; } }
List details of all calendars in the file .
44
9
143,953
public ProjectCalendar addDefaultBaseCalendar ( ) { ProjectCalendar calendar = add ( ) ; calendar . setName ( ProjectCalendar . DEFAULT_BASE_CALENDAR_NAME ) ; calendar . setWorkingDay ( Day . SUNDAY , false ) ; calendar . setWorkingDay ( Day . MONDAY , true ) ; calendar . setWorkingDay ( Day . TUESDAY , true ) ; calendar . setWorkingDay ( Day . WEDNESDAY , true ) ; calendar . setWorkingDay ( Day . THURSDAY , true ) ; calendar . setWorkingDay ( Day . FRIDAY , true ) ; calendar . setWorkingDay ( Day . SATURDAY , false ) ; calendar . addDefaultCalendarHours ( ) ; return ( calendar ) ; }
This is a convenience method used to add a calendar called Standard to the project and populate it with a default working week and default working hours .
166
28
143,954
public ProjectCalendar addDefaultDerivedCalendar ( ) { ProjectCalendar calendar = add ( ) ; calendar . setWorkingDay ( Day . SUNDAY , DayType . DEFAULT ) ; calendar . setWorkingDay ( Day . MONDAY , DayType . DEFAULT ) ; calendar . setWorkingDay ( Day . TUESDAY , DayType . DEFAULT ) ; calendar . setWorkingDay ( Day . WEDNESDAY , DayType . DEFAULT ) ; calendar . setWorkingDay ( Day . THURSDAY , DayType . DEFAULT ) ; calendar . setWorkingDay ( Day . FRIDAY , DayType . DEFAULT ) ; calendar . setWorkingDay ( Day . SATURDAY , DayType . DEFAULT ) ; return ( calendar ) ; }
This is a convenience method to add a default derived calendar to the project .
162
15
143,955
public ProjectCalendar getByName ( String calendarName ) { ProjectCalendar calendar = null ; if ( calendarName != null && calendarName . length ( ) != 0 ) { Iterator < ProjectCalendar > iter = iterator ( ) ; while ( iter . hasNext ( ) == true ) { calendar = iter . next ( ) ; String name = calendar . getName ( ) ; if ( ( name != null ) && ( name . equalsIgnoreCase ( calendarName ) == true ) ) { break ; } calendar = null ; } } return ( calendar ) ; }
Retrieves the named calendar . This method will return null if the named calendar is not located .
119
20
143,956
public ProjectFile read ( ) throws MPXJException { MPD9DatabaseReader reader = new MPD9DatabaseReader ( ) ; reader . setProjectID ( m_projectID ) ; reader . setPreserveNoteFormatting ( m_preserveNoteFormatting ) ; reader . setDataSource ( m_dataSource ) ; reader . setConnection ( m_connection ) ; ProjectFile project = reader . read ( ) ; return ( project ) ; }
Read project data from a database .
96
7
143,957
@ Override public ProjectFile read ( String accessDatabaseFileName ) throws MPXJException { try { Class . forName ( "sun.jdbc.odbc.JdbcOdbcDriver" ) ; String url = "jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb);DBQ=" + accessDatabaseFileName ; m_connection = DriverManager . getConnection ( url ) ; m_projectID = Integer . valueOf ( 1 ) ; return ( read ( ) ) ; } catch ( ClassNotFoundException ex ) { throw new MPXJException ( "Failed to load JDBC driver" , ex ) ; } catch ( SQLException ex ) { throw new MPXJException ( "Failed to create connection" , ex ) ; } finally { if ( m_connection != null ) { try { m_connection . close ( ) ; } catch ( SQLException ex ) { // silently ignore exceptions when closing connection } } } }
This is a convenience method which reads the first project from the named MPD file using the JDBC - ODBC bridge driver .
212
26
143,958
public static ProjectWriter getProjectWriter ( String name ) throws InstantiationException , IllegalAccessException { int index = name . lastIndexOf ( ' ' ) ; if ( index == - 1 ) { throw new IllegalArgumentException ( "Filename has no extension: " + name ) ; } String extension = name . substring ( index + 1 ) . toUpperCase ( ) ; Class < ? extends ProjectWriter > fileClass = WRITER_MAP . get ( extension ) ; if ( fileClass == null ) { throw new IllegalArgumentException ( "Cannot write files of type: " + name ) ; } ProjectWriter file = fileClass . newInstance ( ) ; return ( file ) ; }
Retrieves a ProjectWriter instance which can write a file of the type specified by the supplied file name .
148
22
143,959
private void processCustomFieldValues ( ) { byte [ ] data = m_projectProps . getByteArray ( Props . TASK_FIELD_ATTRIBUTES ) ; if ( data != null ) { int index = 0 ; int offset = 0 ; // First the length int length = MPPUtility . getInt ( data , offset ) ; offset += 4 ; // Then the number of custom value lists int numberOfValueLists = MPPUtility . getInt ( data , offset ) ; offset += 4 ; // Then the value lists themselves FieldType field ; int valueListOffset = 0 ; while ( index < numberOfValueLists && offset < length ) { // Each item consists of the Field ID (4 bytes) and the offset to the value list (4 bytes) // Get the Field field = FieldTypeHelper . getInstance ( MPPUtility . getInt ( data , offset ) ) ; offset += 4 ; // Get the value list offset valueListOffset = MPPUtility . getInt ( data , offset ) ; offset += 4 ; // Read the value list itself if ( valueListOffset < data . length ) { int tempOffset = valueListOffset ; tempOffset += 8 ; // Get the data offset int dataOffset = MPPUtility . getInt ( data , tempOffset ) + valueListOffset ; tempOffset += 4 ; // Get the end of the data offset int endDataOffset = MPPUtility . getInt ( data , tempOffset ) + valueListOffset ; tempOffset += 4 ; // Get the end of the description int endDescriptionOffset = MPPUtility . getInt ( data , tempOffset ) + valueListOffset ; // Get the values themselves int valuesLength = endDataOffset - dataOffset ; byte [ ] values = new byte [ valuesLength ] ; MPPUtility . getByteArray ( data , dataOffset , valuesLength , values , 0 ) ; // Get the descriptions int descriptionsLength = endDescriptionOffset - endDataOffset ; byte [ ] descriptions = new byte [ descriptionsLength ] ; MPPUtility . getByteArray ( data , endDataOffset , descriptionsLength , descriptions , 0 ) ; populateContainer ( field , values , descriptions ) ; } index ++ ; } } }
Reads non outline code custom field values and populates container .
472
13
143,960
private void processOutlineCodeValues ( ) throws IOException { DirectoryEntry outlineCodeDir = ( DirectoryEntry ) m_projectDir . getEntry ( "TBkndOutlCode" ) ; FixedMeta fm = new FixedMeta ( new DocumentInputStream ( ( ( DocumentEntry ) outlineCodeDir . getEntry ( "FixedMeta" ) ) ) , 10 ) ; FixedData fd = new FixedData ( fm , new DocumentInputStream ( ( ( DocumentEntry ) outlineCodeDir . getEntry ( "FixedData" ) ) ) ) ; Map < Integer , FieldType > map = new HashMap < Integer , FieldType > ( ) ; int items = fm . getItemCount ( ) ; for ( int loop = 0 ; loop < items ; loop ++ ) { byte [ ] data = fd . getByteArrayValue ( loop ) ; if ( data . length < 18 ) { continue ; } int index = MPPUtility . getShort ( data , 0 ) ; int fieldID = MPPUtility . getInt ( data , 12 ) ; FieldType fieldType = FieldTypeHelper . getInstance ( fieldID ) ; if ( fieldType . getFieldTypeClass ( ) != FieldTypeClass . UNKNOWN ) { map . put ( Integer . valueOf ( index ) , fieldType ) ; } } VarMeta outlineCodeVarMeta = new VarMeta9 ( new DocumentInputStream ( ( ( DocumentEntry ) outlineCodeDir . getEntry ( "VarMeta" ) ) ) ) ; Var2Data outlineCodeVarData = new Var2Data ( outlineCodeVarMeta , new DocumentInputStream ( ( ( DocumentEntry ) outlineCodeDir . getEntry ( "Var2Data" ) ) ) ) ; Map < FieldType , List < Pair < String , String > > > valueMap = new HashMap < FieldType , List < Pair < String , String > > > ( ) ; for ( Integer id : outlineCodeVarMeta . getUniqueIdentifierArray ( ) ) { FieldType fieldType = map . get ( id ) ; String value = outlineCodeVarData . getUnicodeString ( id , VALUE ) ; String description = outlineCodeVarData . getUnicodeString ( id , DESCRIPTION ) ; List < Pair < String , String > > list = valueMap . get ( fieldType ) ; if ( list == null ) { list = new ArrayList < Pair < String , String > > ( ) ; valueMap . put ( fieldType , list ) ; } list . add ( new Pair < String , String > ( value , description ) ) ; } for ( Entry < FieldType , List < Pair < String , String > > > entry : valueMap . entrySet ( ) ) { populateContainer ( entry . getKey ( ) , entry . getValue ( ) ) ; } }
Reads outline code custom field values and populates container .
593
12
143,961
private void populateContainer ( FieldType field , byte [ ] values , byte [ ] descriptions ) { CustomField config = m_container . getCustomField ( field ) ; CustomFieldLookupTable table = config . getLookupTable ( ) ; List < Object > descriptionList = convertType ( DataType . STRING , descriptions ) ; List < Object > valueList = convertType ( field . getDataType ( ) , values ) ; for ( int index = 0 ; index < descriptionList . size ( ) ; index ++ ) { CustomFieldValueItem item = new CustomFieldValueItem ( Integer . valueOf ( 0 ) ) ; item . setDescription ( ( String ) descriptionList . get ( index ) ) ; if ( index < valueList . size ( ) ) { item . setValue ( valueList . get ( index ) ) ; } table . add ( item ) ; } }
Populate the container converting raw data into Java types .
185
11
143,962
private void populateContainer ( FieldType field , List < Pair < String , String > > items ) { CustomField config = m_container . getCustomField ( field ) ; CustomFieldLookupTable table = config . getLookupTable ( ) ; for ( Pair < String , String > pair : items ) { CustomFieldValueItem item = new CustomFieldValueItem ( Integer . valueOf ( 0 ) ) ; item . setValue ( pair . getFirst ( ) ) ; item . setDescription ( pair . getSecond ( ) ) ; table . add ( item ) ; } }
Populate the container from outline code data .
121
9
143,963
private List < Object > convertType ( DataType type , byte [ ] data ) { List < Object > result = new ArrayList < Object > ( ) ; int index = 0 ; while ( index < data . length ) { switch ( type ) { case STRING : { String value = MPPUtility . getUnicodeString ( data , index ) ; result . add ( value ) ; index += ( ( value . length ( ) + 1 ) * 2 ) ; break ; } case CURRENCY : { Double value = Double . valueOf ( MPPUtility . getDouble ( data , index ) / 100 ) ; result . add ( value ) ; index += 8 ; break ; } case NUMERIC : { Double value = Double . valueOf ( MPPUtility . getDouble ( data , index ) ) ; result . add ( value ) ; index += 8 ; break ; } case DATE : { Date value = MPPUtility . getTimestamp ( data , index ) ; result . add ( value ) ; index += 4 ; break ; } case DURATION : { TimeUnit units = MPPUtility . getDurationTimeUnits ( MPPUtility . getShort ( data , index + 4 ) , m_properties . getDefaultDurationUnits ( ) ) ; Duration value = MPPUtility . getAdjustedDuration ( m_properties , MPPUtility . getInt ( data , index ) , units ) ; result . add ( value ) ; index += 6 ; break ; } case BOOLEAN : { Boolean value = Boolean . valueOf ( MPPUtility . getShort ( data , index ) == 1 ) ; result . add ( value ) ; index += 2 ; break ; } default : { index = data . length ; break ; } } } return result ; }
Convert raw data into Java types .
383
8
143,964
public boolean getBoolean ( FastTrackField type ) { boolean result = false ; Object value = getObject ( type ) ; if ( value != null ) { result = BooleanHelper . getBoolean ( ( Boolean ) value ) ; } return result ; }
Retrieve a boolean field .
53
6
143,965
public Date getTimestamp ( FastTrackField dateName , FastTrackField timeName ) { Date result = null ; Date date = getDate ( dateName ) ; if ( date != null ) { Calendar dateCal = DateHelper . popCalendar ( date ) ; Date time = getDate ( timeName ) ; if ( time != null ) { Calendar timeCal = DateHelper . popCalendar ( time ) ; dateCal . set ( Calendar . HOUR_OF_DAY , timeCal . get ( Calendar . HOUR_OF_DAY ) ) ; dateCal . set ( Calendar . MINUTE , timeCal . get ( Calendar . MINUTE ) ) ; dateCal . set ( Calendar . SECOND , timeCal . get ( Calendar . SECOND ) ) ; dateCal . set ( Calendar . MILLISECOND , timeCal . get ( Calendar . MILLISECOND ) ) ; DateHelper . pushCalendar ( timeCal ) ; } result = dateCal . getTime ( ) ; DateHelper . pushCalendar ( dateCal ) ; } return result ; }
Retrieve a timestamp field .
224
6
143,966
public Duration getDuration ( FastTrackField type ) { Double value = ( Double ) getObject ( type ) ; return value == null ? null : Duration . getInstance ( value . doubleValue ( ) , m_table . getDurationTimeUnit ( ) ) ; }
Retrieve a duration field .
55
6
143,967
public Duration getWork ( FastTrackField type ) { Double value = ( Double ) getObject ( type ) ; return value == null ? null : Duration . getInstance ( value . doubleValue ( ) , m_table . getWorkTimeUnit ( ) ) ; }
Retrieve a work field .
55
6
143,968
public UUID getUUID ( FastTrackField type ) { String value = getString ( type ) ; UUID result = null ; if ( value != null && ! value . isEmpty ( ) && value . length ( ) >= 36 ) { if ( value . startsWith ( "{" ) ) { value = value . substring ( 1 , value . length ( ) - 1 ) ; } if ( value . length ( ) > 16 ) { value = value . substring ( 0 , 36 ) ; } result = UUID . fromString ( value ) ; } return result ; }
Retrieve a UUID field .
122
7
143,969
public static CurrencySymbolPosition getSymbolPosition ( int value ) { CurrencySymbolPosition result ; switch ( value ) { case 1 : { result = CurrencySymbolPosition . AFTER ; break ; } case 2 : { result = CurrencySymbolPosition . BEFORE_WITH_SPACE ; break ; } case 3 : { result = CurrencySymbolPosition . AFTER_WITH_SPACE ; break ; } case 0 : default : { result = CurrencySymbolPosition . BEFORE ; break ; } } return ( result ) ; }
This method maps the currency symbol position from the representation used in the MPP file to the representation used by MPX .
111
24
143,970
public static final Duration getDuration ( double value , TimeUnit type ) { double duration ; // Value is given in 1/10 of minute switch ( type ) { case MINUTES : case ELAPSED_MINUTES : { duration = value / 10 ; break ; } case HOURS : case ELAPSED_HOURS : { duration = value / 600 ; // 60 * 10 break ; } case DAYS : { duration = value / 4800 ; // 8 * 60 * 10 break ; } case ELAPSED_DAYS : { duration = value / 14400 ; // 24 * 60 * 10 break ; } case WEEKS : { duration = value / 24000 ; // 5 * 8 * 60 * 10 break ; } case ELAPSED_WEEKS : { duration = value / 100800 ; // 7 * 24 * 60 * 10 break ; } case MONTHS : { duration = value / 96000 ; // 4 * 5 * 8 * 60 * 10 break ; } case ELAPSED_MONTHS : { duration = value / 432000 ; // 30 * 24 * 60 * 10 break ; } default : { duration = value ; break ; } } return ( Duration . getInstance ( duration , type ) ) ; }
Reads a duration value . This method relies on the fact that the units of the duration have been specified elsewhere .
260
23
143,971
public static void dumpRow ( Map < String , Object > row ) { for ( Entry < String , Object > entry : row . entrySet ( ) ) { Object value = entry . getValue ( ) ; System . out . println ( entry . getKey ( ) + " = " + value + " ( " + ( value == null ? "" : value . getClass ( ) . getName ( ) ) + ")" ) ; } }
Dump the contents of a row from an MPD file .
92
13
143,972
public void generateMapFile ( File jarFile , String mapFileName , boolean mapClassMethods ) throws XMLStreamException , IOException , ClassNotFoundException , IntrospectionException { m_responseList = new LinkedList < String > ( ) ; writeMapFile ( mapFileName , jarFile , mapClassMethods ) ; }
Generate a map file from a jar file .
69
10
143,973
private void writeMapFile ( String mapFileName , File jarFile , boolean mapClassMethods ) throws IOException , XMLStreamException , ClassNotFoundException , IntrospectionException { FileWriter fw = new FileWriter ( mapFileName ) ; XMLOutputFactory xof = XMLOutputFactory . newInstance ( ) ; XMLStreamWriter writer = xof . createXMLStreamWriter ( fw ) ; //XMLStreamWriter writer = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(fw)); writer . writeStartDocument ( ) ; writer . writeStartElement ( "root" ) ; writer . writeStartElement ( "assembly" ) ; addClasses ( writer , jarFile , mapClassMethods ) ; writer . writeEndElement ( ) ; writer . writeEndElement ( ) ; writer . writeEndDocument ( ) ; writer . flush ( ) ; writer . close ( ) ; fw . flush ( ) ; fw . close ( ) ; }
Generate an IKVM map file .
205
9
143,974
private void addClasses ( XMLStreamWriter writer , File jarFile , boolean mapClassMethods ) throws IOException , ClassNotFoundException , XMLStreamException , IntrospectionException { ClassLoader currentThreadClassLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; URLClassLoader loader = new URLClassLoader ( new URL [ ] { jarFile . toURI ( ) . toURL ( ) } , currentThreadClassLoader ) ; JarFile jar = new JarFile ( jarFile ) ; Enumeration < JarEntry > enumeration = jar . entries ( ) ; while ( enumeration . hasMoreElements ( ) ) { JarEntry jarEntry = enumeration . nextElement ( ) ; if ( ! jarEntry . isDirectory ( ) && jarEntry . getName ( ) . endsWith ( ".class" ) ) { addClass ( loader , jarEntry , writer , mapClassMethods ) ; } } jar . close ( ) ; }
Add classes to the map file .
199
7
143,975
private void addClass ( URLClassLoader loader , JarEntry jarEntry , XMLStreamWriter writer , boolean mapClassMethods ) throws ClassNotFoundException , XMLStreamException , IntrospectionException { String className = jarEntry . getName ( ) . replaceAll ( "\\.class" , "" ) . replaceAll ( "/" , "." ) ; writer . writeStartElement ( "class" ) ; writer . writeAttribute ( "name" , className ) ; Set < Method > methodSet = new HashSet < Method > ( ) ; Class < ? > aClass = loader . loadClass ( className ) ; processProperties ( writer , methodSet , aClass ) ; if ( mapClassMethods && ! Modifier . isInterface ( aClass . getModifiers ( ) ) ) { processClassMethods ( writer , aClass , methodSet ) ; } writer . writeEndElement ( ) ; }
Add an individual class to the map file .
189
9
143,976
private void processProperties ( XMLStreamWriter writer , Set < Method > methodSet , Class < ? > aClass ) throws IntrospectionException , XMLStreamException { BeanInfo beanInfo = Introspector . getBeanInfo ( aClass , aClass . getSuperclass ( ) ) ; PropertyDescriptor [ ] propertyDescriptors = beanInfo . getPropertyDescriptors ( ) ; for ( int i = 0 ; i < propertyDescriptors . length ; i ++ ) { PropertyDescriptor propertyDescriptor = propertyDescriptors [ i ] ; if ( propertyDescriptor . getPropertyType ( ) != null ) { String name = propertyDescriptor . getName ( ) ; Method readMethod = propertyDescriptor . getReadMethod ( ) ; Method writeMethod = propertyDescriptor . getWriteMethod ( ) ; String readMethodName = readMethod == null ? null : readMethod . getName ( ) ; String writeMethodName = writeMethod == null ? null : writeMethod . getName ( ) ; addProperty ( writer , name , propertyDescriptor . getPropertyType ( ) , readMethodName , writeMethodName ) ; if ( readMethod != null ) { methodSet . add ( readMethod ) ; } if ( writeMethod != null ) { methodSet . add ( writeMethod ) ; } } else { processAmbiguousProperty ( writer , methodSet , aClass , propertyDescriptor ) ; } } }
Process class properties .
307
4
143,977
private void addProperty ( XMLStreamWriter writer , String name , Class < ? > propertyType , String readMethod , String writeMethod ) throws XMLStreamException { if ( name . length ( ) != 0 ) { writer . writeStartElement ( "property" ) ; // convert property name to .NET style (i.e. first letter uppercase) String propertyName = name . substring ( 0 , 1 ) . toUpperCase ( ) + name . substring ( 1 ) ; writer . writeAttribute ( "name" , propertyName ) ; String type = getTypeString ( propertyType ) ; writer . writeAttribute ( "sig" , "()" + type ) ; if ( readMethod != null ) { writer . writeStartElement ( "getter" ) ; writer . writeAttribute ( "name" , readMethod ) ; writer . writeAttribute ( "sig" , "()" + type ) ; writer . writeEndElement ( ) ; } if ( writeMethod != null ) { writer . writeStartElement ( "setter" ) ; writer . writeAttribute ( "name" , writeMethod ) ; writer . writeAttribute ( "sig" , "(" + type + ")V" ) ; writer . writeEndElement ( ) ; } writer . writeEndElement ( ) ; } }
Add a simple property to the map file .
276
9
143,978
private String getTypeString ( Class < ? > c ) { String result = TYPE_MAP . get ( c ) ; if ( result == null ) { result = c . getName ( ) ; if ( ! result . endsWith ( ";" ) && ! result . startsWith ( "[" ) ) { result = "L" + result + ";" ; } } return result ; }
Converts a class into a signature token .
81
9
143,979
private void processClassMethods ( XMLStreamWriter writer , Class < ? > aClass , Set < Method > methodSet ) throws XMLStreamException { Method [ ] methods = aClass . getDeclaredMethods ( ) ; for ( Method method : methods ) { if ( ! methodSet . contains ( method ) && Modifier . isPublic ( method . getModifiers ( ) ) && ! Modifier . isInterface ( method . getModifiers ( ) ) ) { if ( Modifier . isStatic ( method . getModifiers ( ) ) ) { // TODO Handle static methods here } else { String name = method . getName ( ) ; String methodSignature = createMethodSignature ( method ) ; String fullJavaName = aClass . getCanonicalName ( ) + "." + name + methodSignature ; if ( ! ignoreMethod ( fullJavaName ) ) { // // Hide the original method // writer . writeStartElement ( "method" ) ; writer . writeAttribute ( "name" , name ) ; writer . writeAttribute ( "sig" , methodSignature ) ; writer . writeStartElement ( "attribute" ) ; writer . writeAttribute ( "type" , "System.ComponentModel.EditorBrowsableAttribute" ) ; writer . writeAttribute ( "sig" , "(Lcli.System.ComponentModel.EditorBrowsableState;)V" ) ; writer . writeStartElement ( "parameter" ) ; writer . writeCharacters ( "Never" ) ; writer . writeEndElement ( ) ; writer . writeEndElement ( ) ; writer . writeEndElement ( ) ; // // Create a wrapper method // name = name . toUpperCase ( ) . charAt ( 0 ) + name . substring ( 1 ) ; writer . writeStartElement ( "method" ) ; writer . writeAttribute ( "name" , name ) ; writer . writeAttribute ( "sig" , methodSignature ) ; writer . writeAttribute ( "modifiers" , "public" ) ; writer . writeStartElement ( "body" ) ; for ( int index = 0 ; index <= method . getParameterTypes ( ) . length ; index ++ ) { if ( index < 4 ) { writer . writeEmptyElement ( "ldarg_" + index ) ; } else { writer . writeStartElement ( "ldarg_s" ) ; writer . writeAttribute ( "argNum" , Integer . toString ( index ) ) ; writer . writeEndElement ( ) ; } } writer . writeStartElement ( "callvirt" ) ; writer . writeAttribute ( "class" , aClass . getName ( ) ) ; writer . writeAttribute ( "name" , method . getName ( ) ) ; writer . writeAttribute ( "sig" , methodSignature ) ; writer . writeEndElement ( ) ; if ( ! method . getReturnType ( ) . getName ( ) . equals ( "void" ) ) { writer . writeEmptyElement ( "ldnull" ) ; writer . writeEmptyElement ( "pop" ) ; } writer . writeEmptyElement ( "ret" ) ; writer . writeEndElement ( ) ; writer . writeEndElement ( ) ; /* * The private method approach doesn't work... so * 3. Add EditorBrowsableAttribute (Never) to original methods * 4. Generate C Sharp and VB variants of the DLL to avid case-sensitivity issues * 5. Implement static method support? <attribute type="System.ComponentModel.EditorBrowsableAttribute" sig="(Lcli.System.ComponentModel.EditorBrowsableState;)V"> 914 <parameter>Never</parameter> 915 </attribute> */ m_responseList . add ( fullJavaName ) ; } } } } }
Hides the original Java - style method name using an attribute which should be respected by Visual Studio the creates a new wrapper method using a . Net style method name .
796
33
143,980
private boolean ignoreMethod ( String name ) { boolean result = false ; for ( String ignoredName : IGNORED_METHODS ) { if ( name . matches ( ignoredName ) ) { result = true ; break ; } } return result ; }
Used to determine if the current method should be ignored .
50
11
143,981
private String createMethodSignature ( Method method ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "(" ) ; for ( Class < ? > type : method . getParameterTypes ( ) ) { sb . append ( getTypeString ( type ) ) ; } sb . append ( ")" ) ; Class < ? > type = method . getReturnType ( ) ; if ( type . getName ( ) . equals ( "void" ) ) { sb . append ( "V" ) ; } else { sb . append ( getTypeString ( type ) ) ; } return sb . toString ( ) ; }
Creates a method signature .
139
6
143,982
public boolean contains ( Date date ) { boolean result = false ; if ( date != null ) { result = ( DateHelper . compare ( getFromDate ( ) , getToDate ( ) , date ) == 0 ) ; } return ( result ) ; }
This method determines whether the given date falls in the range of dates covered by this exception . Note that this method assumes that both the start and end date of this exception have been set .
53
37
143,983
@ Override public void setModel ( TableModel model ) { super . setModel ( model ) ; int columns = model . getColumnCount ( ) ; TableColumnModel tableColumnModel = getColumnModel ( ) ; for ( int index = 0 ; index < columns ; index ++ ) { tableColumnModel . getColumn ( index ) . setPreferredWidth ( m_columnWidth ) ; } }
Updates the model . Ensures that we reset the columns widths .
83
15
143,984
@ Override public void process ( MPPReader reader , ProjectFile file , DirectoryEntry root ) throws MPXJException , IOException { try { populateMemberData ( reader , file , root ) ; processProjectProperties ( ) ; if ( ! reader . getReadPropertiesOnly ( ) ) { processSubProjectData ( ) ; processGraphicalIndicators ( ) ; processCustomValueLists ( ) ; processCalendarData ( ) ; processResourceData ( ) ; processTaskData ( ) ; processConstraintData ( ) ; processAssignmentData ( ) ; postProcessTasks ( ) ; if ( reader . getReadPresentationData ( ) ) { processViewPropertyData ( ) ; processTableData ( ) ; processViewData ( ) ; processFilterData ( ) ; processGroupData ( ) ; processSavedViewState ( ) ; } } } finally { clearMemberData ( ) ; } }
This method is used to process an MPP14 file . This is the file format used by Project 14 .
193
22
143,985
private void processGraphicalIndicators ( ) { GraphicalIndicatorReader graphicalIndicatorReader = new GraphicalIndicatorReader ( ) ; graphicalIndicatorReader . process ( m_file . getCustomFields ( ) , m_file . getProjectProperties ( ) , m_projectProps ) ; }
Process the graphical indicator data .
66
6
143,986
private void readSubProjects ( byte [ ] data , int uniqueIDOffset , int filePathOffset , int fileNameOffset , int subprojectIndex ) { while ( uniqueIDOffset < filePathOffset ) { readSubProject ( data , uniqueIDOffset , filePathOffset , fileNameOffset , subprojectIndex ++ ) ; uniqueIDOffset += 4 ; } }
Read a list of sub projects .
76
7
143,987
private void processBaseFonts ( byte [ ] data ) { int offset = 0 ; int blockCount = MPPUtility . getShort ( data , 0 ) ; offset += 2 ; int size ; String name ; for ( int loop = 0 ; loop < blockCount ; loop ++ ) { /*unknownAttribute = MPPUtility.getShort(data, offset);*/ offset += 2 ; size = MPPUtility . getShort ( data , offset ) ; offset += 2 ; name = MPPUtility . getUnicodeString ( data , offset ) ; offset += 64 ; if ( name . length ( ) != 0 ) { FontBase fontBase = new FontBase ( Integer . valueOf ( loop ) , name , size ) ; m_fontBases . put ( fontBase . getIndex ( ) , fontBase ) ; } } }
Create an index of base font numbers and their associated base font instances .
179
14
143,988
private TreeMap < Integer , Integer > createTaskMap ( FieldMap fieldMap , FixedMeta taskFixedMeta , FixedData taskFixedData , Var2Data taskVarData ) { TreeMap < Integer , Integer > taskMap = new TreeMap < Integer , Integer > ( ) ; int uniqueIdOffset = fieldMap . getFixedDataOffset ( TaskField . UNIQUE_ID ) ; Integer taskNameKey = fieldMap . getVarDataKey ( TaskField . NAME ) ; int itemCount = taskFixedMeta . getAdjustedItemCount ( ) ; int uniqueID ; Integer key ; // // First three items are not tasks, so let's skip them // for ( int loop = 3 ; loop < itemCount ; loop ++ ) { byte [ ] data = taskFixedData . getByteArrayValue ( loop ) ; if ( data != null ) { byte [ ] metaData = taskFixedMeta . getByteArrayValue ( loop ) ; // // Check for the deleted task flag // int flags = MPPUtility . getInt ( metaData , 0 ) ; if ( ( flags & 0x02 ) != 0 ) { // Project stores the deleted tasks unique id's into the fixed data as well // and at least in one case the deleted task was listed twice in the list // the second time with data with it causing a phantom task to be shown. // See CalendarErrorPhantomTasks.mpp // // So let's add the unique id for the deleted task into the map so we don't // accidentally include the task later. // uniqueID = MPPUtility . getShort ( data , TASK_UNIQUE_ID_FIXED_OFFSET ) ; // Only a short stored for deleted tasks? key = Integer . valueOf ( uniqueID ) ; if ( taskMap . containsKey ( key ) == false ) { taskMap . put ( key , null ) ; // use null so we can easily ignore this later } } else { // // Do we have a null task? // if ( data . length == NULL_TASK_BLOCK_SIZE ) { uniqueID = MPPUtility . getInt ( data , TASK_UNIQUE_ID_FIXED_OFFSET ) ; key = Integer . valueOf ( uniqueID ) ; if ( taskMap . containsKey ( key ) == false ) { taskMap . put ( key , Integer . valueOf ( loop ) ) ; } } else { // // We apply a heuristic here - if we have more than 75% of the data, we assume // the task is valid. // int maxSize = fieldMap . getMaxFixedDataSize ( 0 ) ; if ( maxSize == 0 || ( ( data . length * 100 ) / maxSize ) > 75 ) { uniqueID = MPPUtility . getInt ( data , uniqueIdOffset ) ; key = Integer . valueOf ( uniqueID ) ; // Accept this task if it does not have a deleted unique ID or it has a deleted unique ID but the name is not null if ( ! taskMap . containsKey ( key ) || taskVarData . getUnicodeString ( key , taskNameKey ) != null ) { taskMap . put ( key , Integer . valueOf ( loop ) ) ; } } } } } } return ( taskMap ) ; }
This method maps the task unique identifiers to their index number within the FixedData block .
696
17
143,989
private void postProcessTasks ( ) throws MPXJException { // // Renumber ID values using a large increment to allow // space for later inserts. // TreeMap < Integer , Integer > taskMap = new TreeMap < Integer , Integer > ( ) ; // I've found a pathological case of an MPP file with around 102k blank tasks... int nextIDIncrement = 102000 ; int nextID = ( m_file . getTaskByUniqueID ( Integer . valueOf ( 0 ) ) == null ? nextIDIncrement : 0 ) ; for ( Map . Entry < Long , Integer > entry : m_taskOrder . entrySet ( ) ) { taskMap . put ( Integer . valueOf ( nextID ) , entry . getValue ( ) ) ; nextID += nextIDIncrement ; } // // Insert any null tasks into the correct location // int insertionCount = 0 ; Map < Integer , Integer > offsetMap = new HashMap < Integer , Integer > ( ) ; for ( Map . Entry < Integer , Integer > entry : m_nullTaskOrder . entrySet ( ) ) { int idValue = entry . getKey ( ) . intValue ( ) ; int baseTargetIdValue = ( idValue - insertionCount ) * nextIDIncrement ; int targetIDValue = baseTargetIdValue ; Integer previousOffsetKey = Integer . valueOf ( baseTargetIdValue ) ; Integer previousOffset = offsetMap . get ( previousOffsetKey ) ; int offset = previousOffset == null ? 0 : previousOffset . intValue ( ) + 1 ; ++ insertionCount ; while ( taskMap . containsKey ( Integer . valueOf ( targetIDValue ) ) ) { ++ offset ; if ( offset == nextIDIncrement ) { throw new MPXJException ( "Unable to fix task order" ) ; } targetIDValue = baseTargetIdValue - ( nextIDIncrement - offset ) ; } offsetMap . put ( previousOffsetKey , Integer . valueOf ( offset ) ) ; taskMap . put ( Integer . valueOf ( targetIDValue ) , entry . getValue ( ) ) ; } // // Finally, we can renumber the tasks // nextID = ( m_file . getTaskByUniqueID ( Integer . valueOf ( 0 ) ) == null ? 1 : 0 ) ; for ( Map . Entry < Integer , Integer > entry : taskMap . entrySet ( ) ) { Task task = m_file . getTaskByUniqueID ( entry . getValue ( ) ) ; if ( task != null ) { task . setID ( Integer . valueOf ( nextID ) ) ; } nextID ++ ; } }
MPP14 files seem to exhibit some occasional weirdness with duplicate ID values which leads to the task structure being reported incorrectly . The following method attempts to correct this . The method uses ordering data embedded in the file to reconstruct the correct ID order of the tasks .
554
52
143,990
private void processHyperlinkData ( Resource resource , byte [ ] data ) { if ( data != null ) { int offset = 12 ; String hyperlink ; String address ; String subaddress ; offset += 12 ; hyperlink = MPPUtility . getUnicodeString ( data , offset ) ; offset += ( ( hyperlink . length ( ) + 1 ) * 2 ) ; offset += 12 ; address = MPPUtility . getUnicodeString ( data , offset ) ; offset += ( ( address . length ( ) + 1 ) * 2 ) ; offset += 12 ; subaddress = MPPUtility . getUnicodeString ( data , offset ) ; resource . setHyperlink ( hyperlink ) ; resource . setHyperlinkAddress ( address ) ; resource . setHyperlinkSubAddress ( subaddress ) ; } }
This method is used to extract the resource hyperlink attributes from a block of data and call the appropriate modifier methods to configure the specified task object .
174
29
143,991
private void readBitFields ( MppBitFlag [ ] flags , FieldContainer container , byte [ ] data ) { for ( MppBitFlag flag : flags ) { flag . setValue ( container , data ) ; } }
Iterate through a set of bit field flags and set the value for each one in the supplied container .
48
21
143,992
public void read ( InputStream is ) throws IOException { byte [ ] headerBlock = new byte [ 20 ] ; is . read ( headerBlock ) ; int headerLength = PEPUtility . getShort ( headerBlock , 8 ) ; int recordCount = PEPUtility . getInt ( headerBlock , 10 ) ; int recordLength = PEPUtility . getInt ( headerBlock , 16 ) ; StreamHelper . skip ( is , headerLength - headerBlock . length ) ; byte [ ] record = new byte [ recordLength ] ; for ( int recordIndex = 1 ; recordIndex <= recordCount ; recordIndex ++ ) { is . read ( record ) ; readRow ( recordIndex , record ) ; } }
Reads the table data from an input stream and breaks it down into rows .
151
16
143,993
protected void addRow ( int uniqueID , Map < String , Object > map ) { m_rows . put ( Integer . valueOf ( uniqueID ) , new MapRow ( map ) ) ; }
Adds a row to the internal storage indexed by primary key .
42
12
143,994
public List < TimephasedWork > getCompleteWork ( ProjectCalendar calendar , ResourceAssignment resourceAssignment , byte [ ] data ) { LinkedList < TimephasedWork > list = new LinkedList < TimephasedWork > ( ) ; if ( calendar != null && data != null && data . length > 2 && MPPUtility . getShort ( data , 0 ) > 0 ) { Date startDate = resourceAssignment . getStart ( ) ; double finishTime = MPPUtility . getInt ( data , 24 ) ; int blockCount = MPPUtility . getShort ( data , 0 ) ; double previousCumulativeWork = 0 ; TimephasedWork previousAssignment = null ; int index = 32 ; int currentBlock = 0 ; while ( currentBlock < blockCount && index + 20 <= data . length ) { double time = MPPUtility . getInt ( data , index + 0 ) ; // If the start of this block is before the start of the assignment, or after the end of the assignment // the values don't make sense, so we'll just set the start of this block to be the start of the assignment. // This deals with an issue where odd timephased data like this was causing an MPP file to be read // extremely slowly. if ( time < 0 || time > finishTime ) { time = 0 ; } else { time /= 80 ; } Duration startWork = Duration . getInstance ( time , TimeUnit . MINUTES ) ; double currentCumulativeWork = ( long ) MPPUtility . getDouble ( data , index + 4 ) ; double assignmentDuration = currentCumulativeWork - previousCumulativeWork ; previousCumulativeWork = currentCumulativeWork ; assignmentDuration /= 1000 ; Duration totalWork = Duration . getInstance ( assignmentDuration , TimeUnit . MINUTES ) ; time = ( long ) MPPUtility . getDouble ( data , index + 12 ) ; time /= 125 ; time *= 6 ; Duration workPerDay = Duration . getInstance ( time , TimeUnit . MINUTES ) ; Date start ; if ( startWork . getDuration ( ) == 0 ) { start = startDate ; } else { start = calendar . getDate ( startDate , startWork , true ) ; } TimephasedWork assignment = new TimephasedWork ( ) ; assignment . setStart ( start ) ; assignment . setAmountPerDay ( workPerDay ) ; assignment . setTotalAmount ( totalWork ) ; if ( previousAssignment != null ) { Date finish = calendar . getDate ( startDate , startWork , false ) ; previousAssignment . setFinish ( finish ) ; if ( previousAssignment . getStart ( ) . getTime ( ) == previousAssignment . getFinish ( ) . getTime ( ) ) { list . removeLast ( ) ; } } list . add ( assignment ) ; previousAssignment = assignment ; index += 20 ; ++ currentBlock ; } if ( previousAssignment != null ) { Duration finishWork = Duration . getInstance ( finishTime / 80 , TimeUnit . MINUTES ) ; Date finish = calendar . getDate ( startDate , finishWork , false ) ; previousAssignment . setFinish ( finish ) ; if ( previousAssignment . getStart ( ) . getTime ( ) == previousAssignment . getFinish ( ) . getTime ( ) ) { list . removeLast ( ) ; } } } return list ; }
Given a block of data representing completed work this method will retrieve a set of TimephasedWork instances which represent the day by day work carried out for a specific resource assignment .
732
35
143,995
public boolean getWorkModified ( List < TimephasedWork > list ) { boolean result = false ; for ( TimephasedWork assignment : list ) { result = assignment . getModified ( ) ; if ( result ) { break ; } } return result ; }
Test the list of TimephasedWork instances to see if any of them have been modified .
56
19
143,996
public TimephasedWorkContainer getBaselineWork ( ResourceAssignment assignment , ProjectCalendar calendar , TimephasedWorkNormaliser normaliser , byte [ ] data , boolean raw ) { TimephasedWorkContainer result = null ; if ( data != null && data . length > 0 ) { LinkedList < TimephasedWork > list = null ; //System.out.println(ByteArrayHelper.hexdump(data, false)); int index = 8 ; // 8 byte header int blockSize = 40 ; double previousCumulativeWorkPerformedInMinutes = 0 ; Date blockStartDate = MPPUtility . getTimestampFromTenths ( data , index + 36 ) ; index += blockSize ; TimephasedWork work = null ; while ( index + blockSize <= data . length ) { double cumulativeWorkInMinutes = ( double ) ( ( long ) MPPUtility . getDouble ( data , index + 20 ) ) / 1000 ; if ( ! Duration . durationValueEquals ( cumulativeWorkInMinutes , previousCumulativeWorkPerformedInMinutes ) ) { //double unknownWorkThisPeriodInMinutes = ((long) MPPUtility.getDouble(data, index + 0)) / 1000; double normalActualWorkThisPeriodInMinutes = ( ( double ) MPPUtility . getInt ( data , index + 8 ) ) / 10 ; double normalRemainingWorkThisPeriodInMinutes = ( ( double ) MPPUtility . getInt ( data , index + 28 ) ) / 10 ; double workThisPeriodInMinutes = cumulativeWorkInMinutes - previousCumulativeWorkPerformedInMinutes ; double overtimeWorkThisPeriodInMinutes = workThisPeriodInMinutes - ( normalActualWorkThisPeriodInMinutes + normalRemainingWorkThisPeriodInMinutes ) ; double overtimeFactor = overtimeWorkThisPeriodInMinutes / ( normalActualWorkThisPeriodInMinutes + normalRemainingWorkThisPeriodInMinutes ) ; double normalWorkPerDayInMinutes = 480 ; double overtimeWorkPerDayInMinutes = normalWorkPerDayInMinutes * overtimeFactor ; work = new TimephasedWork ( ) ; work . setFinish ( MPPUtility . getTimestampFromTenths ( data , index + 16 ) ) ; work . setStart ( blockStartDate ) ; work . setTotalAmount ( Duration . getInstance ( workThisPeriodInMinutes , TimeUnit . MINUTES ) ) ; work . setAmountPerDay ( Duration . getInstance ( normalWorkPerDayInMinutes + overtimeWorkPerDayInMinutes , TimeUnit . MINUTES ) ) ; previousCumulativeWorkPerformedInMinutes = cumulativeWorkInMinutes ; if ( list == null ) { list = new LinkedList < TimephasedWork > ( ) ; } list . add ( work ) ; //System.out.println(work); } blockStartDate = MPPUtility . getTimestampFromTenths ( data , index + 36 ) ; index += blockSize ; } if ( list != null ) { if ( work != null ) { work . setFinish ( assignment . getFinish ( ) ) ; } result = new DefaultTimephasedWorkContainer ( calendar , normaliser , list , raw ) ; } } return result ; }
Extracts baseline work from the MPP file for a specific baseline . Returns null if no baseline work is present otherwise returns a list of timephased work items .
720
34
143,997
public TimephasedCostContainer getBaselineCost ( ProjectCalendar calendar , TimephasedCostNormaliser normaliser , byte [ ] data , boolean raw ) { TimephasedCostContainer result = null ; if ( data != null && data . length > 0 ) { LinkedList < TimephasedCost > list = null ; //System.out.println(ByteArrayHelper.hexdump(data, false)); int index = 16 ; // 16 byte header int blockSize = 20 ; double previousTotalCost = 0 ; Date blockStartDate = MPPUtility . getTimestampFromTenths ( data , index + 16 ) ; index += blockSize ; while ( index + blockSize <= data . length ) { Date blockEndDate = MPPUtility . getTimestampFromTenths ( data , index + 16 ) ; double currentTotalCost = ( double ) ( ( long ) MPPUtility . getDouble ( data , index + 8 ) ) / 100 ; if ( ! costEquals ( previousTotalCost , currentTotalCost ) ) { TimephasedCost cost = new TimephasedCost ( ) ; cost . setStart ( blockStartDate ) ; cost . setFinish ( blockEndDate ) ; cost . setTotalAmount ( Double . valueOf ( currentTotalCost - previousTotalCost ) ) ; if ( list == null ) { list = new LinkedList < TimephasedCost > ( ) ; } list . add ( cost ) ; //System.out.println(cost); previousTotalCost = currentTotalCost ; } blockStartDate = blockEndDate ; index += blockSize ; } if ( list != null ) { result = new DefaultTimephasedCostContainer ( calendar , normaliser , list , raw ) ; } } return result ; }
Extracts baseline cost from the MPP file for a specific baseline . Returns null if no baseline cost is present otherwise returns a list of timephased work items .
374
34
143,998
public void processSplitData ( Task task , List < TimephasedWork > timephasedComplete , List < TimephasedWork > timephasedPlanned ) { Date splitsComplete = null ; TimephasedWork lastComplete = null ; TimephasedWork firstPlanned = null ; if ( ! timephasedComplete . isEmpty ( ) ) { lastComplete = timephasedComplete . get ( timephasedComplete . size ( ) - 1 ) ; splitsComplete = lastComplete . getFinish ( ) ; } if ( ! timephasedPlanned . isEmpty ( ) ) { firstPlanned = timephasedPlanned . get ( 0 ) ; } LinkedList < DateRange > splits = new LinkedList < DateRange > ( ) ; TimephasedWork lastAssignment = null ; DateRange lastRange = null ; for ( TimephasedWork assignment : timephasedComplete ) { if ( lastAssignment != null && lastRange != null && lastAssignment . getTotalAmount ( ) . getDuration ( ) != 0 && assignment . getTotalAmount ( ) . getDuration ( ) != 0 ) { splits . removeLast ( ) ; lastRange = new DateRange ( lastRange . getStart ( ) , assignment . getFinish ( ) ) ; } else { lastRange = new DateRange ( assignment . getStart ( ) , assignment . getFinish ( ) ) ; } splits . add ( lastRange ) ; lastAssignment = assignment ; } // // We may not have a split, we may just have a partially // complete split. // Date splitStart = null ; if ( lastComplete != null && firstPlanned != null && lastComplete . getTotalAmount ( ) . getDuration ( ) != 0 && firstPlanned . getTotalAmount ( ) . getDuration ( ) != 0 ) { lastRange = splits . removeLast ( ) ; splitStart = lastRange . getStart ( ) ; } lastAssignment = null ; lastRange = null ; for ( TimephasedWork assignment : timephasedPlanned ) { if ( splitStart == null ) { if ( lastAssignment != null && lastRange != null && lastAssignment . getTotalAmount ( ) . getDuration ( ) != 0 && assignment . getTotalAmount ( ) . getDuration ( ) != 0 ) { splits . removeLast ( ) ; lastRange = new DateRange ( lastRange . getStart ( ) , assignment . getFinish ( ) ) ; } else { lastRange = new DateRange ( assignment . getStart ( ) , assignment . getFinish ( ) ) ; } } else { lastRange = new DateRange ( splitStart , assignment . getFinish ( ) ) ; } splits . add ( lastRange ) ; splitStart = null ; lastAssignment = assignment ; } // // We must have a minimum of 3 entries for this to be a valid split task // if ( splits . size ( ) > 2 ) { task . getSplits ( ) . addAll ( splits ) ; task . setSplitCompleteDuration ( splitsComplete ) ; } else { task . setSplits ( null ) ; task . setSplitCompleteDuration ( null ) ; } }
Process the timephased resource assignment data to work out the split structure of the task .
659
18
143,999
private void updateScheduleSource ( ProjectProperties properties ) { // Rudimentary identification of schedule source if ( properties . getCompany ( ) != null && properties . getCompany ( ) . equals ( "Synchro Software Ltd" ) ) { properties . setFileApplication ( "Synchro" ) ; } else { if ( properties . getAuthor ( ) != null && properties . getAuthor ( ) . equals ( "SG Project" ) ) { properties . setFileApplication ( "Simple Genius" ) ; } else { properties . setFileApplication ( "Microsoft" ) ; } } properties . setFileType ( "MSPDI" ) ; }
Populate the properties indicating the source of this schedule .
135
11