Java Code Examples for com.baidu.hugegraph.util.E#checkArgument()

The following examples show how to use com.baidu.hugegraph.util.E#checkArgument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementMapping.java    From hugegraph-loader with Apache License 2.0 6 votes vote down vote up
@Override
public void check() throws IllegalArgumentException {
    E.checkArgument(this.label != null && !this.label.isEmpty(),
                    "The label can't be null or empty");
    E.checkArgument(this.selectedFields.isEmpty() ||
                    this.ignoredFields.isEmpty(),
                    "Not allowed to specify selected(%s) and ignored(%s) " +
                    "fields at the same time, at least one of them " +
                    "must be empty", selectedFields, ignoredFields);
    this.mappingFields.values().forEach(value -> {
        E.checkArgument(value != null,
                        "The value in field_mapping can't be null");
    });
    this.mappingValues.values().forEach(m -> {
        m.values().forEach(value -> {
            E.checkArgument(value != null,
                            "The value in value_mapping can't be null");
        });
    });
}
 
Example 2
Source File: WhereBuilder.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
/**
 * Concat as: (key1, key2...keyn) {@code >=} (val1, val2...valn)
 * @param keys the keys to be concatted with {@code >=} operator
 * @param values the values to be concatted with {@code >=} operator
 * @return WhereBuilder
 */
public WhereBuilder gte(List<String> keys, List<Object> values) {
    E.checkArgument(keys.size() == values.size(),
                    "The size of keys '%s' is not equal with " +
                    "values size '%s'",
                    keys.size(), values.size());
    this.builder.append("(");
    for (int i = 0, n = keys.size(); i < n; i++) {
        this.builder.append(keys.get(i));
        if (i != n - 1) {
            this.builder.append(", ");
        }
    }
    this.builder.append(") >= (");
    for (int i = 0, n = values.size(); i < n; i++) {
        this.builder.append(wrapStringIfNeeded(values.get(i)));
        if (i != n - 1) {
            this.builder.append(", ");
        }
    }
    this.builder.append(")");
    return this;
}
 
Example 3
Source File: BoardSerializer.java    From hugegraph-studio with Apache License 2.0 6 votes vote down vote up
private void ensureFileExist() {
    Preconditions.checkNotNull(filePath);
    LOG.debug("The board file path is: {}", filePath);
    File file = new File(filePath);
    if (!file.exists()) {
        try {
            file.getParentFile().mkdirs();
            file.createNewFile();
        } catch (IOException e) {
            throw new RuntimeException(String.format(
                      "Failed to create board file with path '%s'",
                      filePath), e);
        }
    }
    E.checkArgument(file.exists() && file.isFile(),
                    "Please ensure the board file '%s' exist",
                    filePath);
}
 
Example 4
Source File: GraphTransaction.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
public Number queryNumber(Query query) {
    E.checkArgument(!this.hasUpdate(),
                    "It's not allowed to query number when " +
                    "there are uncommitted records.");

    if (!(query instanceof ConditionQuery)) {
        return super.queryNumber(query);
    }

    QueryList<Number> queries = this.optimizeQueries(query, q -> {
        boolean indexQuery = q.getClass() == IdQuery.class;
        Number result = indexQuery ? q.ids().size() : super.queryNumber(q);
        return new QueryResults<>(IteratorUtils.of(result), q);
    });

    QueryResults<Number> results = queries.empty() ?
                                   QueryResults.empty() :
                                   queries.fetch(this.pageSize);
    Aggregate aggregate = query.aggregateNotNull();
    return aggregate.reduce(results.iterator());
}
 
Example 5
Source File: IndexLabelBuilder.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
private void checkRepeatIndex(SchemaLabel schemaLabel,
                              BiPredicate<List<String>, List<String>> check,
                              IndexType... checkedTypes) {
    for (Id id : schemaLabel.indexLabels()) {
        IndexLabel old = this.graph().indexLabel(id);
        if (!Arrays.asList(checkedTypes).contains(old.indexType())) {
            continue;
        }
        List<String> newFields = this.indexFields;
        List<String> oldFields = this.graph()
                                     .mapPkId2Name(old.indexFields());
        E.checkArgument(!check.test(newFields, oldFields),
                        "Repeated new index label %s(%s) with fields %s " +
                        "due to existed index label %s(%s) with fields %s",
                        this.name, this.indexType, newFields,
                        old.name(), old.indexType(), old.indexFields());
    }
}
 
Example 6
Source File: PropertyKeyAPI.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
public PropertyKey create(PropertyKey propertyKey) {
    Object pkey = propertyKey;
    if (this.client.apiVersionLt("0.47")) {
        E.checkArgument(propertyKey.aggregateType().isNone(),
                        "Not support aggregate property until " +
                        "api version 0.47");
        pkey = propertyKey.switchV46();
    }

    RestResult result = this.client.post(this.path(), pkey);
    return result.readObject(PropertyKey.class);
}
 
Example 7
Source File: HugeConfig.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
private Object validateOption(String key, Object value) {
    E.checkArgument(value instanceof String,
                    "Invalid value for key '%s': %s", key, value);

    TypedOption<?, ?> option = OptionSpace.get(key);
    return option.parseConvert(value);
}
 
Example 8
Source File: CustomizedPathsAPI.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private CustomizePathsTraverser.Step jsonToStep(HugeGraph graph) {
    E.checkArgument(this.degree > 0 || this.degree == NO_LIMIT,
                    "The degree must be > 0, but got: %s",
                    this.degree);
    E.checkArgument(this.sample > 0 || this.sample == NO_LIMIT,
                    "The sample must be > 0, but got: %s",
                    this.sample);
    E.checkArgument(this.degree == NO_LIMIT ||
                    this.degree >= this.sample,
                    "Degree must be greater than or equal to sample," +
                    " but got degree %s and sample %s",
                    this.degree, this.sample);
    Map<Id, String> labelIds = new HashMap<>();
    if (this.labels != null) {
        for (String label : this.labels) {
            EdgeLabel el = graph.edgeLabel(label);
            labelIds.put(el.id(), label);
        }
    }
    PropertyKey weightBy = null;
    if (this.weightBy != null) {
        weightBy = graph.propertyKey(this.weightBy);
    }
    return new CustomizePathsTraverser.Step(this.direction, labelIds,
                                            this.properties, weightBy,
                                            this.defaultWeight,
                                            this.degree, this.sample);
}
 
Example 9
Source File: Condition.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private void checkBaseType(Object value, Class<?> clazz) {
    if (!clazz.isInstance(value)) {
        String valueClass = value == null ? "null" :
                            value.getClass().getSimpleName();
        E.checkArgument(false,
                        "Can't execute `%s` on type %s, expect %s",
                        this.operator, valueClass,
                        clazz.getSimpleName());
    }
}
 
Example 10
Source File: PaloFile.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private static int[] parseFileName(String fileName) {
    String[] nameParts = fileName.split("-");
    E.checkArgument(nameParts.length == 2,
                    "Invalid file name format '%s' for palo temp file, " +
                    "the legal format is session{m}-part{n}", fileName);
    int[] rs = new int[2];
    rs[0] = Integer.parseInt(nameParts[0].substring("session".length()));
    rs[1] = Integer.parseInt(nameParts[1].substring("part".length()));
    return rs;
}
 
Example 11
Source File: HugeGraphAuthProxy.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public HugeUser deleteUser(Id id) {
    HugeUser user = this.userManager.getUser(id);
    E.checkArgument(!HugeAuthenticator.USER_ADMIN.equals(user.name()),
                    "Can't delete user '%s'", user.name());
    verifyUserPermission(HugePermission.DELETE, user);
    return this.userManager.deleteUser(id);
}
 
Example 12
Source File: EdgeStructV1.java    From hugegraph-loader with Apache License 2.0 5 votes vote down vote up
@Override
public void check() throws IllegalArgumentException {
    super.check();
    E.checkArgument(this.sourceFields != null &&
                    !this.sourceFields.isEmpty(),
                    "The source field of edge label '%s' " +
                    "can't be null or empty", this.label());
    E.checkArgument(this.targetFields != null &&
                    !this.targetFields.isEmpty(),
                    "The target field of edge label '%s' " +
                    "can't be null or empty", this.label());
}
 
Example 13
Source File: EdgeLabelBuilder.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private void checkSortKeys() {
    if (this.frequency == Frequency.SINGLE ||
        this.frequency == Frequency.DEFAULT) {
        E.checkArgument(this.sortKeys.isEmpty(),
                        "EdgeLabel can't contain sortKeys " +
                        "when the cardinality property is single");
    } else {
        E.checkState(this.sortKeys != null,
                     "The sortKeys can't be null when the " +
                     "cardinality property is multiple");
        E.checkArgument(!this.sortKeys.isEmpty(),
                        "EdgeLabel must contain sortKeys " +
                        "when the cardinality property is multiple");
    }

    if (this.sortKeys.isEmpty()) {
        return;
    }

    // Check whether the properties contains the specified keys
    E.checkArgument(!this.properties.isEmpty(),
                    "The properties can't be empty when exist " +
                    "sort keys for edge label '%s'", this.name);

    for (String key : this.sortKeys) {
        E.checkArgument(this.properties.contains(key),
                        "The sort key '%s' must be contained in " +
                        "properties '%s' for edge label '%s'",
                        key, this.name, this.properties);
    }
}
 
Example 14
Source File: VerticesAPI.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
public List<Vertex> list(List<Object> ids) {
    E.checkArgument(ids != null && !ids.isEmpty(),
                    "Ids can't be null or empty");

    List<String> stringIds = new ArrayList<>(ids.size());
    for (Object id : ids) {
        stringIds.add(GraphAPI.formatVertexId(id, false));
    }

    Map<String, Object> params = new LinkedHashMap<>();
    params.put("ids", stringIds);
    RestResult result = this.client.get(this.path(), params);
    return result.readList(this.type(), Vertex.class);
}
 
Example 15
Source File: IndexLabelBuilder.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private void checkFields4Range() {
    if (this.indexType != IndexType.RANGE) {
        return;
    }
    List<String> fields = this.indexFields;
    E.checkArgument(fields.size() == 1,
                    "Range index can only build on " +
                    "one field, but got %s fields: '%s'",
                    fields.size(), fields);
    String field = fields.iterator().next();
    DataType dataType = this.graph().propertyKey(field).dataType();
    E.checkArgument(dataType.isNumber() || dataType.isDate(),
                    "Range index can only build on numeric or " +
                    "date property, but got %s(%s)", dataType, field);
    switch (dataType) {
        case BYTE:
        case INT:
            this.indexType = IndexType.RANGE_INT;
            break;
        case FLOAT:
            this.indexType = IndexType.RANGE_FLOAT;
            break;
        case LONG:
        case DATE:
            this.indexType = IndexType.RANGE_LONG;
            break;
        case DOUBLE:
            this.indexType = IndexType.RANGE_DOUBLE;
            break;
        default:
            throw new AssertionError("Invalid datatype: " + dataType);
    }
}
 
Example 16
Source File: RolePermission.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public static RolePermission fromJson(Object json) {
    RolePermission role;
    if (json instanceof String) {
        role = JsonUtil.fromJson((String) json, RolePermission.class);
    } else {
        // Optimized json with RolePermission object
        E.checkArgument(json instanceof RolePermission,
                        "Invalid role value: %s", json);
        role = (RolePermission) json;
    }
    return role;
}
 
Example 17
Source File: EdgeLabel.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
public void targetLabel(Id id) {
    E.checkArgument(this.targetLabel == NONE_ID,
                    "Not allowed to set target label multi times " +
                    "of edge label '%s'", this.name());
    this.targetLabel = id;
}
 
Example 18
Source File: EdgeLabelAPI.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
private EdgeLabel.Builder convert2Builder(HugeGraph g) {
    EdgeLabel.Builder builder = g.schema().edgeLabel(this.name);
    if (this.id != 0) {
        E.checkArgument(this.id > 0,
                        "Only positive number can be assign as " +
                        "edge label id");
        E.checkArgument(g.mode() == GraphMode.RESTORING,
                        "Only accept edge label id when graph in " +
                        "RESTORING mode, but '%s' is in mode '%s'",
                        g, g.mode());
        builder.id(this.id);
    }
    if (this.sourceLabel != null) {
        builder.sourceLabel(this.sourceLabel);
    }
    if (this.targetLabel != null) {
        builder.targetLabel(this.targetLabel);
    }
    if (this.frequency != null) {
        builder.frequency(this.frequency);
    }
    if (this.properties != null) {
        builder.properties(this.properties);
    }
    if (this.sortKeys != null) {
        builder.sortKeys(this.sortKeys);
    }
    if (this.nullableKeys != null) {
        builder.nullableKeys(this.nullableKeys);
    }
    if (this.enableLabelIndex != null) {
        builder.enableLabelIndex(this.enableLabelIndex);
    }
    if (this.userdata != null) {
        builder.userdata(this.userdata);
    }
    if (this.checkExist != null) {
        builder.checkExist(this.checkExist);
    }
    if (this.ttl != 0) {
        builder.ttl(this.ttl);
    }
    if (this.ttlStartTime != null) {
        E.checkArgument(this.ttl > 0,
                        "Only set ttlStartTime when ttl is " +
                        "positive,  but got ttl: %s", this.ttl);
        builder.ttlStartTime(this.ttlStartTime);
    }
    return builder;
}
 
Example 19
Source File: StandardHugeGraph.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
public EdgeLabel edgeLabel(String name) {
    EdgeLabel el = this.schemaTransaction().getEdgeLabel(name);
    E.checkArgument(el != null, "Undefined edge label: '%s'", name);
    return el;
}
 
Example 20
Source File: TraversersAPI.java    From hugegraph-client with Apache License 2.0 4 votes vote down vote up
public static void checkAlpha(double alpha) {
    E.checkArgument(alpha > 0 && alpha <= 1.0,
                    "The alpha of rank request must be in range (0, 1], " +
                    "but got '%s'", alpha);
}