當前位置: 首頁>>代碼示例>>Java>>正文


Java BasicDBList.size方法代碼示例

本文整理匯總了Java中com.mongodb.BasicDBList.size方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicDBList.size方法的具體用法?Java BasicDBList.size怎麽用?Java BasicDBList.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mongodb.BasicDBList的用法示例。


在下文中一共展示了BasicDBList.size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAsJsonArray

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
/**
 * Convert the given runnable BasicDBList object to JsonArray.
 *
 * @param object BasicDBList
 * @return JsonArray
 */
public JsonArray getAsJsonArray(DBObject object) {
    if (!(object instanceof BasicDBList)) {
        throw new IllegalArgumentException("Expected BasicDBList as argument type!");
    }
    BasicDBList list = (BasicDBList)object;
    JsonArray jsonArray = new JsonArray();
    for (int i = 0; i < list.size(); i++) {
        Object dbObject = list.get(i);
        if (dbObject instanceof BasicDBList) {
            jsonArray.add(getAsJsonArray((BasicDBList) dbObject));
        } else if (dbObject instanceof BasicDBObject) { // it's an object
            jsonArray.add(getAsJsonObject((BasicDBObject) dbObject));
        } else {   // it's a primitive type number or string
            jsonArray.add(getAsJsonPrimitive(dbObject));
            jsonArray.add(getAsJsonPrimitive(dbObject));
        }
    }
    return jsonArray;
}
 
開發者ID:stump201,項目名稱:mongiORM,代碼行數:26,代碼來源:Mongo2JSON.java

示例2: getPCJIndexDetails

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
private static PCJIndexDetails.Builder getPCJIndexDetails(final BasicDBObject basicObj) {
    final BasicDBObject pcjIndexDBO = (BasicDBObject) basicObj.get(PCJ_DETAILS_KEY);

    final PCJIndexDetails.Builder pcjBuilder = PCJIndexDetails.builder();
    if (!pcjIndexDBO.getBoolean(PCJ_ENABLED_KEY)) {
        pcjBuilder.setEnabled(false);
    } else {
        pcjBuilder.setEnabled(true);//no fluo details to set since mongo has no fluo support
        final BasicDBList pcjs = (BasicDBList) pcjIndexDBO.get(PCJ_PCJS_KEY);
        if (pcjs != null) {
            for (int ii = 0; ii < pcjs.size(); ii++) {
                final BasicDBObject pcj = (BasicDBObject) pcjs.get(ii);
                pcjBuilder.addPCJDetails(toPCJDetails(pcj));
            }
        }
    }
    return pcjBuilder;
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:19,代碼來源:MongoDetailsAdapter.java

示例3: packBackgroundsInToScenarios

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
/**
 * go through find all the backgrounds elements and nest them in their scenarios (simplifies application logic downstream)
 */
protected void packBackgroundsInToScenarios(final DBObject feature) {
	final List<DBObject> packedScenarios = new ArrayList<DBObject>();
	// go through all the backgrounds /scenarios
	final BasicDBList elements = (BasicDBList) feature.get("elements");
	if (elements != null) {
		for (int i = 0; i < elements.size(); i++) {
			final DBObject element = (DBObject) elements.get(i);
			if (element.get("type").equals("background")) { // if its a background
				((DBObject) elements.get(i + 1)).put("background", element); // push it in to the next element.
			} else {
				// assume this is a scenario/other top level element and push it to the packed array.
				packedScenarios.add(element);
			}
		}
		elements.clear();
		elements.addAll(packedScenarios);
	}
}
 
開發者ID:orionhealth,項目名稱:XBDD,代碼行數:22,代碼來源:Report.java

示例4: unmarshal

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
@Override
public Object unmarshal(Object obj, boolean lifecycle) {
    if (obj == null || !(obj instanceof BasicDBList)) {
        return null;
    }

    BasicDBList list = (BasicDBList) obj;
    int[] sizes = sizes(list);

    Object array = Array.newInstance(arrayType, sizes);
    for (int i = 0; i < list.size(); i++) {
        Object value = list.get(i);
        Object result = mapper.unmarshal(value, lifecycle);
        Array.set(array, i, result);
    }

    return array;
}
 
開發者ID:hfoxy,項目名稱:morphix,代碼行數:19,代碼來源:ArrayMapper.java

示例5: saveAll

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
public void saveAll(HashMap<String, Integer> values, int sourceDistributionID, int targetDistributionID) {

//		removeAll(sourceDistributionID, targetDistributionID);

		DBCollection collection = DBSuperClass2.getDBInstance().getCollection(COLLECTION_NAME);
		BasicDBObject mainDoc = new BasicDBObject();
		mainDoc.append(SOURCE_DISTRIBUTION_ID, sourceDistributionID);
		mainDoc.append(TARGET_DISTRIBUTION_ID, targetDistributionID);
		BasicDBList innerList = new BasicDBList();

		for (String s : topNKeys(values, LODVaderProperties.TOP_N_LINKS).keySet()) {
			BasicDBObject innerDoc = new BasicDBObject();
			innerDoc.append(AMOUNT, values.get(s));
			innerDoc.append(LINK, s);
			innerList.add(innerDoc);
		}
		if (innerList.size() > 0) {
			mainDoc.append(DETAILS, innerList);

			collection.insert(mainDoc);
		}
	}
 
開發者ID:AKSW,項目名稱:LODVader,代碼行數:23,代碼來源:SuperTop.java

示例6: Group

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
/**
 * Create a group based on a Mongo DB Object
 *
 * @param group The existing Mongo DB Object
 */
public Group(DBObject group) {
  this.id = ((ObjectId) group.get(DB_ID)).toString();
  this.name = (String) group.get(JSON_KEY_GROUP_NAME);

  BasicDBList dbMembers = ((BasicDBList) group.get(JSON_KEY_MEMBERS_LIST));
  this.members = new String[dbMembers.size()];
  for (int i = 0; i < dbMembers.size(); i++) {
    members[i] = (String) dbMembers.get(i);
  }
}
 
開發者ID:OpenLiberty,項目名稱:sample-acmegifts,代碼行數:16,代碼來源:Group.java

示例7: isEqual

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
public boolean isEqual(BasicDBObject other) {
  BasicDBList oMembers = (BasicDBList) other.get(JSON_KEY_MEMBERS_LIST);

  return ((oMembers.containsAll(Arrays.asList(this.members))
          && oMembers.size() == this.members.length)
      && this.name.equals(other.get(JSON_KEY_GROUP_NAME))
      && this.id.equals(other.getString(DB_ID)));
}
 
開發者ID:OpenLiberty,項目名稱:sample-acmegifts,代碼行數:9,代碼來源:Group.java

示例8: dbArrayToString

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
private String dbArrayToString(BasicDBList list) {
    String[] result = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
        result[i] = list.get(i).toString();
    }
    return StringUtils.join(result, Config.properties.getProperty(Config.ARRAY_DELIMITER));
}
 
開發者ID:shunfei,項目名稱:stinift,代碼行數:8,代碼來源:MongoReader.java

示例9: testGetZipsWithOrderBy

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
@Test
public void testGetZipsWithOrderBy() throws Exception {
	StringWriter sw = new StringWriter();
	PrintWriter pw = new PrintWriter(sw);

	when(response.getWriter()).thenReturn(pw);
	when(request.getPathInfo()).thenReturn("/zips");
	@SuppressWarnings("serial")
	HashMap<String, String[]> parameterMap = new HashMap<String, String[]>() {
		{
			put("order-by", new String[] { "state, city" });
		}
	};
	when(request.getParameterMap()).thenReturn(parameterMap);

	new MongoCrudServlet().doGet(request, response);

	String result = sw.getBuffer().toString().trim();
	System.out.println("Json Result As String is : " + result.length() + " characters long");
	assertTrue("somehow got a very small JSON resposne: " + result, result.length() > 20);
	BasicDBList json = (BasicDBList) JSON.parse(result);
	for (int i = 0; i < json.size() - 1; i++) {
		BasicDBObject r1 = (BasicDBObject) json.get(i);
		BasicDBObject r2 = (BasicDBObject) json.get(i + 1);
		String k1 = r1.getString("state") + " " + r1.getString("city");
		String k2 = r2.getString("state") + " " + r2.getString("city");
		assertTrue(String.format("records %d and %d were not in the right order: %s vs %s", i, i + 1, k1, k2),
				k1.compareTo(k2) <= 0);
	}

}
 
開發者ID:timbaileyjones,項目名稱:nomopojo,代碼行數:32,代碼來源:MongoCrudServletTest.java

示例10: testGetZipsForStateAndCity

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
public int testGetZipsForStateAndCity(final String stateCode, final String city) throws Exception {
	StringWriter sw = new StringWriter();
	PrintWriter pw = new PrintWriter(sw);

	when(response.getWriter()).thenReturn(pw);
	when(request.getPathInfo()).thenReturn("/zips");
	@SuppressWarnings("serial")
	HashMap<String, String[]> parameterMap = new HashMap<String, String[]>() {
		{
			put("state", new String[] { stateCode });
			if (city != null)
				put("city", new String[] { city });
		}
	};
	when(request.getParameterMap()).thenReturn(parameterMap);

	new MongoCrudServlet().doGet(request, response);

	String result = sw.getBuffer().toString().trim();
	System.out.println("Json Result As String is : " + result.length() + " characters long");
	assertTrue("somehow got a very small JSON resposne: " + result, result.length() > 20);
	System.out.println("first few lines of Json Result:\n" + result.substring(0, 400));

	BasicDBList json = (BasicDBList) JSON.parse(result);
	if (city == null) {
		assertTrue(stateCode + "should have at least 700 zip codes", json.size() > 700);
		System.out.println(
				stateCode + " has " + json.size() + " zip codes, out of a total of " + zipDocuments.size());
	} else {
		assertTrue(city + ", " + stateCode + "should have at least 10 zip codes", json.size() > 10);
		System.out.println(city + ", " + stateCode + " has " + json.size() + " zip codes, out of a total of "
				+ zipDocuments.size());

	}
	assertTrue(true);
	return json.size();
}
 
開發者ID:timbaileyjones,項目名稱:nomopojo,代碼行數:38,代碼來源:MongoCrudServletTest.java

示例11: embedSteps

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
/**
 * go through all the embedded content, store it to GridFS, replace the doc embeddings with a hyperlink to the saved content.
 */
protected void embedSteps(final DBObject feature, final GridFS gridFS, final Coordinates coordinates) {
	final BasicDBList elements = (BasicDBList) feature.get("elements");
	final String featureId = (String) feature.get("_id");
	if (elements != null) {
		for (int j = 0; j < elements.size(); j++) {
			final DBObject scenario = (DBObject) elements.get(j);
			final String scenarioId = (String) scenario.get("_id");
			final BasicDBList steps = (BasicDBList) scenario.get("steps");
			if (steps != null) {
				for (int k = 0; k < steps.size(); k++) {
					final DBObject step = (DBObject) steps.get(k);
					final BasicDBList embeddings = (BasicDBList) step.get("embeddings");
					if (embeddings != null) {
						for (int l = 0; l < embeddings.size(); l++) {
							final DBObject embedding = (DBObject) embeddings.get(l);
							final GridFSInputFile image = gridFS
									.createFile(Base64.decodeBase64(((String) embedding.get("data")).getBytes()));
							image.setFilename(guid());
							final BasicDBObject metadata = new BasicDBObject().append("product", coordinates.getProduct())
									.append("major", coordinates.getMajor()).append("minor", coordinates.getMinor())
									.append("servicePack", coordinates.getServicePack()).append("build", coordinates.getBuild())
									.append("feature", featureId)
									.append("scenario", scenarioId);
							image.setMetaData(metadata);
							image.setContentType((String) embedding.get("mime_type"));
							image.save();
							embeddings.put(l, image.getFilename());
						}
					}
				}
			}
		}
	}
}
 
開發者ID:orionhealth,項目名稱:XBDD,代碼行數:38,代碼來源:Report.java

示例12: addBuildToRecents

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
@PUT
@Path("/build/{product}/{major}.{minor}.{servicePack}/{build}")
@Produces("application/json")
public Response addBuildToRecents(@BeanParam Coordinates coordinates,
		@Context final HttpServletRequest req) {
	
	DBObject buildCoords = coordinates.getReportCoordinates();
	
	final DB db = this.client.getDB("bdd");
	final DBCollection collection = db.getCollection("users");
	
	final BasicDBObject user = new BasicDBObject();
	user.put("user_id", req.getRemoteUser());
	
	final DBObject blank = new BasicDBObject();
	DBObject doc = collection.findAndModify(user, blank, blank, false, new BasicDBObject("$set", user), true, true);
	
	if (doc.containsField("recentBuilds")) {
		BasicDBList buildArray = (BasicDBList) doc.get("recentBuilds");
		if (buildArray.contains(buildCoords)) {
			//BasicDBObject toMove = (BasicDBObject) featureArray.get(featureArray.indexOf(featureDetails));
			buildArray.remove(buildCoords);
			buildArray.add(buildCoords);
			collection.update(user, new BasicDBObject("$set",new BasicDBObject("recentBuilds", buildArray)));
		} else {
			if (buildArray.size()>=5) {
				collection.update(user, new BasicDBObject("$pop",new BasicDBObject("recentBuilds", "-1")));
			}
			collection.update(user, new BasicDBObject("$addToSet",new BasicDBObject("recentBuilds", buildCoords)));
		}
	} else {
		collection.update(user, new BasicDBObject("$addToSet",new BasicDBObject("recentBuilds", buildCoords)));
	}
		
	return Response.ok().build();
}
 
開發者ID:orionhealth,項目名稱:XBDD,代碼行數:37,代碼來源:Recents.java

示例13: getFeatureStatus

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
public static String getFeatureStatus(final DBObject feature) {
	final List<String> allStatuses = new ArrayList<String>();
	final BasicDBList featureElements = (BasicDBList) feature.get("elements");
	if (featureElements != null) {
		for (int i = 0; i < featureElements.size(); i++) {
			final DBObject scenario = (DBObject) featureElements.get(i);
			if (isScenarioKeyword((String) scenario.get("keyword"))) {
				allStatuses.add(getScenarioStatus(scenario));
			}
		}
	}

	final String result = reduceStatuses(allStatuses).getTextName();
	return result;
}
 
開發者ID:orionhealth,項目名稱:XBDD,代碼行數:16,代碼來源:StatusHelper.java

示例14: loadEntitiesPerStatus

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
public static Map<Long, List<NamedEntity>> loadEntitiesPerStatus(String hostname, String dbname, String collName) {
	
	Map<String, NamedEntity> entitiesMap =new HashMap<String, NamedEntity>();
	Map<Long, List<NamedEntity>> entitiesPerStatus = new HashMap<Long, List<NamedEntity>>();
	
	DBCollection collection = MongoDAODep.getCollection(hostname, dbname, collName);
	DBCursor cursor = collection.find();
	while(cursor.hasNext()) {
		
		DBObject obj = cursor.next();
		Long id = (Long) obj.get("id");
		
		List<NamedEntity> entities = new ArrayList<NamedEntity>();
		BasicDBList entitiesList = (BasicDBList) obj.get("entities");
		for(int i=0; i<entitiesList.size(); i++) {
			DBObject o = (DBObject) entitiesList.get(i);
			String name = (String) o.get("name");
			String type = (String) o.get("type");
			Integer frequency = (Integer) o.get("frequency");
			
			NamedEntity e = entitiesMap.get(name+"%"+type);
			if(e == null) {
				e = new NamedEntity(name, type);
				entitiesMap.put(name+"%"+type, e);
			}
			e.setFrequency(frequency);
			
			entities.add(e);
		}
		entitiesPerStatus.put(id, entities);
	}
	return entitiesPerStatus;
}
 
開發者ID:MKLab-ITI,項目名稱:mgraph-summarization,代碼行數:34,代碼來源:MongoDAODep.java

示例15: and

import com.mongodb.BasicDBList; //導入方法依賴的package包/類
/**
 * Adds a list of clauses to the query as conjunction (logical AND).
 */
public Query and(BasicDBList clauses) {
  if (clauses==null || clauses.size()==0) {
    return this;
  }
  if (query.containsField("$and")) {
    BasicDBList existingAndClauses = (BasicDBList) query.get("$and");
    existingAndClauses.add(clauses);
  } else {
    query.append("$and", clauses);
  }
  return this;
}
 
開發者ID:effektif,項目名稱:effektif,代碼行數:16,代碼來源:Query.java


注:本文中的com.mongodb.BasicDBList.size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。