@SuppressWarnings("deprecation")
	private static WriteConcern mergeWriteConcern(WriteConcern original, WriteConcern writeConcern) {
		if ( original == null ) {
			return writeConcern;
		}
		else if ( writeConcern == null ) {
			return original;
		}
		else if ( original.equals( writeConcern ) ) {
			return original;
		}

		Object wObject;
		int wTimeoutMS;
		boolean fsync;
		Boolean journal;

		if ( original.getWObject() instanceof String ) {
			wObject = original.getWString();
		}
		else if ( writeConcern.getWObject() instanceof String ) {
			wObject = writeConcern.getWString();
		}
		else {
			wObject = Math.max( original.getW(), writeConcern.getW() );
		}

		wTimeoutMS = Math.min( original.getWtimeout(), writeConcern.getWtimeout() );

		fsync = original.getFsync() || writeConcern.getFsync();

		if ( original.getJournal() == null ) {
			journal = writeConcern.getJournal();
		}
		else if ( writeConcern.getJournal() == null ) {
			journal = original.getJournal();
		}
		else {
			journal = original.getJournal() || writeConcern.getJournal();
		}

		if ( wObject instanceof String ) {
			return new WriteConcern( (String) wObject, wTimeoutMS, fsync, journal );
		}
		else {
			return new WriteConcern( (int) wObject, wTimeoutMS, fsync, journal );
		}
	}
@ SuppressWarnings ( "deprecation" ) private static WriteConcern mergeWriteConcern ( WriteConcern original , WriteConcern writeConcern ) { if ( original == null ) { return writeConcern ; } else if ( writeConcern == null ) { return original ; } else if ( original . equals ( writeConcern ) ) { return original ; } Object wObject ; int wTimeoutMS ; boolean fsync ; Boolean journal ; if ( original . getWObject ( ) instanceof String ) { wObject = original . getWString ( ) ; } else if ( writeConcern . getWObject ( ) instanceof String ) { wObject = writeConcern . getWString ( ) ; } else { wObject = Math . max ( original . getW ( ) , writeConcern . getW ( ) ) ; } wTimeoutMS = Math . min ( original . getWtimeout ( ) , writeConcern . getWtimeout ( ) ) ; fsync = original . getFsync ( ) || writeConcern . getFsync ( ) ; if ( original . getJournal ( ) == null ) { journal = writeConcern . getJournal ( ) ; } else if ( writeConcern . getJournal ( ) == null ) { journal = original . getJournal ( ) ; } else { journal = original . getJournal ( ) || writeConcern . getJournal ( ) ; } if ( wObject instanceof String ) { return new WriteConcern ( ( String ) wObject , wTimeoutMS , fsync , journal ) ; } else { return new WriteConcern ( ( int ) wObject , wTimeoutMS , fsync , journal ) ; } }
As we merge several operations into one operation, we need to be sure the write concern applied to the aggregated
operation respects all the requirements expressed for each separate operation.

Thus, for each parameter of the write concern, we keep the stricter one for the resulting merged write concern.