当前位置: 首页>>代码示例>>Java>>正文


Java Tuple.v2方法代码示例

本文整理汇总了Java中org.elasticsearch.common.collect.Tuple.v2方法的典型用法代码示例。如果您正苦于以下问题:Java Tuple.v2方法的具体用法?Java Tuple.v2怎么用?Java Tuple.v2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.collect.Tuple的用法示例。


在下文中一共展示了Tuple.v2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testToAndFromXContent

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testToAndFromXContent() throws Exception {
    XContentType xContentType = randomFrom(XContentType.values());
    Tuple<GetResult, GetResult> tuple = randomGetResult(xContentType);
    GetResponse getResponse = new GetResponse(tuple.v1());
    GetResponse expectedGetResponse = new GetResponse(tuple.v2());
    boolean humanReadable = randomBoolean();
    BytesReference originalBytes = toXContent(getResponse, xContentType, humanReadable);
    //test that we can parse what we print out
    GetResponse parsedGetResponse;
    try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
        parsedGetResponse = GetResponse.fromXContent(parser);
        assertNull(parser.nextToken());
    }
    assertEquals(expectedGetResponse, parsedGetResponse);
    //print the parsed object out and test that the output is the same as the original output
    BytesReference finalBytes = toXContent(parsedGetResponse, xContentType, humanReadable);
    assertToXContentEquivalent(originalBytes, finalBytes, xContentType);
    //check that the source stays unchanged, no shuffling of keys nor anything like that
    assertEquals(expectedGetResponse.getSourceAsString(), parsedGetResponse.getSourceAsString());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:GetResponseTests.java

示例2: randomShardInfo

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/**
 * Returns a tuple that contains a randomized {@link ShardInfo} value (left side) and its corresponding
 * value (right side) after it has been printed out as a {@link ToXContent} and parsed back using a parsing
 * method like {@link ShardInfo#fromXContent(XContentParser)}. A `withShardFailures` parameter indicates if
 * the randomized ShardInfo must or must not contain shard failures.
 *
 * @param random            Random generator
 * @param withShardFailures indicates if the generated ShardInfo must contain shard failures
 */
public static Tuple<ShardInfo, ShardInfo> randomShardInfo(Random random, boolean withShardFailures) {
    int total = randomIntBetween(random, 1, 10);
    if (withShardFailures == false) {
        return Tuple.tuple(new ShardInfo(total, total), new ShardInfo(total, total));
    }

    int successful = randomIntBetween(random, 1, Math.max(1, (total - 1)));
    int failures = Math.max(1, (total - successful));

    Failure[] actualFailures = new Failure[failures];
    Failure[] expectedFailures = new Failure[failures];

    for (int i = 0; i < failures; i++) {
        Tuple<Failure, Failure> failure = randomShardInfoFailure(random);
        actualFailures[i] = failure.v1();
        expectedFailures[i] = failure.v2();
    }
    return Tuple.tuple(new ShardInfo(total, successful, actualFailures), new ShardInfo(total, successful, expectedFailures));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:RandomObjects.java

示例3: AzureStorageServiceImpl

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public AzureStorageServiceImpl(Settings settings) {
    super(settings);

    Tuple<AzureStorageSettings, Map<String, AzureStorageSettings>> storageSettings = AzureStorageSettings.parse(settings);
    this.primaryStorageSettings = storageSettings.v1();
    this.secondariesStorageSettings = storageSettings.v2();

    this.clients = new HashMap<>();

    logger.debug("starting azure storage client instance");

    // We register the primary client if any
    if (primaryStorageSettings != null) {
        logger.debug("registering primary client for account [{}]", primaryStorageSettings.getAccount());
        createClient(primaryStorageSettings);
    }

    // We register all secondary clients
    for (Map.Entry<String, AzureStorageSettings> azureStorageSettingsEntry : secondariesStorageSettings.entrySet()) {
        logger.debug("registering secondary client for account [{}]", azureStorageSettingsEntry.getKey());
        createClient(azureStorageSettingsEntry.getValue());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:AzureStorageServiceImpl.java

示例4: parseCopy

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/** Creates an copy of the current field with given field name and boost */
private static void parseCopy(String field, ParseContext context) throws IOException {
    FieldMapper fieldMapper = context.docMapper().mappers().getMapper(field);
    if (fieldMapper != null) {
        fieldMapper.parse(context);
    } else {
        // The path of the dest field might be completely different from the current one so we need to reset it
        context = context.overridePath(new ContentPath(0));

        final String[] paths = splitAndValidatePath(field);
        final String fieldName = paths[paths.length-1];
        Tuple<Integer, ObjectMapper> parentMapperTuple = getDynamicParentMapper(context, paths, null);
        ObjectMapper mapper = parentMapperTuple.v2();
        parseDynamicValue(context, mapper, fieldName, context.parser().currentToken());
        for (int i = 0; i < parentMapperTuple.v1(); i++) {
            context.path().remove();
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:DocumentParser.java

示例5: testToAndFromXContent

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testToAndFromXContent() throws IOException {
    final XContentType xContentType = randomFrom(XContentType.values());

    for (DocWriteRequest.OpType opType : DocWriteRequest.OpType.values()) {
        int bulkItemId = randomIntBetween(0, 100);
        boolean humanReadable = randomBoolean();

        Tuple<? extends DocWriteResponse, ? extends DocWriteResponse> randomDocWriteResponses = null;
        if (opType == DocWriteRequest.OpType.INDEX || opType == DocWriteRequest.OpType.CREATE) {
            randomDocWriteResponses = IndexResponseTests.randomIndexResponse();
        } else if (opType == DocWriteRequest.OpType.DELETE) {
            randomDocWriteResponses = DeleteResponseTests.randomDeleteResponse();
        } else if (opType == DocWriteRequest.OpType.UPDATE) {
            randomDocWriteResponses = UpdateResponseTests.randomUpdateResponse(xContentType);
        } else {
            fail("Test does not support opType [" + opType + "]");
        }

        BulkItemResponse bulkItemResponse = new BulkItemResponse(bulkItemId, opType, randomDocWriteResponses.v1());
        BulkItemResponse expectedBulkItemResponse = new BulkItemResponse(bulkItemId, opType, randomDocWriteResponses.v2());
        BytesReference originalBytes = toXContent(bulkItemResponse, xContentType, humanReadable);

        // Shuffle the XContent fields
        if (randomBoolean()) {
            try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
                originalBytes = shuffleXContent(parser, randomBoolean()).bytes();
            }
        }

        BulkItemResponse parsedBulkItemResponse;
        try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
            assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
            parsedBulkItemResponse = BulkItemResponse.fromXContent(parser, bulkItemId);
            assertNull(parser.nextToken());
        }
        assertBulkItemResponse(expectedBulkItemResponse, parsedBulkItemResponse);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:BulkItemResponseTests.java

示例6: parse

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public static GreaterThanAssertion parse(XContentParser parser) throws IOException {
    XContentLocation location = parser.getTokenLocation();
    Tuple<String,Object> stringObjectTuple = ParserUtils.parseTuple(parser);
    if (! (stringObjectTuple.v2() instanceof Comparable) ) {
        throw new IllegalArgumentException("gt section can only be used with objects that support natural ordering, found "
                + stringObjectTuple.v2().getClass().getSimpleName());
    }
    return new GreaterThanAssertion(location, stringObjectTuple.v1(), stringObjectTuple.v2());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:GreaterThanAssertion.java

示例7: parse

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public static LessThanOrEqualToAssertion parse(XContentParser parser) throws IOException {
    XContentLocation location = parser.getTokenLocation();
    Tuple<String,Object> stringObjectTuple = ParserUtils.parseTuple(parser);
    if (false == stringObjectTuple.v2() instanceof Comparable) {
        throw new IllegalArgumentException("lte section can only be used with objects that support natural ordering, found "
                + stringObjectTuple.v2().getClass().getSimpleName());
    }
    return new LessThanOrEqualToAssertion(location, stringObjectTuple.v1(), stringObjectTuple.v2());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:LessThanOrEqualToAssertion.java

示例8: apply

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
@Override
public Query apply(Function input, Context context) {
    Tuple<Reference, Literal> tuple = super.prepare(input);
    if (tuple == null) {
        return null;
    }
    Reference reference = tuple.v1();
    Literal literal = tuple.v2();
    String columnName = reference.info().ident().columnIdent().fqn();
    if (DataTypes.isCollectionType(reference.valueType()) && DataTypes.isCollectionType(literal.valueType())) {
        List<Term> terms = getTerms(columnName, literal);
        if (terms.isEmpty()) {
            return genericFunctionFilter(input, context);
        }
        Query termsQuery = new TermsQuery(terms);

        // wrap boolTermsFilter and genericFunction filter in an additional BooleanFilter to control the ordering of the filters
        // termsFilter is applied first
        // afterwards the more expensive genericFunctionFilter
        BooleanQuery.Builder filterClauses = new BooleanQuery.Builder();
        filterClauses.add(termsQuery, BooleanClause.Occur.MUST);
        filterClauses.add(genericFunctionFilter(input, context), BooleanClause.Occur.MUST);
        return filterClauses.build();
    }
    QueryBuilderHelper builder = QueryBuilderHelper.forType(tuple.v1().valueType());
    return builder.eq(columnName, tuple.v2().value());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:28,代码来源:LuceneQueryBuilder.java

示例9: parse

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public DocumentMapper parse(@Nullable String type, CompressedXContent source, String defaultSource) throws MapperParsingException {
    Map<String, Object> mapping = null;
    if (source != null) {
        Map<String, Object> root = XContentHelper.convertToMap(source.compressedReference(), true, XContentType.JSON).v2();
        Tuple<String, Map<String, Object>> t = extractMapping(type, root);
        type = t.v1();
        mapping = t.v2();
    }
    if (mapping == null) {
        mapping = new HashMap<>();
    }
    return parse(type, mapping, defaultSource);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:DocumentMapperParser.java

示例10: testToAndFromXContent

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testToAndFromXContent() throws IOException {
    final Tuple<DeleteResponse, DeleteResponse> tuple = randomDeleteResponse();
    DeleteResponse deleteResponse = tuple.v1();
    DeleteResponse expectedDeleteResponse = tuple.v2();

    boolean humanReadable = randomBoolean();
    final XContentType xContentType = randomFrom(XContentType.values());
    BytesReference deleteResponseBytes = toXContent(deleteResponse, xContentType, humanReadable);

    // Shuffle the XContent fields
    if (randomBoolean()) {
        try (XContentParser parser = createParser(xContentType.xContent(), deleteResponseBytes)) {
            deleteResponseBytes = shuffleXContent(parser, randomBoolean()).bytes();
        }
    }

    // Parse the XContent bytes to obtain a parsed DeleteResponse
    DeleteResponse parsedDeleteResponse;
    try (XContentParser parser = createParser(xContentType.xContent(), deleteResponseBytes)) {
        parsedDeleteResponse = DeleteResponse.fromXContent(parser);
        assertNull(parser.nextToken());
    }

    // We can't use equals() to compare the original and the parsed delete response
    // because the random delete response can contain shard failures with exceptions,
    // and those exceptions are not parsed back with the same types.
    assertDocWriteResponse(expectedDeleteResponse, parsedDeleteResponse);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:DeleteResponseTests.java

示例11: withContentOrSourceParamParserOrNull

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/**
 * Call a consumer with the parser for the contents of this request if it has contents, otherwise with a parser for the {@code source}
 * parameter if there is one, otherwise with {@code null}. Use {@link #contentOrSourceParamParser()} if you should throw an exception
 * back to the user when there isn't request content.
 */
public final void withContentOrSourceParamParserOrNull(CheckedConsumer<XContentParser, IOException> withParser) throws IOException {
    Tuple<XContentType, BytesReference> tuple = contentOrSourceParam();
    BytesReference content = tuple.v2();
    XContentType xContentType = tuple.v1();
    if (content.length() > 0) {
        try (XContentParser parser = xContentType.xContent().createParser(xContentRegistry, content)) {
            withParser.accept(parser);
        }
    } else {
        withParser.accept(null);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RestRequest.java

示例12: prepareRequest

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
    Tuple<XContentType, BytesReference> sourceTuple = restRequest.contentOrSourceParam();
    PutPipelineRequest request = new PutPipelineRequest(restRequest.param("id"), sourceTuple.v2(), sourceTuple.v1());
    request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
    request.timeout(restRequest.paramAsTime("timeout", request.timeout()));
    return channel -> client.admin().cluster().putPipeline(request, new AcknowledgedRestListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:RestPutPipelineAction.java

示例13: testToAndFromXContent

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testToAndFromXContent() throws IOException {
    final Tuple<IndexResponse, IndexResponse> tuple = randomIndexResponse();
    IndexResponse indexResponse = tuple.v1();
    IndexResponse expectedIndexResponse = tuple.v2();

    boolean humanReadable = randomBoolean();
    XContentType xContentType = randomFrom(XContentType.values());
    BytesReference indexResponseBytes = toXContent(indexResponse, xContentType, humanReadable);

    // Shuffle the XContent fields
    if (randomBoolean()) {
        try (XContentParser parser = createParser(xContentType.xContent(), indexResponseBytes)) {
            indexResponseBytes = shuffleXContent(parser, randomBoolean()).bytes();
        }
    }

    // Parse the XContent bytes to obtain a parsed
    IndexResponse parsedIndexResponse;
    try (XContentParser parser = createParser(xContentType.xContent(), indexResponseBytes)) {
        parsedIndexResponse = IndexResponse.fromXContent(parser);
        assertNull(parser.nextToken());
    }

    // We can't use equals() to compare the original and the parsed index response
    // because the random index response can contain shard failures with exceptions,
    // and those exceptions are not parsed back with the same types.
    assertDocWriteResponse(expectedIndexResponse, parsedIndexResponse);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:IndexResponseTests.java

示例14: testShardInfoToAndFromXContent

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
public void testShardInfoToAndFromXContent() throws IOException {
    final Tuple<ShardInfo, ShardInfo> tuple = RandomObjects.randomShardInfo(random());
    ShardInfo shardInfo = tuple.v1();
    ShardInfo expectedShardInfo = tuple.v2();

    final XContentType xContentType = randomFrom(XContentType.values());
    boolean humanReadable = randomBoolean();
    BytesReference originalBytes = toXContent(shardInfo, xContentType, humanReadable);

    // Shuffle the XContent fields
    if (randomBoolean()) {
        try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
            originalBytes = shuffleXContent(parser, randomBoolean()).bytes();
        }
    }

    ShardInfo parsedShardInfo;
    try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
        // Move to the first start object
        assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
        parsedShardInfo = ShardInfo.fromXContent(parser);
        assertNull(parser.nextToken());
    }
    assertShardInfo(expectedShardInfo, parsedShardInfo);

    BytesReference expectedFinalBytes = toXContent(expectedShardInfo, xContentType, humanReadable);
    BytesReference finalBytes = toXContent(parsedShardInfo, xContentType, humanReadable);
    assertToXContentEquivalent(expectedFinalBytes, finalBytes, xContentType);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:ReplicationResponseTests.java

示例15: shouldAutoCreate

import org.elasticsearch.common.collect.Tuple; //导入方法依赖的package包/类
/**
 * Should the index be auto created?
 * @throws IndexNotFoundException if the the index doesn't exist and shouldn't be auto created
 */
public boolean shouldAutoCreate(String index, ClusterState state) {
    if (resolver.hasIndexOrAlias(index, state)) {
        return false;
    }
    // One volatile read, so that all checks are done against the same instance:
    final AutoCreate autoCreate = this.autoCreate;
    if (autoCreate.autoCreateIndex == false) {
        throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] is [false]", index);
    }
    if (dynamicMappingDisabled) {
        throw new IndexNotFoundException("no such index and [" + MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey() + "] is [false]",
                index);
    }
    // matches not set, default value of "true"
    if (autoCreate.expressions.isEmpty()) {
        return true;
    }
    for (Tuple<String, Boolean> expression : autoCreate.expressions) {
        String indexExpression = expression.v1();
        boolean include = expression.v2();
        if (Regex.simpleMatch(indexExpression, index)) {
            if (include) {
                return true;
            }
            throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] contains [-"
                    + indexExpression + "] which forbids automatic creation of the index", index);
        }
    }
    throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] ([" + autoCreate
            + "]) doesn't match", index);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:AutoCreateIndex.java


注:本文中的org.elasticsearch.common.collect.Tuple.v2方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。