Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * #%L
   * Wikitty :: api
   * %%
   * Copyright (C) 2012 CodeLutin, Benjamin Poussin
   * %%
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as 
   * published by the Free Software Foundation, either version 3 of the 
  * License, or (at your option) any later version.
  * 
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Lesser Public License for more details.
  * 
  * You should have received a copy of the GNU General Lesser Public 
  * License along with this program.  If not, see
  * <http://www.gnu.org/licenses/lgpl-3.0.html>.
  * #L%
  */
 package org.nuiton.wikitty.query;
 
 import java.util.List;
 import java.util.Map;
Represente un resultat de requete WikittyQuery. Pour caster les valeurs dans une autre representation vous pouvez utiliser la methode org.nuiton.wikitty.WikittyClient.castTo(java.lang.Class,org.nuiton.wikitty.query.WikittyQueryResult)

Author(s):
poussin
Version:
$Revision$
Since:
3.3 Last update: $Date$ by : $Author$
 
 public class WikittyQueryResult<T> implements SerializableIterable<T> {

    
to use log facility, just put in your code: log.info(\"...\");
 
     static private Log log = LogFactory.getLog(WikittyQueryResult.class);
 
     private static final long serialVersionUID = 1L;

    
nom du critere qui a ete uitilise (peut-etre null) si le critete n'avait pas de nom
 
     protected String queryName;
    
indice of offset result in global search result
 
     protected int offset;
    
total number of result if we call the query for all possible result
 
     protected int totalResult;
    
query really executed (internal representation depend of search engine used
 
     protected String queryString;
    
query used to produce initial WikittyQueryResult
 
     protected WikittyQuery query;

    
list of result in the wanted interval
 
     protected List<T> results;
    
Wikitty ids resulting of where clause
 
     protected List<StringwikittyIdResult;
    
if query contains select clause, contains select result
 
     protected List<Map<StringObject>> selectResult;
    
facet asked or null if no facet
 
     protected Map<StringList<FacetTopic>> facets;

    
facet asked of null if no facet, FacetTopic are put in map with key topic name, To use this variable, you must used getter, because, this variable is lazy loaded from facets variable.
 
     transient protected Map<StringMap<StringFacetTopic>> facetsAsMap = null;

    
temps (nanoseconde) mis pour faire la requete (calcul cote serveur
 
     protected long timeQuery;
    
temps (nanoseconde) de transformation des resultats bruts en un autre type(calcul cote client
 
     protected long timeConvertion;


    
Init paged result. we don't initialize securityToken

Parameters:
offset indice element in global search result
totalResult total number of result if we call the query for all possible result
queryString query really executed
facets facet asked or null if no facet
results list of result in the wanted interval
    public WikittyQueryResult(String queryName,
            int offsetint totalResultWikittyQuery queryString queryString,
            List<T> results,
            List<Map<StringObject>> selectResult,
            List<StringwikittyIdResult,
            Map<StringList<FacetTopic>> facets
            long timeQuerylong timeConvertion) {
        this. = queryName;
        this. = offset;
        this. = totalResult;
        this. = query;
        this. = queryString;
        this. = Collections.unmodifiableList(results);
        this. = selectResult;
        this. = wikittyIdResult;
        this. = facets;
        this. = timeQuery;
        this. = timeConvertion;
    }

    
if this WikittyQueryResult contains Map<String, Object>, and each Map contains only one value, this methode return new WikittyQueryResult with value only (no more map). If this WikittyQueryResult don't contains Map, then this is returned

Returns:
    public <E> WikittyQueryResult<E> convertMapToSimple() {
         WikittyQueryResult<E> result;
        if (.isEmpty() || !(.get(0) instanceof Map)) {
            result = (WikittyQueryResult<E>)this;
        } else {
            List<E> data = new ArrayList<E>(.size());
            for (Map map : (List<Map>)) {
                if (map.size() != 1) {
                    throw new IllegalStateException(String.format(
                            "Map must have ONE element (currently %s"map.size()));
                }
                data.addAll(map.values());
            }
            result = new WikittyQueryResult<E>(
                    ,
                    data,
                    );
        }
        return result;
    }
         List dataObject = convertMapToSimple().getAll();
         List<Stringdata = new ArrayList<String>(dataObject.size());
         for (Object o : dataObject) {
             data.add(WikittyUtil.toString(o));
         }
         WikittyQueryResult<Stringresult = new WikittyQueryResult<String>(
                 ,
                 data,
                 );
        return result;
    }

    
nom du critere qui a ete uitilise (peut-etre null) si le critete n'avait pas de nom
    public String getQueryName() {
        return ;
    }

    

Deprecated:
since 3.5 use getOffset()
    @Deprecated
    public int getFirst() {
        return ;
    }

    
indice of offset result in global search result
    public int getOffset() {
        return ;
    }

    
total number of result if we call the query for all possible result
    public int getTotalResult() {
        return ;
    }

    
query really executed (internal representation depend of search engine used
    public String getQueryString() {
        return ;
    }

    
Return query used to initialise the first WikittyQueryResult (before some transformation with getSelect or getWikitties). This query is query realy send to server after some modification by WikittyClient if necessary

Returns:
Since:
3.10
    public WikittyQuery getQuery() {
        return ;
    }

    
retourne le nombre de wikitty actuellement disponible dans le resultat

Returns:
Since:
3.10
    public int getWikittyResultSize() {
        int result = 0;
        if ( != null) {
            result = .size();
        }
        return result;
    }

    
Retourne un nouveau WikittyQueryResult avec comme resultat la liste des ids des wikitties selectionnes par la Query initiale

Returns:
Since:
3.10
        WikittyQueryResult<Stringresult = new WikittyQueryResult<String>(
                ,
                ,
                );
        return result;
    }

    
Retourne un nouveau WikittyQueryResult avec comme resultat une liste de BusinessEntity du type de la class passee en parametre a partir des ids des wikitties selectionnes par la Query initiale

Returns:
Since:
3.10
    public <E extends BusinessEntityWikittyQueryResult<E> getWikittyResult(
            WikittyClient clientClass<E> clazz) {
        WikittyQueryResult<E> result = getWikittyResult().castTo(clientclazz);
        return result;
    }

    
Indique s'il y a des resultats de select on non

Returns:
Since:
3.10
    public boolean hasSelectResult() {
        boolean result = CollectionUtils.isNotEmpty();
        return result;
    }

    
Le nombre de map contenu dans le resultat de select

Returns:
Since:
3.10
    public int selectResultSize() {
        int result = 0;
        if (hasSelectResult()) {
            result = .size();
        }
        return result;
    }

    
Retourne la liste liste des noms disponible comme resulat de select

Returns:
Since:
3.10
    public List<StringgetSelectResultName() {
        List<Stringresult = null;
        if (hasSelectResult()) {
            Map<StringObjectfirst = .get(0);
            result = new ArrayList<String>(first.keySet());
        }
        return result;
    }

    
Retourne les resultats de select

Returns:
Since:
3.10
        WikittyQueryResult<Map<StringObject>> result = null;
        if (hasSelectResult()) {
            result = new WikittyQueryResult<Map<StringObject>>(
                    ,
                    ,
                    );
        }
        return result;
    }

    
Retourne les resultats de select transforme en objet de type clazz

Parameters:
<E>
client
clazz
Returns:
Since:
3.10
    public <E> WikittyQueryResult<Map<String, E>> getSelectResult(
            WikittyClient clientClass<E> clazz) {
        WikittyQueryResult<Map<String, E>> result = getSelectResult().castToMap(clientclazz);
        return result;
    }

    
Retourne les resultats de select pour le champs demande

Parameters:
resultName
Returns:
Since:
3.10
    public WikittyQueryResult<ObjectgetSelectResult(String resultName) {
        List<Objectdata = new ArrayList(selectResultSize());
        for (Map<StringObjectm : ) {
            data.add(m.get(resultName));
        }
        WikittyQueryResult<Objectresult = new WikittyQueryResult<Object>(
                ,
                data,
                );
        return result;
    }

    
Retourne les resultats de select pour le champs demande et le transforme en objet de type clazz

Parameters:
resultName
Returns:
Since:
3.10
    public <E> WikittyQueryResult<E> getSelectResult(
            WikittyClient clientClass<E> clazzString resultName) {
        WikittyQueryResult<E> result = getSelectResult(resultName).castTo(clientclazz);
        return result;
    }


    
Return name of all facet used in query.

Returns:
result's facets names
    public Collection<StringgetFacetNames() {
        Collection<Stringresult = .keySet();
        return result;
    }

    
Return all topic for the specified facet.

Parameters:
facetName name of the wanted facet
Returns:
facet's topics
    public List<FacetTopicgetTopic(String facetName) {
        List<FacetTopicresult = .get(facetName);
        return result;
    }

    
Return all topic for the specified facet.

Parameters:
facetName name of the wanted facet
Returns:
facet's topics
Since:
3.4
    public List<FacetTopicgetTopic(Element facetName) {
        List<FacetTopicresult = getTopic(facetName.getValue());
        return result;
    }

    
Return topic for the specified facet and topic name.

Parameters:
facetName name of the wanted facet
topicName name of the wanted topic
Returns:
topic
    public FacetTopic getTopic(String facetNameString topicName) {
        FacetTopic result = getFacetsAsMap().get(facetName).get(topicName);
        return result;
    }

    
Return topic count for the specified facet and topic name. If facet or topic don't exist, return 0.

Parameters:
facetName name of the wanted facet
topicName name of the wanted topic
Returns:
topic count or 0
    public int getTopicCount(String facetNameString topicName) {
        int result = 0;
        if (getFacetsAsMap() != null) {
            Map<StringFacetTopictopics = getFacetsAsMap().get(facetName);
            if (topics != null) {
                FacetTopic topic = topics.get(topicName);
                if (topic != null) {
                    result = topic.getCount();
                }
            }
        }
        return result;
    }

    
Get map represent facets. return map of list
  • key is facet name
  • value is topic liste une this facet

    Returns:
    all facets
  •     public Map<StringList<FacetTopic>> getFacets() {
            return ;
        }

        
    Get map represent facets. return map of map
  • primary key is facet name
  • secondary key is topic name
  • value is topic

    Returns:
  •     public Map<StringMap<StringFacetTopic>> getFacetsAsMap() {
            if ( == null &&  != null) {
                // use local variable to prevent multi-thread problem (multiple add)
                Map<StringMap<StringFacetTopic>> localFacetsAsMap =
                        new HashMap<StringMap<StringFacetTopic>>();
                for (Map.Entry<StringList<FacetTopic>> e : getFacets().entrySet()) {
                    Map<StringFacetTopictopics = new HashMap<StringFacetTopic>();
                    localFacetsAsMap.put(e.getKey(), topics);
                    for (FacetTopic t : e.getValue()) {
                        topics.put(t.getTopicName(), t);
                    }
                }
                 = localFacetsAsMap;
            }
            return ;
        }



        
    Return the offset element in result Can throw an exception if no element available

    Returns:
    offset element
        public T peek() {
            T result = get(0);
            return result;
        }

        
    Return element at index.

    Parameters:
    i index
    Returns:
    element at index
        public T get(int i) {
            T result = .get(i);
            return result;
        }

        
    Return unmodifiable list of all result.

    Returns:
    all results
        public List<T> getAll() {
            return ;
        }

        
    Return the number of result in this object.

    Returns:
    result number
        public int size() {
            int result = .size();
            return result;
        }

        
    temps (nanoseconde) mis pour faire la requete (calcul cote serveur)
        public long getTimeQuery() {
            return ;
        }

        
    temps (nanoseconde) mis pour faire la requete (calcul cote serveur)
        public void setTimeQuery(long timeQuery) {
            this. = timeQuery;
        }

        
    temps (nanoseconde) de transformation des resultats bruts en un autre type(calcul cote client)
        public long getTimeConvertion() {
            return ;
        }

        
    temps (nanoseconde) de transformation des resultats bruts en un autre type(calcul cote client)
        public void setTimeConvertion(long timeConvertion) {
            this. = timeConvertion;
        }

        
    Iterate on result, same as getAll().iterator().

    Returns:
        public Iterator<T> iterator() {
            Iterator<T> result = getAll().iterator();
            return result;
        }
        @Override
        public String toString() {
            String result = getQueryString() + " results " + getAll();
            if (!getFacetNames().isEmpty()) {
                result += "\nfacets " + getFacets();
            }
            return result;
        }


        
    Convert all result to the wanted type and return new WikittyQueryResult with this new result list. For business object transformation, if some result don't have the right extension (clazz) this extension is automatically added.

    Parameters:
    queryResult result to convert
    target to cast into. Can be Wikitty, BusinessEntity, String, Date, Number (returned is BigDecimal), Boolean, byte[]
    Returns:
    new WikittyQueryResult with element in right class or Exception if conversion is impossible
    Since:
    3.10
        public <E> WikittyQueryResult<E> castTo(WikittyClient clientClass<E> target) {
            WikittyQueryResult<E> result;
            if (target == null || Map.class.isAssignableFrom(target)) {
                result = (WikittyQueryResult<E>)this;
            } else {
                long startTime = System.nanoTime();
                WikittyQueryResult queryResultFlated = convertMapToSimple();
                List<E> castedResult = client.castTo(targetqueryResultFlated.getAll());
                long estimatedTime = System.nanoTime() - startTime;
                result = new WikittyQueryResult<E>(
                        ,
                        castedResult,
                        estimatedTime);
            }
            return result;
        }

        
    Convert all result to the wanted type and return new WikittyQueryResult with this new result list. For business object transformation, if some result don't have the right extension (clazz) this extension is automatically added.

    Parameters:
    queryResult result to convert
    target to cast into. Can be Wikitty, BusinessEntity, String, Date, Number (returned is BigDecimal), Boolean, byte[]
    Returns:
    new WikittyQueryResult with element in right class or Exception if conversion is impossible
    Since:
    3.10
        public <E, F> WikittyQueryResult<Map<String, E>> castToMap(
                WikittyClient clientClass<E> target) {
            WikittyQueryResult<Map<String, E>> result;
            long startTime = System.nanoTime();
            List<Map<String, E>> castedResult = client.castToMap(target,
                    (List<Map<String, F>>)this.getAll());
            long estimatedTime = System.nanoTime() - startTime;
            result = new WikittyQueryResult<Map<String, E>>(
                    ,
                    castedResult,
                    estimatedTime);
            return result;
        }
    New to GrepCode? Check out our FAQ X