List of usage examples for com.google.gwt.json.client JSONNumber doubleValue
public double doubleValue()
From source file:org.rstudio.studio.client.workbench.views.vcs.dialog.HistoryPresenter.java
License:Open Source License
private void showCommitDetail(boolean noSizeWarning) { final CommitInfo commitInfo = view_.getCommitList().getSelectedCommit(); if (!noSizeWarning && commitInfo != null && commitInfo.getId().equals(commitShowing_)) { return;/*from ww w . ja v a2 s . com*/ } commitShowing_ = null; view_.hideSizeWarning(); view_.getCommitDetail().setSelectedCommit(commitInfo); view_.getCommitDetail().showDetailProgress(); invalidation_.invalidate(); if (commitInfo == null) return; final Token token = invalidation_.getInvalidationToken(); strategy_.showCommit(commitInfo.getId(), noSizeWarning, new SimpleRequestCallback<String>() { @Override public void onResponseReceived(String response) { super.onResponseReceived(response); if (token.isInvalid()) return; DiffParser parser = strategy_.createParserForCommit(response); view_.getCommitDetail().setDetails(parser, !strategy_.isShowFileSupported()); commitShowing_ = commitInfo.getId(); } @Override public void onError(ServerError error) { commitShowing_ = null; JSONNumber size = error.getClientInfo().isNumber(); if (size != null) view_.showSizeWarning((long) size.doubleValue()); else if (strategy_.getShowHistoryErrors()) super.onError(error); else Debug.logError(error); } }); }
From source file:org.rstudio.studio.client.workbench.views.vcs.git.dialog.GitReviewPresenter.java
License:Open Source License
private void updateDiff(boolean allowModeSwitch) { view_.hideSizeWarning();/* w w w .j ava2s . c om*/ final ArrayList<StatusAndPath> paths = view_.getChangelistTable().getSelectedItems(); if (paths.size() != 1) { clearDiff(); return; } final StatusAndPath item = paths.get(0); if (allowModeSwitch) { if (!softModeSwitch_) { boolean staged = item.getStatus().charAt(0) != ' ' && item.getStatus().charAt(1) == ' '; HasValue<Boolean> checkbox = staged ? view_.getStagedCheckBox() : view_.getUnstagedCheckBox(); if (!checkbox.getValue()) { clearDiff(); checkbox.setValue(true, true); } } else { if (view_.getStagedCheckBox().getValue() && (item.getStatus().charAt(0) == ' ' || item.getStatus().charAt(0) == '?')) { clearDiff(); view_.getUnstagedCheckBox().setValue(true, true); } else if (view_.getUnstagedCheckBox().getValue() && item.getStatus().charAt(1) == ' ') { clearDiff(); view_.getStagedCheckBox().setValue(true, true); } } } softModeSwitch_ = false; if (!item.getPath().equals(currentFilename_)) { clearDiff(); currentFilename_ = item.getPath(); } diffInvalidation_.invalidate(); final Token token = diffInvalidation_.getInvalidationToken(); final PatchMode patchMode = view_.getStagedCheckBox().getValue() ? PatchMode.Stage : PatchMode.Working; server_.gitDiffFile(item.getPath(), patchMode, view_.getContextLines().getValue(), overrideSizeWarning_, new SimpleRequestCallback<DiffResult>("Diff Error") { @Override public void onResponseReceived(DiffResult diffResult) { if (token.isInvalid()) return; // Use lastResponse_ to prevent unnecessary flicker String response = diffResult.getDecodedValue(); if (response.equals(currentResponse_)) return; currentResponse_ = response; currentSourceEncoding_ = diffResult.getSourceEncoding(); UnifiedParser parser = new UnifiedParser(response); parser.nextFilePair(); ArrayList<ChunkOrLine> allLines = new ArrayList<ChunkOrLine>(); activeChunks_.clear(); for (DiffChunk chunk; null != (chunk = parser.nextChunk());) { activeChunks_.add(chunk); allLines.add(new ChunkOrLine(chunk)); for (Line line : chunk.getLines()) allLines.add(new ChunkOrLine(line)); } view_.setShowActions(!"??".equals(item.getStatus()) && !"UU".equals(item.getStatus())); view_.setData(allLines, patchMode); } @Override public void onError(ServerError error) { JSONNumber size = error.getClientInfo().isNumber(); if (size != null) view_.showSizeWarning((long) size.doubleValue()); else { if (error.getCode() != ServerError.TRANSMISSION) super.onError(error); } } }); }
From source file:org.rstudio.studio.client.workbench.views.vcs.svn.dialog.SVNReviewPresenter.java
License:Open Source License
private void updateDiff() { view_.hideSizeWarning();// w w w. ja v a 2 s. c o m final ArrayList<StatusAndPath> paths = view_.getChangelistTable().getSelectedItems(); if (paths.size() != 1) { clearDiff(); return; } final StatusAndPath item = paths.get(0); if (!item.getPath().equals(currentFilename_)) { clearDiff(); currentFilename_ = item.getPath(); } // bail if this is an undiffable status if (undiffableStatuses_.contains(item.getStatus())) return; diffInvalidation_.invalidate(); final Token token = diffInvalidation_.getInvalidationToken(); server_.svnDiffFile(item.getPath(), view_.getContextLines().getValue(), overrideSizeWarning_, new SimpleRequestCallback<DiffResult>("Diff Error") { @Override public void onResponseReceived(DiffResult diffResult) { if (token.isInvalid()) return; String response = diffResult.getDecodedValue(); // Use lastResponse_ to prevent unnecessary flicker if (response.equals(currentResponse_)) return; currentResponse_ = response; currentEncoding_ = diffResult.getSourceEncoding(); SVNDiffParser parser = new SVNDiffParser(response); parser.nextFilePair(); ArrayList<ChunkOrLine> allLines = new ArrayList<ChunkOrLine>(); activeChunks_.clear(); for (DiffChunk chunk; null != (chunk = parser.nextChunk());) { if (!chunk.shouldIgnore()) { activeChunks_.add(chunk); allLines.add(new ChunkOrLine(chunk)); } for (Line line : chunk.getLines()) allLines.add(new ChunkOrLine(line)); } view_.getLineTableDisplay().setShowActions(!"?".equals(item.getStatus())); view_.setData(allLines); } @Override public void onError(ServerError error) { JSONNumber size = error.getClientInfo().isNumber(); if (size != null) view_.showSizeWarning((long) size.doubleValue()); else super.onError(error); } }); }
From source file:org.sonar.api.web.gwt.client.webservices.JsonUtils.java
License:Open Source License
public static Double getDouble(JSONObject json, String field) { JSONValue jsonValue;/*from www .j a v a2s .c o m*/ JSONNumber jsonNumber; if ((jsonValue = json.get(field)) == null) { return null; } if ((jsonNumber = jsonValue.isNumber()) == null) { return null; } return jsonNumber.doubleValue(); }
From source file:org.sonar.gwt.JsonUtils.java
License:Open Source License
public static Double getAsDouble(JSONValue jsonValue) { if (jsonValue == null) { return null; }/* w w w .ja v a2 s.c om*/ JSONNumber jsonNumber; if ((jsonNumber = jsonValue.isNumber()) == null) { JSONString jsonString = jsonValue.isString(); return jsonString != null ? Double.parseDouble(jsonString.toString()) : null; } return jsonNumber.doubleValue(); }
From source file:org.spiffyui.client.JSONUtil.java
License:Apache License
/** * Get an int from the JSON object or the defaultValue if it doesn't exist or * isn't an int. This will handle JSON numbers like this: * //from w ww . j a va 2 s . c o m * "val": 5 * * It will also handle numbers in strings like: * * "val": "5" * * @param obj the object with the value * @param key the key for the object * @param defaultValue the default value if the specified key isn't found. * * @return the value or the defaultValue if it could not be decoded */ public static int getIntValue(JSONObject obj, String key, int defaultValue) { if (!obj.containsKey(key)) { return defaultValue; } try { JSONValue v = obj.get(key); if (v != null) { JSONNumber n = v.isNumber(); if (n != null) { return (int) n.doubleValue(); } else { /* * If this isn't a number, then it might be a string * like "5" so we try to parse it as a number. */ return Integer.parseInt(getStringValue(obj, key)); } } } catch (Exception e) { JSUtil.println(e.getMessage()); } return defaultValue; }
From source file:org.spiffyui.client.JSONUtil.java
License:Apache License
/** * Get a double from the JSON object or the defaultValue if it doesn't exist or * isn't a double. This will handle JSON numbers like this: * * "val": 0.5 or "val": -0.5 or "val": +0.5 * * It will also handle numbers in strings like: * * "val": "0.5" or "val": "-0.5" or "val": "+0.5" * * @param obj the object with the value * @param key the key for the object//from w ww.j a va2 s.c o m * @param defaultValue the default value if the specified key isn't found. * * @return the value or the defaultValue if it could not be decoded */ public static double getDoubleValue(JSONObject obj, String key, double defaultValue) { if (!obj.containsKey(key)) { return defaultValue; } try { JSONValue v = obj.get(key); if (v != null) { JSONNumber n = v.isNumber(); if (n != null) { return n.doubleValue(); } else { /* * If this isn't a number, then it might be a string * like "5" so we try to parse it as a number. */ return Double.parseDouble(getStringValue(obj, key)); } } } catch (Exception e) { JSUtil.println(e.getMessage()); } return defaultValue; }
From source file:org.spiffyui.client.JSONUtil.java
License:Apache License
/** * Get a long from the JSON object or the defaultValue if it doesn't exist or * isn't a long. This will handle JSON numbers like this: * //w ww . ja va 2s .c o m * "val": 5 * * It will also handle numbers in strings like: * * "val": "5" * * @param obj the object with the value * @param key the key for the object * @param defaultValue the default value if the specified key isn't found. * * @return the value or the defaultValue if it could not be decoded */ public static long getLongValue(JSONObject obj, String key, long defaultValue) { if (!obj.containsKey(key)) { return defaultValue; } try { JSONValue v = obj.get(key); if (v != null) { JSONNumber n = v.isNumber(); if (n != null) { return (long) n.doubleValue(); } else { /* * If this isn't a number, then it might be a string * like "5" so we try to parse it as a number. */ return Long.parseLong(getStringValue(obj, key)); } } } catch (Exception e) { JSUtil.println(e.getMessage()); } return defaultValue; }
From source file:org.spiffyui.client.JSONUtil.java
License:Apache License
/** * Get a java.util.Date from the JSON object as an epoch time in milliseconds * or return null if it doesn't exist or * cannot be converted from epoch to Date * //from ww w. j a v a2s . c o m * @param obj the object with the value * @param key the key for the object * * @return the value or null it could not be decoded/converted */ public static Date getDateValue(JSONObject obj, String key) { JSONValue v = obj.get(key); if (v != null) { JSONNumber n = v.isNumber(); if (n != null) { return new Date(Double.valueOf(n.doubleValue()).longValue()); } else { String s = getStringValue(obj, key); if (s != null) { return new Date(Long.parseLong(s)); } } } return null; }
From source file:org.utgenome.gwt.utgb.client.db.datatype.IntegerType.java
License:Apache License
public String toString(JSONValue value) { JSONNumber n = value.isNumber(); if (n != null) return Integer.toString((int) n.doubleValue()); else {//from w w w . j av a 2 s . co m return super.toString(value); } }