src/org/ohmage/domain/campaign/RepeatableSetResponse.java
@Override
	public JSONObject toJson(final boolean withId) throws JSONException {
		JSONObject result = new JSONObject();
		
		if(withId) {
			result.put(REPEATABLE_SET_ID, repeatableSet.getId());
		}
		// TODO: This is always true. This needs to be removed.
		result.put(SKIPPED, true);
		
		if(wasNotDisplayed()) {
			result.put(NOT_DISPLAYED, true);
		}
		else {
			result.put(NOT_DISPLAYED, false);

			List<Integer> iterations = new ArrayList<Integer>(responses.keySet());
			Collections.sort(iterations);

			JSONArray repeatableSetResponses = new JSONArray();
			for(Integer iteration : iterations) {
				Map<Integer, Response> iterationResponses = responses.get(iteration);
				List<Integer> indices = new ArrayList<Integer>(iterationResponses.keySet());
				Collections.sort(indices);
				
				if(withId) {
					JSONArray iterationResponse = new JSONArray();
					for(Integer index : indices) {
						iterationResponse.put(iterationResponses.get(index).toJson(true));
					}
					repeatableSetResponses.put(iterationResponse);
				}
				else {
					JSONObject iterationResponse = new JSONObject();
					for(Integer index : indices) {
						Response response = iterationResponses.get(index);
						iterationResponse.put(response.getId(), response.toJson(false));
					}
					repeatableSetResponses.put(iterationResponse);
				}
			}
			result.put(RESPONSES, repeatableSetResponses);
		}
		
		return result;
	}
/**
	 * Returns a JSONObject that represents the values of the responses in this
	 * repeatable set as well as the repeatable set itself.
	 * 
	 * @param withId Whether or not to include the prompt's ID in the result.
	 * 
	 * @return A JSONObject representing this repeatable set and all of the
	 * 		   prompt responses contained within it.
	 * 
	 * @throws JSONException There was a problem creating the JSONObject.
	 */
Returns a JSONObject that represents the values of the responses in this
repeatable set as well as the repeatable set itself.

@param withId Whether or not to include the prompt's ID in the result.

@return A JSONObject representing this repeatable set and all of the
prompt responses contained within it.

@throws JSONException There was a problem creating the JSONObject.
Returns a JSONObject that represents the values of the responses in this repeatable set as well as the repeatable set itself . @param withId Whether or not to include the prompt ' s ID in the result . @return A JSONObject representing this repeatable set and all of the prompt responses contained within it . @throws JSONException There was a problem creating the JSONObject .
@Override
	public JSONObject toJson(final boolean withId) throws JSONException {
		JSONObject result = new JSONObject();
		if(withId) {
			result.put(REPEATABLE_SET_ID, repeatableSet.getId());
		}
		result.put(SKIPPED, true);
		if(wasNotDisplayed()) {
			result.put(NOT_DISPLAYED, true);
		}
		else {
			result.put(NOT_DISPLAYED, false);
			List<Integer> iterations = new ArrayList<Integer>(responses.keySet());
			Collections.sort(iterations);
			JSONArray repeatableSetResponses = new JSONArray();
			for(Integer iteration : iterations) {
				Map<Integer, Response> iterationResponses = responses.get(iteration);
				List<Integer> indices = new ArrayList<Integer>(iterationResponses.keySet());
				Collections.sort(indices);
				if(withId) {
					JSONArray iterationResponse = new JSONArray();
					for(Integer index : indices) {
						iterationResponse.put(iterationResponses.get(index).toJson(true));
					}
					repeatableSetResponses.put(iterationResponse);
				}
				else {
					JSONObject iterationResponse = new JSONObject();
					for(Integer index : indices) {
						Response response = iterationResponses.get(index);
						iterationResponse.put(response.getId(), response.toJson(false));
					}
					repeatableSetResponses.put(iterationResponse);
				}
			}
			result.put(RESPONSES, repeatableSetResponses);
		}
		return result;
	}
@ Override public JSONObject toJson ( final boolean withId ) throws JSONException { JSONObject result = new JSONObject ( ) ; if ( withId ) { result . put ( REPEATABLE_SET_ID , repeatableSet . getId ( ) ) ; } result . put ( SKIPPED , true ) ; if ( wasNotDisplayed ( ) ) { result . put ( NOT_DISPLAYED , true ) ; } else { result . put ( NOT_DISPLAYED , false ) ; List < Integer > iterations = new ArrayList < Integer > ( responses . keySet ( ) ) ; Collections . sort ( iterations ) ; JSONArray repeatableSetResponses = new JSONArray ( ) ; for ( Integer iteration : iterations ) { Map < Integer , Response > iterationResponses = responses . get ( iteration ) ; List < Integer > indices = new ArrayList < Integer > ( iterationResponses . keySet ( ) ) ; Collections . sort ( indices ) ; if ( withId ) { JSONArray iterationResponse = new JSONArray ( ) ; for ( Integer index : indices ) { iterationResponse . put ( iterationResponses . get ( index ) . toJson ( true ) ) ; } repeatableSetResponses . put ( iterationResponse ) ; } else { JSONObject iterationResponse = new JSONObject ( ) ; for ( Integer index : indices ) { Response response = iterationResponses . get ( index ) ; iterationResponse . put ( response . getId ( ) , response . toJson ( false ) ) ; } repeatableSetResponses . put ( iterationResponse ) ; } } result . put ( RESPONSES , repeatableSetResponses ) ; } return result ; }
Returns a JSONObject that represents the values of the responses in this
 repeatable set as well as the repeatable set itself.
Returns a JSONObject that represents the values of the responses in this repeatable set as well as the repeatable set itself .
// TODO: This is always true. This needs to be removed.