Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014 Christophe Pollet
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package net.cpollet.jixture.fixtures.capacities.extraction;
 
 import java.util.List;
 import java.util.Set;

Holds the results of entities extractions. Extractions are composed of collections in which entities are stored. Those collections have names to be able to get entities belonging to a collection.

Author(s):
Christophe Pollet
 
 public class ExtractionResult {
 
 	public ExtractionResult() {
 		this. = new HashSet<Result>();
 	}

Add a new entity to an extraction collection.

Parameters:
entity the entity to add.
name the name of the collection where this entity should be put.
 
 	public void add(Object entityString name) {
 		Result result = new Result(entityname);
 		.add(result);
 	}

Returns all entities stored in the given collection.

Parameters:
name the collection's name
Returns:
all entities stored in the given collection.
 
 	public List<ObjectgetEntities(String name) {
 		List<ObjectentitiesList = new LinkedList<Object>();
 
 		for (Result result : ) {
 			if (result.getResultName().equals(name)) {
 				entitiesList.add(result.getObject());
 			}
 		}
 
 		return entitiesList;
 	}

Returns all entities of the given type.

Parameters:
entityClass the entities type.
Returns:
all entities of the given type.
 
 	public List<ObjectgetEntities(Class entityClass) {
 		List<ObjectentitiesList = new LinkedList<Object>();
 
 		for (Result result : ) {
 			if (result.getClazz().equals(entityClass)) {
 				entitiesList.add(result.getObject());
 			}
 		}
 
 		return entitiesList;
 	}

Returns all entities of a given type from a particular collection.

Parameters:
name the collection's name
entityClass the entities type.
Returns:
all entities of a given type from a particular collection.
 
 	public List<ObjectgetEntities(String nameClass entityClass) {
 		List<ObjectentitiesList = new LinkedList<Object>();
 
 		for (Result result : ) {
 			if (result.getResultName().equals(name) && result.getClazz().equals(entityClass)) {
 				entitiesList.add(result.getObject());
 			}
 		}
 
		return entitiesList;
	}

Returns all entities.

Returns:
all entities.
	public List<ObjectgetEntities() {
		List<ObjectentitiesList = new LinkedList<Object>();
		for (Result result : ) {
			entitiesList.add(result.getObject());
		}
		return entitiesList;
	}

Merges another ExtractionResult into this one.

Parameters:
extractionResult the other ExtractionResult to merge.
	public void merge(ExtractionResult extractionResult) {
		for (Result result : extractionResult.results) {
			add(result.getObject(), result.getResultName());
		}
	}
	private class Result {
		private Object object;
		private Class clazz;
		private String resultName;
		private Result(Object objectString resultName) {
			this. = object;
			this. = object.getClass();
			this. = resultName;
		}
		public Object getObject() {
			return ;
		}
		public Class getClazz() {
			return ;
		}
		public String getResultName() {
			return ;
		}
		public boolean equals(Object o) {
			if (this == o) {
				return true;
			}
			if (!(o instanceof Result)) {
				return false;
			}
			Result result = (Resulto;
			return  == result.object && .equals(result.resultName);
		}
		public int hashCode() {
			int result = null !=  ? .hashCode() : 0;
			result = 31 * result + (null !=  ? .hashCode() : 0);
			return result;
		}
	}
New to GrepCode? Check out our FAQ X