本文整理了Java中elemental.json.JsonObject.hasKey()
方法的一些代码示例,展示了JsonObject.hasKey()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonObject.hasKey()
方法的具体详情如下:
包路径:elemental.json.JsonObject
类名称:JsonObject
方法名:hasKey
[英]Test whether a given key has present.
[中]测试给定的密钥是否存在。
代码示例来源:origin: com.vaadin/vaadin-server
private String getConfigOrNull(String name) {
JsonObject parameters = context.getApplicationParameters();
if (parameters.hasKey(name)) {
return parameters.getString(name);
} else {
return null;
}
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Gets a data object with the given key from the given JsonObject. If
* there is no object with the key, this method creates a new
* JsonObject.
*
* @param jsonObject
* the json object
* @param key
* the key where the desired data object is stored
* @return data object for the given key
*/
private JsonObject getDataObject(JsonObject jsonObject, String key) {
if (!jsonObject.hasKey(key)) {
jsonObject.put(key, Json.createObject());
}
return jsonObject.getObject(key);
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Sets the expected value of a state property so that changes can be
* properly sent to the client. This needs to be done in cases where a state
* change originates from the client, since otherwise the server-side would
* fail to recognize if the value is changed back to its previous value.
*
* @param propertyName
* the name of the shared state property to update
* @param newValue
* the new diffstate reference value
*/
protected void updateDiffstate(String propertyName, JsonValue newValue) {
if (!isAttached()) {
return;
}
JsonObject diffState = getUI().getConnectorTracker().getDiffState(this);
if (diffState == null) {
return;
}
assert diffState.hasKey(propertyName) : "Diffstate for "
+ getClass().getName() + " has no property named "
+ propertyName;
diffState.put(propertyName, newValue);
}
}
代码示例来源:origin: com.vaadin/vaadin-server
if (json.hasKey(ApplicationConstants.RESYNCHRONIZE_ID)) {
resynchronize = json
.getBoolean(ApplicationConstants.RESYNCHRONIZE_ID);
resynchronize = false;
if (json.hasKey(ApplicationConstants.WIDGETSET_VERSION_ID)) {
widgetsetVersion = json
.getString(ApplicationConstants.WIDGETSET_VERSION_ID);
if (json.hasKey(ApplicationConstants.CLIENT_TO_SERVER_ID)) {
clientToServerMessageId = (int) json
.getNumber(ApplicationConstants.CLIENT_TO_SERVER_ID);
代码示例来源:origin: com.vaadin/vaadin-server
if (!hierachyInfo.hasKey(firstVisibleParent.getConnectorId())) {
代码示例来源:origin: com.vaadin/vaadin-server
Object fieldValue = property.getValue(value);
if (encoded.hasKey(fieldName)) {
throw new RuntimeException("Can't encode "
+ valueType.getName()
代码示例来源:origin: com.vaadin/flow-server
private static boolean isTemplateModelValue(Component instance,
JsonValue argValue, Class<?> convertedType) {
return instance instanceof PolymerTemplate
&& argValue instanceof JsonObject
&& ((PolymerTemplate<?>) instance)
.isSupportedClass(convertedType)
&& ((JsonObject) argValue).hasKey("nodeId");
}
代码示例来源:origin: com.vaadin/flow-server
private static Map<LoadMode, JsonArray> popDependenciesToProcessOnServer(
JsonObject initialUIDL) {
Map<LoadMode, JsonArray> result = new EnumMap<>(LoadMode.class);
Stream.of(LoadMode.EAGER, LoadMode.INLINE).forEach(mode -> {
if (initialUIDL.hasKey(mode.name())) {
result.put(mode, initialUIDL.getArray(mode.name()));
initialUIDL.remove(mode.name());
}
});
return result;
}
代码示例来源:origin: com.vaadin/flow-maven-plugin
private String getPackageName(ArtifactData webJar, String nameSourceJarPath) {
String fileContents;
try {
fileContents = IOUtils.toString(jarContentsManager.getFileContents(webJar.getFileOrDirectory(), nameSourceJarPath), StandardCharsets.UTF_8.displayName());
} catch (IOException e) {
throw new UncheckedIOException(String.format("Unable to read file '%s' from webJar '%s'", nameSourceJarPath, webJar.getFileOrDirectory()), e);
}
JsonObject jsonObject = Json.parse(fileContents);
if (jsonObject.hasKey("name")) {
String name = jsonObject.getString("name");
return name.substring(name.lastIndexOf('/') + 1);
} else {
throw new IllegalStateException(String.format("Incorrect WebJar '%s': file '%s' inside it has no 'name' field", webJar, nameSourceJarPath));
}
}
代码示例来源:origin: com.vaadin/hummingbird-server
@Override
protected void handleNode(StateNode node, JsonObject invocationJson) {
assert invocationJson.hasKey(JsonConstants.RPC_PROPERTY);
assert invocationJson.hasKey(JsonConstants.RPC_PROPERTY_VALUE);
String property = invocationJson.getString(JsonConstants.RPC_PROPERTY);
Serializable value = JsonCodec.decodeWithoutTypeInfo(
invocationJson.get(JsonConstants.RPC_PROPERTY_VALUE));
node.getFeature(ElementPropertyMap.class).setProperty(property, value,
false);
}
代码示例来源:origin: com.haulmont.cuba/cuba-web-toolkit
@Override
protected void afterUpdatesOptionsBox(List<JsonObject> items) {
int index = 0;
for (JsonObject item : items) {
CubaDoubleClickListBox cubaSelections = (CubaDoubleClickListBox) optionsListBox;
if (item.hasKey("style")) {
cubaSelections.setOptionClassName(index, item.getString("style"));
} else {
cubaSelections.removeClassName(index);
}
index++;
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-web-toolkit
@Override
protected void afterUpdatesSelectionsBox(List<JsonObject> selection) {
int index = 0;
for (JsonObject item : selection) {
CubaDoubleClickListBox cubaSelections = (CubaDoubleClickListBox) selectionsListBox;
if (item.hasKey("style")) {
cubaSelections.setOptionClassName(index, item.getString("style"));
} else {
cubaSelections.removeClassName(index);
}
index++;
}
}
代码示例来源:origin: org.eclipse.che.core/che-core-ide-app
/**
* Determines whether perspective is maximized.
*
* @param partStacksState part stack state
* @return <b>true</b> is perspective has maximized part stack
*/
private boolean isPerspectiveMaximized(JsonObject partStacksState) {
for (String partStackType : partStacksState.keys()) {
JsonObject partStackState = partStacksState.getObject(partStackType);
if (partStackState.hasKey(PART_STACK_STATE)
&& PartStack.State.MAXIMIZED.name().equals(partStackState.getString(PART_STACK_STATE))) {
return true;
}
}
return false;
}
代码示例来源:origin: com.vaadin/vaadin-upload-flow
private String getStringObject(String propertyName, String object,
String subName) {
String result = null;
JsonObject json = (JsonObject) getElement()
.getPropertyRaw(propertyName);
if (json != null && json.hasKey(object)
&& !(json.get(object) instanceof JsonNull)) {
json = json.getObject(object);
if (json != null && json.hasKey(subName)
&& !(json.get(subName) instanceof JsonNull)) {
result = json.getString(subName);
}
}
return result;
}
代码示例来源:origin: com.vaadin/flow-server
private Serializable tryConvert(Serializable value, StateNode context) {
if (value instanceof JsonObject) {
JsonObject json = (JsonObject) value;
if (json.hasKey("nodeId")) {
StateTree tree = (StateTree) context.getOwner();
double id = json.getNumber("nodeId");
StateNode stateNode = tree.getNodeById((int) id);
return tryCopyStateNode(stateNode, json);
}
}
return value;
}
代码示例来源:origin: com.vaadin/vaadin-upload-flow
private String getStringObject(String propertyName, String subName) {
String result = null;
JsonObject json = (JsonObject) getElement()
.getPropertyRaw(propertyName);
if (json != null && json.hasKey(subName)
&& !(json.get(subName) instanceof JsonNull)) {
result = json.getString(subName);
}
return result;
}
代码示例来源:origin: org.eclipse.che.core/che-core-ide-app
@Override
public Promise<Void> loadState(JsonObject state) {
if (state.hasKey(PERSPECTIVES)) {
JsonObject perspectives = state.getObject(PERSPECTIVES);
Map<String, Perspective> perspectiveMap = perspectiveManagerProvider.get().getPerspectives();
ArrayOf<Promise<?>> perspectivePromises = Collections.arrayOf();
for (String key : perspectives.keys()) {
if (perspectiveMap.containsKey(key)) {
perspectivePromises.push(perspectiveMap.get(key).loadState(perspectives.getObject(key)));
}
}
return promises.all2(perspectivePromises).thenPromise(ignored -> promises.resolve(null));
}
return promises.resolve(null);
}
代码示例来源:origin: com.vaadin/flow-server
@Override
public Optional<Runnable> handleNode(StateNode node, JsonObject invocationJson) {
assert invocationJson.hasKey(JsonConstants.RPC_EVENT_TYPE);
String eventType = invocationJson
.getString(JsonConstants.RPC_EVENT_TYPE);
JsonObject eventData = invocationJson
.getObject(JsonConstants.RPC_EVENT_DATA);
if (eventData == null) {
eventData = Json.createObject();
}
DomEvent event = new DomEvent(Element.get(node), eventType, eventData);
node.getFeature(ElementListenerMap.class).fireEvent(event);
return Optional.empty();
}
代码示例来源:origin: com.vaadin/hummingbird-server
@Override
public void handle(UI ui, JsonObject invocationJson) {
assert invocationJson.hasKey(JsonConstants.RPC_NODE);
StateNode node = ui.getInternals().getStateTree()
.getNodeById(getNodeId(invocationJson));
if (node == null) {
getLogger().warning("Got an RPC for non-existent node: "
+ getNodeId(invocationJson));
return;
}
if (!node.isAttached()) {
getLogger().warning("Got an RPC for detached node: "
+ getNodeId(invocationJson));
return;
}
handleNode(node, invocationJson);
}
代码示例来源:origin: com.vaadin/hummingbird-server
@Override
public void handleNode(StateNode node, JsonObject invocationJson) {
assert invocationJson.hasKey(JsonConstants.RPC_EVENT_TYPE);
String eventType = invocationJson
.getString(JsonConstants.RPC_EVENT_TYPE);
JsonObject eventData = invocationJson
.getObject(JsonConstants.RPC_EVENT_DATA);
if (eventData == null) {
eventData = Json.createObject();
}
DomEvent event = new DomEvent(Element.get(node), eventType, eventData);
node.getFeature(ElementListenerMap.class).fireEvent(event);
}
内容来源于网络,如有侵权,请联系作者删除!