src/org/ohmage/service/ObserverServices.java
public void removeDuplicates(
			final String username,
			final String observerId,
			final Collection<DataStream> data)
			throws ServiceException {
		
		try {
			// Get the IDs for each stream from this upload's data.
			Map<String, Collection<String>> uploadIds = 
				new HashMap<String, Collection<String>>();
			for(DataStream dataStream : data) {
				MetaData dataStreamMetaData = dataStream.getMetaData();
				
				if(dataStreamMetaData != null) {
					String id = dataStreamMetaData.getId();
				
					if(id != null) {
						Stream stream = dataStream.getStream();
						
						Collection<String> streamIds = 
							uploadIds.get(stream.getId());
						if(streamIds == null) {
							streamIds = new LinkedList<String>();
							uploadIds.put(stream.getId(), streamIds);
						}
						streamIds.add(id);
					}
				}
			}
			
			// Get the existing IDs for each stream that are also in this 
			// upload's IDs.
			Collection<String> duplicateIds = new HashSet<String>();
			for(String streamId : uploadIds.keySet()) {
				duplicateIds.addAll( 
					observerQueries.getDuplicateIds(
						username,
						observerId,
						streamId,
						uploadIds.get(streamId)));
			}
			
			// Remove any of this upload's IDs that already exist.
			Iterator<DataStream> dataIter = data.iterator();
			while(dataIter.hasNext()) {
				DataStream dataStream = dataIter.next();
				MetaData dataStreamMetaData = dataStream.getMetaData();
				
				if(dataStreamMetaData != null) {
					String id = dataStreamMetaData.getId();
				
					if((id != null) && (duplicateIds.contains(id))) {
						dataIter.remove();
					}
				}
			}
		}
		catch(DataAccessException e) {
			throw new ServiceException(e);
		}
	}
/**
	 * Prunes the duplicates from the collection of data elements. A duplicate
	 * is defined as a point with an ID whose ID already exists for the given
	 * user and for the associated stream. This will not remove duplicates in
	 * a single upload.
	 *  
	 * @param username The username of the user that will own these points.
	 * 
	 * @param observerId The observer's unique identifier.
	 * 
	 * @param data The data that has been uploaded.
	 * 
	 * @throws ServiceException There was an error.
	 */
Prunes the duplicates from the collection of data elements. A duplicate
is defined as a point with an ID whose ID already exists for the given
user and for the associated stream. This will not remove duplicates in
a single upload.

@param username The username of the user that will own these points.

@param observerId The observer's unique identifier.

@param data The data that has been uploaded.

@throws ServiceException There was an error.
Prunes the duplicates from the collection of data elements . A duplicate is defined as a point with an ID whose ID already exists for the given user and for the associated stream . This will not remove duplicates in a single upload . @param username The username of the user that will own these points . @param observerId The observer ' s unique identifier . @param data The data that has been uploaded . @throws ServiceException There was an error .
public void removeDuplicates(
			final String username,
			final String observerId,
			final Collection<DataStream> data)
			throws ServiceException {
		try {
			Map<String, Collection<String>> uploadIds = 
				new HashMap<String, Collection<String>>();
			for(DataStream dataStream : data) {
				MetaData dataStreamMetaData = dataStream.getMetaData();
				if(dataStreamMetaData != null) {
					String id = dataStreamMetaData.getId();
					if(id != null) {
						Stream stream = dataStream.getStream();
						Collection<String> streamIds = 
							uploadIds.get(stream.getId());
						if(streamIds == null) {
							streamIds = new LinkedList<String>();
							uploadIds.put(stream.getId(), streamIds);
						}
						streamIds.add(id);
					}
				}
			}
			Collection<String> duplicateIds = new HashSet<String>();
			for(String streamId : uploadIds.keySet()) {
				duplicateIds.addAll( 
					observerQueries.getDuplicateIds(
						username,
						observerId,
						streamId,
						uploadIds.get(streamId)));
			}
			Iterator<DataStream> dataIter = data.iterator();
			while(dataIter.hasNext()) {
				DataStream dataStream = dataIter.next();
				MetaData dataStreamMetaData = dataStream.getMetaData();
				if(dataStreamMetaData != null) {
					String id = dataStreamMetaData.getId();
					if((id != null) && (duplicateIds.contains(id))) {
						dataIter.remove();
					}
				}
			}
		}
		catch(DataAccessException e) {
			throw new ServiceException(e);
		}
	}
public void removeDuplicates ( final String username , final String observerId , final Collection < DataStream > data ) throws ServiceException { try { Map < String , Collection < String > > uploadIds = new HashMap < String , Collection < String > > ( ) ; for ( DataStream dataStream : data ) { MetaData dataStreamMetaData = dataStream . getMetaData ( ) ; if ( dataStreamMetaData != null ) { String id = dataStreamMetaData . getId ( ) ; if ( id != null ) { Stream stream = dataStream . getStream ( ) ; Collection < String > streamIds = uploadIds . get ( stream . getId ( ) ) ; if ( streamIds == null ) { streamIds = new LinkedList < String > ( ) ; uploadIds . put ( stream . getId ( ) , streamIds ) ; } streamIds . add ( id ) ; } } } Collection < String > duplicateIds = new HashSet < String > ( ) ; for ( String streamId : uploadIds . keySet ( ) ) { duplicateIds . addAll ( observerQueries . getDuplicateIds ( username , observerId , streamId , uploadIds . get ( streamId ) ) ) ; } Iterator < DataStream > dataIter = data . iterator ( ) ; while ( dataIter . hasNext ( ) ) { DataStream dataStream = dataIter . next ( ) ; MetaData dataStreamMetaData = dataStream . getMetaData ( ) ; if ( dataStreamMetaData != null ) { String id = dataStreamMetaData . getId ( ) ; if ( ( id != null ) && ( duplicateIds . contains ( id ) ) ) { dataIter . remove ( ) ; } } } } catch ( DataAccessException e ) { throw new ServiceException ( e ) ; } }
Prunes the duplicates from the collection of data elements.
Prunes the duplicates from the collection of data elements .
// Get the IDs for each stream from this upload's data. // Get the existing IDs for each stream that are also in this  // upload's IDs. // Remove any of this upload's IDs that already exist.