本文整理了Java中org.codehaus.jettison.json.JSONObject.optLong()
方法的一些代码示例,展示了JSONObject.optLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.optLong()
方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONObject
类名称:JSONObject
方法名:optLong
[英]Get an optional long value associated with a key, or zero if there is no such key or if the value is not a number. If the value is a string, an attempt will be made to evaluate it as a number.
[中]获取与键关联的可选长值,如果没有此类键或该值不是数字,则获取零。如果该值是字符串,将尝试将其作为数字计算。
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Get an optional long value associated with a key,
* or zero if there is no such key or if the value is not a number.
* If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A key string.
* @return An object which is the value.
*/
public long optLong(String key) {
return optLong(key, 0);
}
代码示例来源:origin: org.codehaus.jettison/com.springsource.org.codehaus.jettison
/**
* Get an optional long value associated with a key,
* or zero if there is no such key or if the value is not a number.
* If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A key string.
* @return An object which is the value.
*/
public long optLong(String key) {
return optLong(key, 0);
}
代码示例来源:origin: com.tinkerpop.blueprints/blueprints-rexster-graph
public long count() {
final String directionReturnToken;
if (this.direction == Direction.IN) {
directionReturnToken = RexsterTokens.SLASH_INCOUNT;
} else if (this.direction == Direction.OUT) {
directionReturnToken = RexsterTokens.SLASH_OUTCOUNT;
} else {
directionReturnToken = RexsterTokens.SLASH_BOTHCOUNT;
}
final JSONObject jsonObject = RestHelper.get(buildUri(directionReturnToken));
return jsonObject.optLong(RexsterTokens.TOTAL_SIZE);
}
代码示例来源:origin: thinkaurelius/faunus
private long getTrueVertexCount() {
try {
final HttpURLConnection connection = HttpHelper.createConnection(
this.getRestCountEndpoint(), this.getAuthenticationHeaderValue());
final JSONObject json = new JSONObject(convertStreamToString(connection.getInputStream()));
return json.optLong(FaunusRexsterInputFormatExtension.EXTENSION_METHOD_COUNT);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
代码示例来源:origin: org.apache.apex/apex-engine
@POST
@Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{opId:\\d+}/ports/{portName}/" + PATH_RECORDINGS_START)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject startRecording(@PathParam("opId") int opId, @PathParam("portName") String portName, String content) throws JSONException
{
init();
LOG.debug("Start recording on {}.{} requested", opId, portName);
JSONObject response = new JSONObject();
long numWindows = 0;
if (StringUtils.isNotBlank(content)) {
JSONObject r = new JSONObject(content);
numWindows = r.optLong("numWindows", 0);
}
String id = getTupleRecordingId();
dagManager.startRecording(id, opId, portName, numWindows);
response.put("id", id);
return response;
}
代码示例来源:origin: org.apache.apex/apex-engine
@POST
@Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{opId:\\d+}/" + PATH_RECORDINGS_START)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject startRecording(@PathParam("opId") int opId, String content) throws JSONException
{
init();
LOG.debug("Start recording on {} requested", opId);
JSONObject response = new JSONObject();
long numWindows = 0;
if (StringUtils.isNotBlank(content)) {
JSONObject r = new JSONObject(content);
numWindows = r.optLong("numWindows", 0);
}
String id = getTupleRecordingId();
dagManager.startRecording(id, opId, null, numWindows);
response.put("id", id);
return response;
}
代码示例来源:origin: org.apache.tez/tez-history-parser
public static List<DataDependencyEvent> parseDataEventDependencyFromJSON(JSONObject jsonObject)
throws JSONException {
List<DataDependencyEvent> events = Lists.newArrayList();
JSONArray fields = jsonObject.optJSONArray(Constants.LAST_DATA_EVENTS);
for (int i=0; i<fields.length(); i++) {
JSONObject eventMap = fields.getJSONObject(i);
events.add(new DataDependencyEvent(
StringInterner.weakIntern(eventMap.optString(EntityTypes.TEZ_TASK_ATTEMPT_ID.name())),
eventMap.optLong(Constants.TIMESTAMP)));
}
return events;
}
代码示例来源:origin: com.tinkerpop.blueprints/blueprints-rexster-graph
public long count(final String key, final Object value) {
final JSONObject countJson = RestHelper.get(this.graph.getGraphURI() + RexsterTokens.SLASH_INDICES_SLASH + RestHelper.encode(this.indexName) + RexsterTokens.SLASH_COUNT + RexsterTokens.QUESTION + RexsterTokens.KEY_EQUALS + key + RexsterTokens.AND + RexsterTokens.VALUE_EQUALS + RestHelper.uriCast(value));
return countJson.optLong("totalSize");
}
}
代码示例来源:origin: cwensel/cascading
private TaskStatus parseTaskStatus( JSONObject jsonRoot )
{
try
{
String taskID = jsonRoot.optString( ATSConstants.ENTITY );
JSONObject otherInfoNode = jsonRoot.getJSONObject( ATSConstants.OTHER_INFO );
String status = otherInfoNode.optString( ATSConstants.STATUS );
long scheduledTime = otherInfoNode.optLong( ATSConstants.SCHEDULED_TIME, -1 );
long startTime = otherInfoNode.optLong( ATSConstants.START_TIME, -1 ); // actual attempt launch time
long endTime = otherInfoNode.optLong( ATSConstants.FINISH_TIME, -1 ); // endTime
String successfulAttemptID = otherInfoNode.optString( ATSConstants.SUCCESSFUL_ATTEMPT_ID );
String diagnostics = otherInfoNode.optString( ATSConstants.DIAGNOSTICS );
if( status.equals( "" ) )
return new TaskStatus( taskID );
JSONObject countersNode = otherInfoNode.optJSONObject( ATSConstants.COUNTERS );
Map<String, Map<String, Long>> counters = parseDagCounters( countersNode );
return new TaskStatus( taskID, status, scheduledTime, startTime, endTime, successfulAttemptID, counters, diagnostics );
}
catch( JSONException exception )
{
throw new CascadingException( exception );
}
}
代码示例来源:origin: cascading/cascading-hadoop2-tez-stats
private TaskStatus parseTaskStatus( JSONObject jsonRoot )
{
try
{
String taskID = jsonRoot.optString( ATSConstants.ENTITY );
JSONObject otherInfoNode = jsonRoot.getJSONObject( ATSConstants.OTHER_INFO );
String status = otherInfoNode.optString( ATSConstants.STATUS );
long scheduledTime = otherInfoNode.optLong( ATSConstants.SCHEDULED_TIME, -1 );
long startTime = otherInfoNode.optLong( ATSConstants.START_TIME, -1 ); // actual attempt launch time
long endTime = otherInfoNode.optLong( ATSConstants.FINISH_TIME, -1 ); // endTime
String successfulAttemptID = otherInfoNode.optString( ATSConstants.SUCCESSFUL_ATTEMPT_ID );
String diagnostics = otherInfoNode.optString( ATSConstants.DIAGNOSTICS );
if( status.equals( "" ) )
return new TaskStatus( taskID );
JSONObject countersNode = otherInfoNode.optJSONObject( ATSConstants.COUNTERS );
Map<String, Map<String, Long>> counters = parseDagCounters( countersNode );
return new TaskStatus( taskID, status, scheduledTime, startTime, endTime, successfulAttemptID, counters, diagnostics );
}
catch( JSONException exception )
{
throw new CascadingException( exception );
}
}
代码示例来源:origin: org.apache.tez/tez-history-parser
/**
* Parse events from json
*
* @param eventNodes
* @param eventList
* @throws JSONException
*/
public static void parseEvents(JSONArray eventNodes, List<Event> eventList) throws
JSONException {
if (eventNodes == null) {
return;
}
for (int i = 0; i < eventNodes.length(); i++) {
JSONObject eventNode = eventNodes.optJSONObject(i);
final String eventInfo = eventNode.optString(Constants.EVENT_INFO);
final String eventType = eventNode.optString(Constants.EVENT_TYPE);
final long time = eventNode.optLong(Constants.EVENT_TIME_STAMP);
Event event = new Event(eventInfo, eventType, time);
eventList.add(event);
}
}
代码示例来源:origin: thinkaurelius/faunus
private static void fromJSONEdges(final FaunusVertex vertex, final JSONArray edges, final Direction direction) throws JSONException, IOException {
if (null != edges) {
for (int i = 0; i < edges.length(); i++) {
final JSONObject edge = edges.optJSONObject(i);
FaunusEdge faunusEdge = null;
if (direction.equals(Direction.IN)) {
faunusEdge = (FaunusEdge) graphson.edgeFromJson(edge, new FaunusVertex(edge.optLong(GraphSONTokens._OUT_V)), vertex);
} else if (direction.equals(Direction.OUT)) {
faunusEdge = (FaunusEdge) graphson.edgeFromJson(edge, vertex, new FaunusVertex(edge.optLong(GraphSONTokens._IN_V)));
}
if (faunusEdge != null) {
vertex.addEdge(direction, faunusEdge);
}
}
}
}
代码示例来源:origin: org.apache.tez/tez-history-parser
long sTime = otherInfoNode.optLong(Constants.START_TIME);
long eTime = otherInfoNode.optLong(Constants.FINISH_TIME);
if (eTime < sTime) {
LOG.warn("Task has got wrong start/end values. "
successfulAttemptId = StringInterner.weakIntern(
otherInfoNode.optString(Constants.SUCCESSFUL_ATTEMPT_ID));
scheduledTime = otherInfoNode.optLong(Constants.SCHEDULED_TIME);
status = StringInterner.weakIntern(otherInfoNode.optString(Constants.STATUS));
代码示例来源:origin: org.apache.tez/tez-history-parser
initRequestedTime = otherInfoNode.optLong(Constants.INIT_REQUESTED_TIME);
startRequestedTime = otherInfoNode.optLong(Constants.START_REQUESTED_TIME);
long sTime = otherInfoNode.optLong(Constants.START_TIME);
long iTime = otherInfoNode.optLong(Constants.INIT_TIME);
long eTime = otherInfoNode.optLong(Constants.FINISH_TIME);
if (eTime < sTime) {
LOG.warn("Vertex has got wrong start/end values. "
代码示例来源:origin: com.tinkerpop.rexster/rexster-core
private static Long getOffset(final JSONObject requestObject, final String offsetToken) {
final JSONObject rexsterRequestObject = getRexsterRequest(requestObject);
if (rexsterRequestObject != null) {
if (rexsterRequestObject.has(Tokens.OFFSET)) {
// returns zero if the value identified by the offsetToken is
// not a number and the key is just present.
if (rexsterRequestObject.optJSONObject(Tokens.OFFSET).has(offsetToken)) {
return rexsterRequestObject.optJSONObject(Tokens.OFFSET).optLong(offsetToken);
} else {
return null;
}
} else {
return null;
}
} else {
return null;
}
}
}
代码示例来源:origin: org.apache.tez/tez-history-parser
long sTime = otherInfoNode.optLong(Constants.START_TIME);
long eTime= otherInfoNode.optLong(Constants.FINISH_TIME);
userName = otherInfoNode.optString(Constants.USER);
if (eTime < sTime) {
submitTime = otherInfoNode.optLong(Constants.START_REQUESTED_TIME);
diagnostics = otherInfoNode.optString(Constants.DIAGNOSTICS);
failedTasks = otherInfoNode.optInt(Constants.NUM_FAILED_TASKS);
代码示例来源:origin: org.apache.tez/tez-history-parser
long sTime = otherInfoNode.optLong(Constants.START_TIME);
long eTime = otherInfoNode.optLong(Constants.FINISH_TIME);
if (eTime < sTime) {
LOG.warn("TaskAttemptInfo has got wrong start/end values. "
creationTime = otherInfoNode.optLong(Constants.CREATION_TIME);
creationCausalTA = StringInterner.weakIntern(
otherInfoNode.optString(Constants.CREATION_CAUSAL_ATTEMPT));
allocationTime = otherInfoNode.optLong(Constants.ALLOCATION_TIME);
containerId = StringInterner.weakIntern(otherInfoNode.optString(Constants.CONTAINER_ID));
String id = otherInfoNode.optString(Constants.NODE_ID);
代码示例来源:origin: GluuFederation/oxAuth
key.setAlg(signatureAlgorithm);
key.setKty(KeyType.fromString(signatureAlgorithm.getFamily().toString()));
key.setExp(result.optLong(EXPIRATION_TIME));
key.setCrv(signatureAlgorithm.getCurve());
key.setN(result.optString(MODULUS));
key.setAlg(encryptionAlgorithm);
key.setKty(KeyType.fromString(encryptionAlgorithm.getFamily().toString()));
key.setExp(result.optLong(EXPIRATION_TIME));
key.setCrv(encryptionAlgorithm.getCurve());
key.setN(result.optString(MODULUS));
key.setAlg(signatureAlgorithm);
key.setKty(KeyType.fromString(signatureAlgorithm.getFamily().toString()));
key.setExp(result.optLong(EXPIRATION_TIME));
key.setCrv(signatureAlgorithm.getCurve());
key.setN(result.optString(MODULUS));
key.setAlg(encryptionAlgorithm);
key.setKty(KeyType.fromString(encryptionAlgorithm.getFamily().toString()));
key.setExp(result.optLong(EXPIRATION_TIME));
key.setCrv(encryptionAlgorithm.getCurve());
key.setN(result.optString(MODULUS));
内容来源于网络,如有侵权,请联系作者删除!