srcanaapps/apiquerytool/com.nokia.s60tools.apiquery/src/com/nokia/s60tools/apiquery/shared/datatypes/APIShortDescriptionSearchResults.java
changeset 0 a02c979e8dfd
equal deleted inserted replaced
-1:000000000000 0:a02c979e8dfd
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17  
       
    18 package com.nokia.s60tools.apiquery.shared.datatypes;
       
    19 
       
    20 import java.util.ArrayList;
       
    21 import java.util.Collection;
       
    22 import java.util.Iterator;
       
    23 
       
    24 import com.nokia.s60tools.apiquery.shared.exceptions.QueryOperationFailedException;
       
    25 
       
    26 /**
       
    27  * Class for holding search results and search errors. 
       
    28  */
       
    29 public class APIShortDescriptionSearchResults {
       
    30 	
       
    31 	public APIShortDescriptionSearchResults(){
       
    32 		searchResults = new ArrayList<APIShortDescription>();
       
    33 		searchErrors = new ArrayList<QueryOperationFailedException>();
       
    34 	}
       
    35 	
       
    36 	/**
       
    37 	 * Search results
       
    38 	 */
       
    39 	private Collection<APIShortDescription> searchResults = null;
       
    40 	
       
    41 	/**
       
    42 	 * Search errors
       
    43 	 */
       
    44 	private Collection<QueryOperationFailedException> searchErrors = null;
       
    45 
       
    46 	/**
       
    47 	 * @return the searchResults
       
    48 	 */
       
    49 	public Collection<APIShortDescription> getSearchResults() {
       
    50 		return searchResults;
       
    51 	}
       
    52 
       
    53 	/**
       
    54 	 * @param searchResults the searchResults to set
       
    55 	 */
       
    56 	public void addSearchResults(Collection<APIShortDescription> searchResults) {
       
    57 		//Can't add null to results
       
    58 		if(searchResults != null){
       
    59 			this.searchResults.addAll(searchResults);
       
    60 		}
       
    61 	}
       
    62 
       
    63 	/**
       
    64 	 * Get errors occurred when queries was executed 
       
    65 	 * @return the searchErrors
       
    66 	 */
       
    67 	public Collection<QueryOperationFailedException> getSearchErrors() {
       
    68 		return searchErrors;
       
    69 	}
       
    70 
       
    71 	/**
       
    72 	 * Add one search error.
       
    73 	 * @param searchError
       
    74 	 */
       
    75 	public void addSearchError(QueryOperationFailedException searchError) {
       
    76 
       
    77 		if(searchError != null){
       
    78 			this.searchErrors.add(searchError);
       
    79 		}
       
    80 	}
       
    81 	
       
    82 	/**
       
    83 	 * Check if there was some errors whit queries.
       
    84 	 * @return <code>true</code> if there was some errors <code>false</code> otherwise. 
       
    85 	 */
       
    86 	public boolean hasErrors(){
       
    87 		return !this.searchErrors.isEmpty();
       
    88 	}
       
    89 	
       
    90 	/**
       
    91 	 * Get all error messages. One message takes one line, so if there is many errors there is as many lines of text also.
       
    92 	 * @return Errors as list or empty string if there was not any.
       
    93 	 */
       
    94 	public String getErrorMessages(){
       
    95 		if(!hasErrors()){
       
    96 			return new String();
       
    97 		}
       
    98 		else{
       
    99 			StringBuffer errors = new StringBuffer();
       
   100 			int count = searchErrors.size();
       
   101 			int i = 0;
       
   102 			for (Iterator<QueryOperationFailedException> iterator = searchErrors.iterator(); iterator.hasNext();) {
       
   103 				QueryOperationFailedException err = (QueryOperationFailedException) iterator.next();
       
   104 				errors.append(err.getMessage());
       
   105 				if(count > 1 && i < (count - 1)){
       
   106 					errors.append("\n");//$NON-NLS-1$
       
   107 				}
       
   108 				i++;
       
   109 			}
       
   110 			return errors.toString();
       
   111 		}
       
   112 	}
       
   113 
       
   114 }