Example usage for com.google.gson JsonArray contains

List of usage examples for com.google.gson JsonArray contains

Introduction

In this page you can find the example usage for com.google.gson JsonArray contains.

Prototype

public boolean contains(JsonElement element) 

Source Link

Document

Returns true if this array contains the specified element.

Usage

From source file:arces.unibo.SEPA.commons.SPARQL.BindingsResults.java

License:Open Source License

public boolean contains(Bindings solution) {
    if (solution == null)
        return false;
    JsonArray bindings = getBindingsArray();
    if (bindings == null)
        return false;

    return bindings.contains(solution.toJson());
}

From source file:ch.jamiete.hilda.admin.commands.AdminAllowCommand.java

License:Apache License

@Override
public void execute(final Message message, final String[] arguments, final String label) {
    if (arguments.length == 1 && arguments[0].equalsIgnoreCase("list")) {
        final List<String> strings = new ArrayList<>();

        for (String str : this.hilda.getAllowedServers()) {
            Guild guild = this.hilda.getBot().getGuildById(str);

            if (guild != null) {
                strings.add(this.name(guild));
            }/*  w w w. j  a  v  a 2 s  . co  m*/
        }

        if (strings.isEmpty()) {
            this.reply(message, "The whitelist function is not enabled!");
        } else {
            final MessageBuilder mb = new MessageBuilder();
            mb.append("I'm currently allowing ");

            if (strings.size() != this.hilda.getBot().getGuilds().size()) {
                mb.append("only ");
            }

            mb.append(strings.size()).append(strings.size() == 1 ? "server" : "servers").append(": ");
            mb.append(Util.getAsList(strings));
            mb.append(".");
            this.reply(message, mb.build());
        }

        return;
    }

    if (arguments.length == 0) {
        this.usage(message, "<id.../list>");
    }

    final AllowDirection direction = AllowDirection.valueOf(label.toUpperCase());
    final List<String> ids = new ArrayList<>();
    final List<String> success = new ArrayList<>();
    final List<String> fail = new ArrayList<>();

    for (final String arg : arguments) {
        Guild guild = this.hilda.getBot().getGuildById(arg);

        if (guild == null) {
            fail.add(arg);
        } else {
            ids.add(arg);
            success.add(this.name(guild));
        }
    }

    if (!success.isEmpty()) {
        final Configuration cfg = this.hilda.getConfigurationManager().getConfiguration(this.plugin,
                "allowedservers");
        JsonArray array = cfg.get().getAsJsonArray("servers");

        if (array == null) {
            array = new JsonArray();
        }

        for (final String id : ids) {
            if (direction == AllowDirection.ALLOW) {
                this.hilda.addAllowedServer(id);

                if (!array.contains(new JsonPrimitive(id))) {
                    array.add(id);
                }
            }

            if (direction == AllowDirection.DISALLOW) {
                this.hilda.removeAllowedServer(id);
                array.remove(new JsonPrimitive(id));
            }
        }

        cfg.get().add("servers", array);
        cfg.save();
    }

    final MessageBuilder mb = new MessageBuilder();

    mb.append("OK, ");

    if (!success.isEmpty()) {
        mb.append("I'm ").append(direction == AllowDirection.ALLOW ? "now" : "no longer").append(" allowing ");
        mb.append(Util.getAsList(success));
    }

    if (!fail.isEmpty()) {
        if (!success.isEmpty()) {
            mb.append(", however ");
        }

        mb.append("I couldn't find any servers matching ");
        mb.append(Util.getAsList(fail));
    }

    mb.append(".");

    mb.buildAll(SplitPolicy.SPACE).forEach(m -> message.getChannel().sendMessage(m).queue());
}

From source file:ch.jamiete.hilda.admin.commands.AdminIgnoreCommand.java

License:Apache License

@Override
public void execute(final Message message, final String[] arguments, final String label) {
    if (arguments.length == 1 && arguments[0].equalsIgnoreCase("list")) {
        final List<String> strings = this.hilda.getCommandManager().getIgnoredUsers();

        if (strings.isEmpty()) {
            this.reply(message, "I'm not ignoring any channels!");
        } else {/*w  ww .  j  ava  2  s  . co  m*/
            final MessageBuilder mb = new MessageBuilder();
            mb.append("I'm currently ignoring ");
            mb.append(Util.getAsList(this.getPieces(strings)));
            mb.append(".");
            this.reply(message, mb.build());
        }

        return;
    }

    if (arguments.length == 0) {
        this.usage(message, "<@user.../id...>");
    }

    final IgnoreDirection direction = IgnoreDirection.valueOf(label.toUpperCase());
    final List<String> ids = new ArrayList<>();

    if (!message.getMentionedUsers().isEmpty()) {
        message.getMentionedUsers().forEach(u -> ids.add(u.getId()));
    }

    for (final String arg : arguments) {
        if (!arg.startsWith("<@")) {
            ids.add(arg);
        }
    }

    final Configuration cfg = this.hilda.getConfigurationManager().getConfiguration(this.plugin,
            "ignoredusers");
    JsonArray array = cfg.get().getAsJsonArray("users");

    if (array == null) {
        array = new JsonArray();
    }

    for (final String id : ids) {
        if (direction == IgnoreDirection.IGNORE) {
            this.hilda.getCommandManager().addIgnoredUser(id);

            if (!array.contains(new JsonPrimitive(id))) {
                array.add(id);
            }
        }

        if (direction == IgnoreDirection.UNIGNORE) {
            this.hilda.getCommandManager().removeIgnoredUser(id);
            array.remove(new JsonPrimitive(id));
        }
    }

    cfg.get().add("users", array);
    cfg.save();

    final MessageBuilder mb = new MessageBuilder();

    mb.append("OK, I'm ").append(direction == IgnoreDirection.IGNORE ? "now" : "no longer")
            .append(" ignoring ");
    mb.append(Util.getAsList(this.getPieces(ids)));
    mb.append(".");

    mb.buildAll(SplitPolicy.SPACE).forEach(m -> message.getChannel().sendMessage(m).queue());
}

From source file:ch.jamiete.hilda.moderatortools.commands.IgnoreCommand.java

License:Apache License

@Override
public void execute(final Message message, final String[] arguments, final String label) {
    if (arguments.length == 1 && arguments[0].equalsIgnoreCase("list")) {
        final MessageBuilder mb = new MessageBuilder();
        final List<String> strings = this.hilda.getCommandManager().getIgnoredChannels();
        final List<TextChannel> ignored = new ArrayList<TextChannel>();

        for (final String s : strings) {
            final TextChannel c = message.getGuild().getTextChannelById(s);

            if (c != null) {
                ignored.add(c);//  w  ww.  j a v  a 2  s.  co m
            }
        }

        if (ignored.isEmpty()) {
            this.reply(message, "I'm not ignoring any channels!");
        } else {
            mb.append("I'm currently ignoring ");

            for (final TextChannel c : ignored) {
                mb.append(c.getAsMention());
                mb.append(", ");
            }

            mb.replaceLast(", ", "");
            mb.append(".");
            this.reply(message, mb.build());
        }

        return;
    }

    final IgnoreDirection direction = IgnoreDirection.valueOf(label.toUpperCase());
    final List<TextChannel> channels = new ArrayList<TextChannel>();

    if (arguments.length == 0) {
        channels.add(message.getTextChannel());
    }

    if (!message.getMentionedChannels().isEmpty()) {
        channels.addAll(message.getMentionedChannels());
    }

    final Configuration cfg = this.hilda.getConfigurationManager().getConfiguration(this.plugin,
            "ignore-" + message.getGuild().getId());
    JsonArray array = cfg.get().getAsJsonArray("channels");

    if (array == null) {
        array = new JsonArray();
    }

    for (final TextChannel channel : channels) {
        if (direction == IgnoreDirection.IGNORE) {
            this.hilda.getCommandManager().addIgnoredChannel(channel.getId());

            if (!array.contains(new JsonPrimitive(channel.getId()))) {
                array.add(channel.getId());
            }
        }

        if (direction == IgnoreDirection.UNIGNORE) {
            this.hilda.getCommandManager().removeIgnoredChannel(channel.getId());
            array.remove(new JsonPrimitive(channel.getId()));
        }
    }

    cfg.get().add("channels", array);
    cfg.save();

    final MessageBuilder mb = new MessageBuilder();

    mb.append("OK, I'm ").append(direction == IgnoreDirection.IGNORE ? "now" : "no longer")
            .append(" ignoring ");
    mb.append(Util.getChannelsAsString(channels));
    mb.append(".");

    mb.buildAll().forEach(m -> message.getChannel().sendMessage(m).queue());
}

From source file:de.dfki.mmf.attributeselection.AttributeSelectionAlgorithm.java

License:Open Source License

/**
 * @return list with JsonObjects each containing those attributes of the queried object which discriminates it from the compared database object
 */// w ww.ja v a  2 s  . c om
public List<JsonObject> computeSingleDiscriminatingIdentifiers() {
    //data structure to save discriminating identifiers resulting from the comparisons between queried object and each database object
    ArrayList<JsonObject> identifiers = new ArrayList<>();
    for (JsonObject databaseObject : databaseObjects) {
        //create list for each comparison of queried object properties and the properties of a database object
        // to save property values which uniquely identify queried object
        JsonObject singleDiscriminatingIdentifiers = new JsonObject();
        //go over each property of the queried object
        Set<Map.Entry<String, JsonElement>> entrySet = queriedObject.entrySet();
        for (Map.Entry<String, JsonElement> entry : entrySet) {
            String queryKey = entry.getKey();
            //check saliencyAnnotation is exists
            if (saliencyAnnotations != null) {
                //look up the saliency annotation of the object
                if (saliencyAnnotations.has(queryKey)) {
                    double saliencyNbr = saliencyAnnotations.get(queryKey).getAsDouble();
                    //if saliency is lower than threshold -> property will be pruned, continue with next property
                    if (saliencyNbr < saliencyThreshold) {
                        continue;
                    }
                } else {
                    continue;
                }
            }
            //the values the queried object has for certain property
            JsonElement queriedPropertyValues = queriedObject.get(queryKey);
            //check if database object has this property
            if (databaseObject.has(queryKey)) {
                //get the values the database object has for this property
                JsonElement dataPropertyValues = databaseObject.get(queryKey);
                //check if objects have the same values for this property -> if not add values of queried object to list
                if ((queriedPropertyValues.isJsonArray() && !dataPropertyValues.isJsonArray())
                        || (!queriedPropertyValues.isJsonArray() && dataPropertyValues.isJsonArray())) {
                    singleDiscriminatingIdentifiers.add(queryKey, queriedPropertyValues);
                } else if (!queriedPropertyValues.isJsonArray() && !dataPropertyValues.isJsonArray()) {
                    if (!Objects.equals(queriedPropertyValues.toString(), dataPropertyValues.toString())) {
                        singleDiscriminatingIdentifiers.add(queryKey, queriedPropertyValues);
                    }
                } else if (queriedPropertyValues.isJsonArray() && dataPropertyValues.isJsonArray()) {
                    JsonArray queryArray = queriedPropertyValues.getAsJsonArray();
                    JsonArray dataArray = dataPropertyValues.getAsJsonArray();
                    boolean added = false;
                    for (JsonElement queryElement : queryArray) {
                        if (!dataArray.contains(queryElement)) {
                            singleDiscriminatingIdentifiers.add(queryKey, queriedPropertyValues);
                            added = true;
                            break;
                        }
                    }
                    if (!added) {
                        for (JsonElement dataElement : dataArray) {
                            if (!queryArray.contains(dataElement)) {
                                singleDiscriminatingIdentifiers.add(queryKey, queriedPropertyValues);
                                break;
                            }
                        }
                    }
                }
                //compared database object does not have particular property -> can be seen as differentiating
            } else {
                singleDiscriminatingIdentifiers.add(queryKey, queriedPropertyValues);
            }
        }
        //add single discriminating identifiers to list with all found identifiers
        identifiers.add(singleDiscriminatingIdentifiers);
    }
    return identifiers;
}

From source file:it.unibo.arces.wot.sepa.commons.sparql.BindingsResults.java

License:Open Source License

/**
 * Contains.//  w w  w. ja v a 2 s .c o m
 *
 * @param solution
 *            the solution
 * @return true, if successful
 */
public boolean contains(Bindings solution) {
    if (solution == null)
        return false;
    JsonArray bindings = getBindingsArray();
    if (bindings == null)
        return false;

    return bindings.contains(solution.toJson());
}

From source file:org.ballerinalang.composer.service.workspace.tools.ModelGenerator.java

License:Open Source License

public static JsonObject getContext() {
    // Set alias for the classes
    alias.put("ImportNode", "ImportPackageNode");
    alias.put("RecordLiteralKeyValueNode", "RecordKeyValueNode");
    alias.put("XmlnsNode", "XMLNSDeclarationNode");
    alias.put("ArrayLiteralExprNode", "ArrayLiteralNode");
    alias.put("BinaryExprNode", "BinaryExpressionNode");
    alias.put("ConnectorInitExprNode", "ConnectorInitNode");
    alias.put("FieldBasedAccessExprNode", "FieldBasedAccessNode");
    alias.put("IndexBasedAccessExprNode", "IndexBasedAccessNode");
    alias.put("LambdaNode", "LambdaFunctionNode");
    alias.put("RecordLiteralExprNode", "RecordLiteralNode");
    alias.put("SimpleVariableRefNode", "SimpleVariableReferenceNode");
    alias.put("TernaryExprNode", "TernaryExpressionNode");
    alias.put("TypeCastExprNode", "TypeCastNode");
    alias.put("TypeConversionExprNode", "TypeConversionNode");
    alias.put("UnaryExprNode", "UnaryExpressionNode");
    alias.put("XmlAttributeNode", "XMLAttributeNode");
    alias.put("XmlCommentLiteralNode", "XMLCommentLiteralNode");
    alias.put("XmlElementLiteralNode", "XMLElementLiteralNode");
    alias.put("XmlPiLiteralNode", "XMLProcessingInstructionLiteralNode");
    alias.put("XmlQnameNode", "XMLQNameNode");
    alias.put("XmlQuotedStringNode", "XMLQuotedStringNode");
    alias.put("XmlTextLiteralNode", "XMLTextLiteralNode");
    alias.put("TryNode", "TryCatchFinallyNode");
    alias.put("VariableDefNode", "VariableDefinitionNode");
    alias.put("BuiltInRefTypeNode", "BuiltInReferenceTypeNode");
    alias.put("EnumeratorNode", "EnumNode");

    List<Class<?>> list = ModelGenerator.find("org.ballerinalang.model.tree");

    NodeKind[] nodeKinds = NodeKind.class.getEnumConstants();
    JsonObject nodes = new JsonObject();
    for (NodeKind node : nodeKinds) {
        String nodeKind = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, node.toString());
        String nodeClassName = nodeKind + "Node";
        try {//  www.  j  a va  2s  .  c o  m
            String actualClassName = (alias.get(nodeClassName) != null) ? alias.get(nodeClassName)
                    : nodeClassName;
            Class<?> clazz = list.stream()
                    .filter(nodeClass -> nodeClass.getSimpleName().equals(actualClassName)).findFirst().get();

            JsonObject nodeObj = new JsonObject();
            nodeObj.addProperty("kind", nodeKind);
            nodeObj.addProperty("name", nodeClassName);
            nodeObj.addProperty("fileName", CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, nodeClassName));
            JsonArray attr = new JsonArray();
            JsonArray bools = new JsonArray();
            JsonArray imports = new JsonArray();
            List<String> parents = Arrays.asList(clazz.getInterfaces()).stream()
                    .map(parent -> parent.getSimpleName()).collect(Collectors.toList());

            // tag object with supper type
            if (parents.contains("StatementNode")) {
                nodeObj.addProperty("isStatement", true);
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "StatementNode");
                imp.addProperty("returnTypeFile", "statement-node");
                imports.add(imp);
            } else {
                nodeObj.addProperty("isStatement", false);
            }

            if (parents.contains("ExpressionNode")) {
                nodeObj.addProperty("isExpression", true);
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "ExpressionNode");
                imp.addProperty("returnTypeFile", "expression-node");
                imports.add(imp);
            } else {
                nodeObj.addProperty("isExpression", false);
            }

            if (!parents.contains("StatementNode") && !parents.contains("ExpressionNode")) {
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "Node");
                imp.addProperty("returnTypeFile", "node");
                imports.add(imp);
            }

            Method[] methods = clazz.getMethods();
            for (Method m : methods) {
                String methodName = m.getName();
                if ("getKind".equals(methodName) || "getWS".equals(methodName)
                        || "getPosition".equals(methodName)) {
                    continue;
                }
                if (methodName.startsWith("get")) {
                    JsonObject attribute = new JsonObject();
                    JsonObject imp = new JsonObject();
                    attribute.addProperty("property", toJsonName(m.getName(), 3));
                    attribute.addProperty("methodSuffix", m.getName().substring(3));
                    attribute.addProperty("list", List.class.isAssignableFrom(m.getReturnType()));
                    attribute.addProperty("isNode", Node.class.isAssignableFrom(m.getReturnType()));
                    if (Node.class.isAssignableFrom(m.getReturnType())) {
                        String returnClass = m.getReturnType().getSimpleName();
                        if (alias.containsValue(m.getReturnType().getSimpleName())) {
                            returnClass = getKindForAliasClass(m.getReturnType().getSimpleName());
                        }
                        imp.addProperty("returnType", returnClass);
                        attribute.addProperty("returnType", returnClass);
                        imp.addProperty("returnTypeFile",
                                CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, returnClass));
                        if (!imports.contains(imp)) {
                            imports.add(imp);
                        }
                    }
                    attr.add(attribute);
                }
                if (methodName.startsWith("is")) {
                    JsonObject attribute = new JsonObject();
                    JsonObject imp = new JsonObject();
                    attribute.addProperty("property", toJsonName(m.getName(), 2));
                    attribute.addProperty("methodSuffix", m.getName().substring(2));
                    attribute.addProperty("list", List.class.isAssignableFrom(m.getReturnType()));
                    attribute.addProperty("isNode", Node.class.isAssignableFrom(m.getReturnType()));
                    if (Node.class.isAssignableFrom(m.getReturnType())) {
                        String returnClass = m.getReturnType().getSimpleName();
                        if (alias.containsValue(m.getReturnType().getSimpleName())) {
                            returnClass = getKindForAliasClass(m.getReturnType().getSimpleName());
                        }
                        imp.addProperty("returnType", returnClass);
                        attribute.addProperty("returnType", returnClass);
                        imp.addProperty("returnTypeFile",
                                CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, returnClass));
                        if (!imports.contains(imp)) {
                            imports.add(imp);
                        }
                    }
                    bools.add(attribute);
                }
            }
            nodeObj.add("attributes", attr);
            nodeObj.add("bools", bools);
            nodeObj.add("imports", imports);
            nodes.add(nodeClassName, nodeObj);
        } catch (NoSuchElementException e) {
            out.println("alias.put(\"" + nodeClassName + "\", \"\");");
        }
    }
    out.println(nodes);
    return nodes;
}

From source file:org.ballerinalang.composer.tools.ModelGenerator.java

License:Open Source License

public static JsonObject getContext() {

    // Set alias for the classes
    alias.put("ImportNode", "ImportPackageNode");
    alias.put("ArrayLiteralExprNode", "ArrayLiteralNode");
    alias.put("BinaryExprNode", "BinaryExpressionNode");
    alias.put("BracedTupleExprNode", "BracedOrTupleExpression");
    alias.put("TypeInitExprNode", "TypeInitNode");
    alias.put("FieldBasedAccessExprNode", "FieldBasedAccessNode");
    alias.put("IndexBasedAccessExprNode", "IndexBasedAccessNode");
    alias.put("IntRangeExprNode", "IntRangeExpression");
    alias.put("LambdaNode", "LambdaFunctionNode");
    alias.put("SimpleVariableRefNode", "SimpleVariableReferenceNode");
    alias.put("TernaryExprNode", "TernaryExpressionNode");
    alias.put("AwaitExprNode", "AwaitExpressionNode");
    alias.put("TypeCastExprNode", "TypeCastNode");
    alias.put("TypeConversionExprNode", "TypeConversionNode");
    alias.put("UnaryExprNode", "UnaryExpressionNode");
    alias.put("RestArgsExprNode", "RestArgsNode");
    alias.put("NamedArgsExprNode", "NamedArgNode");
    alias.put("MatchExpressionPatternClauseNode", "MatchExpressionNode");
    alias.put("MatchPatternClauseNode", "MatchStatementPatternNode");
    alias.put("TryNode", "TryCatchFinallyNode");
    alias.put("VariableDefNode", "VariableDefinitionNode");
    alias.put("UnionTypeNodeNode", "UnionTypeNode");
    alias.put("TupleTypeNodeNode", "TupleTypeNode");
    alias.put("EndpointTypeNode", "UserDefinedTypeNode");
    alias.put("StreamingQueryNode", "StreamingQueryStatementNode");
    alias.put("WithinNode", "WithinClause");
    alias.put("PatternClauseNode", "PatternClause");
    alias.put("ElvisExprNode", "ElvisExpressionNode");
    alias.put("CheckExprNode", "CheckedExpressionNode");
    alias.put("RecordLiteralExprNode", "RecordLiteralNode");
    alias.put("TypeDefinitionNode", "TypeDefinition");

    alias.put("EnumeratorNode", "");
    alias.put("RecordLiteralKeyValueNode", "");
    alias.put("TableNode", "");
    alias.put("XmlnsNode", "");
    alias.put("IsAssignableExprNode", "");
    alias.put("XmlQnameNode", "");
    alias.put("XmlAttributeNode", "");
    alias.put("XmlAttributeAccessExprNode", "");
    alias.put("XmlQuotedStringNode", "");
    alias.put("XmlElementLiteralNode", "");
    alias.put("XmlTextLiteralNode", "");
    alias.put("XmlCommentLiteralNode", "");
    alias.put("XmlPiLiteralNode", "");
    alias.put("XmlSequenceLiteralNode", "");
    alias.put("TableQueryExpressionNode", "");
    alias.put("NextNode", "");
    alias.put("TransformNode", "");
    alias.put("StreamNode", "");
    alias.put("FiniteTypeNodeNode", "");
    alias.put("BuiltInRefTypeNode", "");
    alias.put("StreamingInputNode", "");
    alias.put("JoinStreamingInputNode", "");
    alias.put("TableQueryNode", "");
    alias.put("SetAssignmentClauseNode", "");
    alias.put("SetNode", "");
    alias.put("QueryNode", "");
    alias.put("StreamingQueryDeclarationNode", "");

    List<Class<?>> list = ModelGenerator.find("org.ballerinalang.model.tree");

    NodeKind[] nodeKinds = NodeKind.class.getEnumConstants();
    JsonObject nodes = new JsonObject();
    for (NodeKind node : nodeKinds) {
        String nodeKind = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, node.toString());
        String nodeClassName = nodeKind + "Node";
        try {/*from  w  w w .  ja  v  a  2 s  .c  o m*/
            String actualClassName = (alias.get(nodeClassName) != null) ? alias.get(nodeClassName)
                    : nodeClassName;
            Class<?> clazz = list.stream()
                    .filter(nodeClass -> nodeClass.getSimpleName().equals(actualClassName)).findFirst().get();

            JsonObject nodeObj = new JsonObject();
            nodeObj.addProperty("kind", nodeKind);
            nodeObj.addProperty("name", nodeClassName);
            nodeObj.addProperty("fileName", CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, nodeClassName));
            JsonArray attr = new JsonArray();
            JsonArray bools = new JsonArray();
            JsonArray imports = new JsonArray();
            List<String> parents = Arrays.asList(clazz.getInterfaces()).stream()
                    .map(parent -> parent.getSimpleName()).collect(Collectors.toList());

            // tag object with supper type
            if (parents.contains("StatementNode")) {
                nodeObj.addProperty("isStatement", true);
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "StatementNode");
                imp.addProperty("returnTypeFile", "statement-node");
                imports.add(imp);
            } else {
                nodeObj.addProperty("isStatement", false);
            }

            if (parents.contains("ExpressionNode")) {
                nodeObj.addProperty("isExpression", true);
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "ExpressionNode");
                imp.addProperty("returnTypeFile", "expression-node");
                imports.add(imp);
            } else {
                nodeObj.addProperty("isExpression", false);
            }

            if (!parents.contains("StatementNode") && !parents.contains("ExpressionNode")) {
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "Node");
                imp.addProperty("returnTypeFile", "node");
                imports.add(imp);
            }

            Method[] methods = clazz.getMethods();
            for (Method m : methods) {
                String methodName = m.getName();
                if ("getKind".equals(methodName) || "getWS".equals(methodName)
                        || "getPosition".equals(methodName)) {
                    continue;
                }
                if (methodName.startsWith("get")) {
                    JsonObject attribute = new JsonObject();
                    JsonObject imp = new JsonObject();
                    attribute.addProperty("property", toJsonName(m.getName(), 3));
                    attribute.addProperty("methodSuffix", m.getName().substring(3));
                    attribute.addProperty("list", List.class.isAssignableFrom(m.getReturnType()));
                    attribute.addProperty("isNode", Node.class.isAssignableFrom(m.getReturnType()));
                    if (Node.class.isAssignableFrom(m.getReturnType())) {
                        String returnClass = m.getReturnType().getSimpleName();
                        if (alias.containsValue(m.getReturnType().getSimpleName())) {
                            returnClass = getKindForAliasClass(m.getReturnType().getSimpleName());
                        }
                        imp.addProperty("returnType", returnClass);
                        attribute.addProperty("returnType", returnClass);
                        imp.addProperty("returnTypeFile",
                                CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, returnClass));
                        if (!imports.contains(imp)) {
                            imports.add(imp);
                        }
                    }
                    attr.add(attribute);
                }
                if (methodName.startsWith("is")) {
                    JsonObject attribute = new JsonObject();
                    JsonObject imp = new JsonObject();
                    attribute.addProperty("property", toJsonName(m.getName(), 2));
                    attribute.addProperty("methodSuffix", m.getName().substring(2));
                    attribute.addProperty("list", List.class.isAssignableFrom(m.getReturnType()));
                    attribute.addProperty("isNode", Node.class.isAssignableFrom(m.getReturnType()));
                    if (Node.class.isAssignableFrom(m.getReturnType())) {
                        String returnClass = m.getReturnType().getSimpleName();
                        if (alias.containsValue(m.getReturnType().getSimpleName())) {
                            returnClass = getKindForAliasClass(m.getReturnType().getSimpleName());
                        }
                        imp.addProperty("returnType", returnClass);
                        attribute.addProperty("returnType", returnClass);
                        imp.addProperty("returnTypeFile",
                                CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, returnClass));
                        if (!imports.contains(imp)) {
                            imports.add(imp);
                        }
                    }
                    bools.add(attribute);
                }
            }
            nodeObj.add("attributes", attr);
            nodeObj.add("bools", bools);
            nodeObj.add("imports", imports);
            nodes.add(nodeClassName, nodeObj);
        } catch (NoSuchElementException e) {
            out.println("alias.put(\"" + nodeClassName + "\", \"\");");
        }
    }
    out.println(nodes);
    return nodes;
}

From source file:org.hibernate.search.backend.elasticsearch.search.query.impl.SourceHitExtractor.java

License:LGPL

@Override
public void contributeRequest(JsonObject requestBody) {
    JsonArray source = REQUEST_SOURCE_ACCESSOR.get(requestBody).orElseGet(() -> {
        JsonArray newSource = new JsonArray();
        REQUEST_SOURCE_ACCESSOR.set(requestBody, newSource);
        return newSource;
    });/* w  w w  . j  a  v  a 2s . c  om*/
    JsonPrimitive fieldPathJson = new JsonPrimitive(absoluteFieldPath);
    if (!source.contains(fieldPathJson)) {
        source.add(fieldPathJson);
    }
}

From source file:org.wso2.am.integration.tests.restapi.GIT_1628_OAuthAppUpdateViaRestApiTestCase.java

License:Open Source License

@Test(description = "Key generation response should contain grant types and callback url")
public void testKeyGenerationResponseContainsGrantTypesAndCallback() throws Exception {
    String url = storeRestApiBaseUrl + "applications/generate-keys?applicationId=" + applicationId;
    String payload = "{\n" + "  \"validityTime\": \"3600\",\n" + "  \"keyType\": \"PRODUCTION\",\n"
            + "  \"accessAllowDomains\": [\"ALL\" ],\n"
            + "  \"callbackUrl\": \"http://GIT_1628.com/prod_callback\",\n"
            + "  \"supportedGrantTypes\":    [\n" + "      \"refresh_token\",\n"
            + "      \"client_credentials\"\n" + "  ]\n" + '}';
    HttpResponse response = HTTPSClientUtils.doPost(url, headers, payload);
    if (response.getResponseCode() != 200) {
        Assert.fail("Key generation failed: Response code is " + response.getResponseCode()
                + " Response message is '" + response.getData() + '\'');
    }//from w  w  w .  j  a va  2 s . c om

    String json = response.getData();
    Gson gson = new Gson();
    JsonObject jsonObject = gson.fromJson(json, JsonObject.class);

    consumerKey = jsonObject.getAsJsonPrimitive("consumerKey").getAsString();
    Assert.assertNotNull(consumerKey, "ConsumerKey is not available in the response:" + response.getData());
    consumerSecret = jsonObject.getAsJsonPrimitive("consumerSecret").getAsString();
    Assert.assertNotNull(consumerSecret,
            "ConsumerSecret is not available in the response:" + response.getData());

    String callbackUrl = jsonObject.getAsJsonPrimitive("callbackUrl").getAsString();
    Assert.assertEquals(callbackUrl, "http://GIT_1628.com/prod_callback");

    JsonArray grantTypes = jsonObject.getAsJsonArray("supportedGrantTypes");
    Assert.assertNotNull(grantTypes, "Grant Types are not available in the response:" + response.getData());

    Assert.assertTrue(grantTypes.contains(new JsonPrimitive("refresh_token")),
            "refresh_token is not available " + "in grant type list. Response: " + response.getData());
    Assert.assertTrue(grantTypes.contains(new JsonPrimitive("client_credentials")),
            "client_credentials is not available " + "in grant type list. Response: " + response.getData());

    Assert.assertFalse(grantTypes.contains(new JsonPrimitive("password")),
            "password is available " + "in grant type list. Response: " + response.getData());
    Assert.assertFalse(grantTypes.contains(new JsonPrimitive("iwa:ntlm")),
            "iwa:ntlm is available " + "in grant type list. Response: " + response.getData());
    Assert.assertFalse(grantTypes.contains(new JsonPrimitive("urn:ietf:params:oauth:grant-type:saml2-bearer")),
            "urn:ietf:params:oauth:grant-type:saml2-bearer is available in grant type list. Response: "
                    + response.getData());
}