Java Code Examples for com.mongodb.DBCursor#toArray()

The following examples show how to use com.mongodb.DBCursor#toArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalValidator.java    From scava with Eclipse Public License 2.0 8 votes vote down vote up
private Map<String, Float> readDistanceScores(String startingObject, Set<String> others) {
	Map<String, Float> result = new HashMap<String, Float>();
	Query query = new org.springframework.data.mongodb.core.query.Query();
	query.addCriteria(Criteria.where("type.name").is(_SIMILARITY_METHOD).orOperator(
			Criteria.where("fromArtifact.$id").is(new ObjectId(startingObject)),
			Criteria.where("toArtifact.$id").is(new ObjectId(startingObject))));
	DBCollection dbCollection = mongoTemplate.getCollection("relation");
	DBCursor cursor = dbCollection.find(query.getQueryObject());
	List<DBObject> list = cursor.toArray();
	for (DBObject dbObject : list) {
		String toArtifact = ((DBRef) dbObject.get("toArtifact")).getId().toString();
		String fromArtifact = ((DBRef) dbObject.get("fromArtifact")).getId().toString();
		double value = ((double) dbObject.get("value"));
		if (toArtifact.equals(startingObject)) {
			if (others.contains(fromArtifact))
				result.put(fromArtifact, (float) (1 - value));
		} else if (others.contains(toArtifact))
			result.put(toArtifact, (float) (1 - value));
	}
	return result;
}
 
Example 2
Source File: InternalValidator.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
private Map<String, Float> readDistanceScores(String object) {
	Map<String, Float> result = new HashMap<String, Float>();
	Query query = new org.springframework.data.mongodb.core.query.Query();
	query.addCriteria(Criteria.where("type.name").is(_SIMILARITY_METHOD).orOperator(
			Criteria.where("fromArtifact.$id").is(new ObjectId(object)),
			Criteria.where("toArtifact.$id").is(new ObjectId(object))));
	DBCollection dbCollection = mongoTemplate.getCollection("relation");
	DBCursor cursor = dbCollection.find(query.getQueryObject());
	List<DBObject> list = cursor.toArray();
	for (DBObject dbObject : list) {
		String toArtifact = ((DBRef) dbObject.get("toArtifact")).getId().toString();
		String fromArtifact = ((DBRef) dbObject.get("fromArtifact")).getId().toString();
		double value = ((double) dbObject.get("value"));
		if (toArtifact.equals(object))
			result.put(fromArtifact, (float) (1 - value));
		else
			result.put(toArtifact, (float) (1 - value));
	}
	return result;
}
 
Example 3
Source File: KmeansClulsterCalulator.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
private Map<String, Float> readDistanceScores(String object) {
	Map<String, Float> result = new HashMap<String, Float>();
	Query query = new org.springframework.data.mongodb.core.query.Query();
	query.addCriteria(Criteria.where("type.name").is(sm.getSimilarityName())
			.orOperator(Criteria.where("fromArtifact.$id").is(new ObjectId(object)), 
					    Criteria.where("toArtifact.$id").is(new ObjectId(object))));
	DBCollection dbCollection = mongoTemplate.getCollection("relation");
    DBCursor cursor = dbCollection.find(query.getQueryObject());
    List<DBObject> list = cursor.toArray();
    for (DBObject dbObject : list) {
		String toArtifact = ((DBRef)dbObject.get("toArtifact")).getId().toString();
		String fromArtifact = ((DBRef)dbObject.get("fromArtifact")).getId().toString();
		double value = ((double)dbObject.get("value"));
		if (toArtifact.equals(object))  
			result.put(fromArtifact, (float) (1 - value));
		else 
			result.put(toArtifact, (float) (1 - value));
	}
	return result;
}
 
Example 4
Source File: ClaraClulsterCalulator.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
private Map<String, Float> readDistanceScores(String object) {
	Map<String, Float> result = new HashMap<String, Float>();
	Query query = new org.springframework.data.mongodb.core.query.Query();
	query.addCriteria(Criteria.where("type.name").is(sm.getSimilarityName()).orOperator(
			Criteria.where("fromArtifact.$id").is(new ObjectId(object)),
			Criteria.where("toArtifact.$id").is(new ObjectId(object))));
	DBCollection dbCollection = mongoTemplate.getCollection("relation");
	DBCursor cursor = dbCollection.find(query.getQueryObject());
	List<DBObject> list = cursor.toArray();
	for (DBObject dbObject : list) {
		String toArtifact = ((DBRef) dbObject.get("toArtifact")).getId().toString();
		String fromArtifact = ((DBRef) dbObject.get("fromArtifact")).getId().toString();
		double value = ((double) dbObject.get("value"));
		if (toArtifact.equals(object))
			result.put(fromArtifact, (float) (1 - value));
		else
			result.put(toArtifact, (float) (1 - value));
	}
	return result;
}