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


Java Element.getType方法代码示例

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


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

示例1: determineIndexServerVersion

import com.allanbank.mongodb.bson.Element; //导入方法依赖的package包/类
/**
 * Determines the minimum server version required to support the provided
 * index keys and options.
 *
 * @param keys
 *            The index keys.
 * @return The version required for the index. May be null.
 */
protected Version determineIndexServerVersion(final Element[] keys) {
    Version result = null;

    for (final Element key : keys) {
        if (key.getType() == ElementType.STRING) {
            final String type = key.getValueAsString();
            if (Index.GEO_2DSPHERE_INDEX_NAME.equals(type)) {
                result = Version.later(result, Version.VERSION_2_4);
            }
            else if (Index.HASHED_INDEX_NAME.equals(type)) {
                result = Version.later(result, Version.VERSION_2_4);
            }
            else if (Index.TEXT_INDEX_NAME.equals(type)) {
                result = Version.later(result, Version.VERSION_2_4);
            }
        }
    }

    return result;
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:29,代码来源:SynchronousMongoCollectionImpl.java

示例2: compareTo

import com.allanbank.mongodb.bson.Element; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Overridden to compare the string values if the base class comparison is
 * equals.
 * </p>
 * <p>
 * Note that for MongoDB {@link SymbolElement} and {@link StringElement}
 * will return equal based on the type. Care is taken here to make sure that
 * the values return the same value regardless of comparison order.
 * </p>
 * <p>
 * Note: Comparison of strings in MongoDB does not use a collator. This
 * class emulates the MongoDB behavior and orders the string elements based
 * on the UTF-8 encoding of the strings.
 * </p>
 */
@Override
public int compareTo(final Element otherElement) {
    int result = super.compareTo(otherElement);

    if (result == 0) {
        // Might be a StringElement or SymbolElement.
        final ElementType otherType = otherElement.getType();

        if (otherType == ElementType.SYMBOL) {
            result = utf8Compare(myValue,
                    ((SymbolElement) otherElement).getSymbol());
        }
        else {
            result = utf8Compare(myValue,
                    ((StringElement) otherElement).getValue());
        }
    }

    return result;
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:38,代码来源:StringElement.java

示例3: compareTo

import com.allanbank.mongodb.bson.Element; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Overridden to compare the string values if the base class comparison is
 * equals.
 * </p>
 * <p>
 * Note that for MongoDB {@link SymbolElement} and {@link StringElement}
 * will return equal based on the type. Care is taken here to make sure that
 * the values return the same value regardless of comparison order.
 * </p>
 * <p>
 * Note: Comparison of strings in MongoDB does not use a collator. This
 * class emulates the MongoDB behavior and orders the string elements based
 * on the UTF-8 encoding of the strings.
 * </p>
 */
@Override
public int compareTo(final Element otherElement) {
    int result = super.compareTo(otherElement);

    if (result == 0) {
        // Might be a StringElement or SymbolElement.
        final ElementType otherType = otherElement.getType();

        if (otherType == ElementType.SYMBOL) {
            result = StringElement.utf8Compare(mySymbol,
                    ((SymbolElement) otherElement).getSymbol());
        }
        else {
            result = StringElement.utf8Compare(mySymbol,
                    ((StringElement) otherElement).getValue());
        }
    }

    return result;
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:38,代码来源:SymbolElement.java

示例4: compareTo

import com.allanbank.mongodb.bson.Element; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Overridden to compare the times if the base class comparison is equals.
 * </p>
 * <p>
 * Note that for MongoDB {@link MongoTimestampElement} and
 * {@link TimestampElement} will return equal based on the type. Care is
 * taken here to make sure that the values return the same value regardless
 * of comparison order.
 * </p>
 */
@Override
public int compareTo(final Element otherElement) {
    int result = super.compareTo(otherElement);

    if (result == 0) {
        // Might be a MongoTimestampElement or TimestampElement.
        final ElementType otherType = otherElement.getType();

        if (otherType == ElementType.MONGO_TIMESTAMP) {
            result = compare(getTime(),
                    ((MongoTimestampElement) otherElement).getTime());
        }
        else {
            result = compare(getTime(),
                    ((TimestampElement) otherElement).getTime());
        }
    }

    return result;
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:33,代码来源:MongoTimestampElement.java

示例5: compareTo

import com.allanbank.mongodb.bson.Element; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Overridden to compare the times if the base class comparison is equals.
 * </p>
 * <p>
 * Note that for MongoDB {@link MongoTimestampElement} and
 * {@link TimestampElement} will return equal based on the type. Care is
 * taken here to make sure that the values return the same value regardless
 * of comparison order.
 * </p>
 */
@Override
public int compareTo(final Element otherElement) {
    int result = super.compareTo(otherElement);

    if (result == 0) {
        // Might be a MongoTimestampElement or TimestampElement.
        final ElementType otherType = otherElement.getType();

        if (otherType == ElementType.UTC_TIMESTAMP) {
            result = compare(getTime(),
                    ((TimestampElement) otherElement).getTime());
        }
        else {
            result = compare(getTime(),
                    ((MongoTimestampElement) otherElement).getTime());
        }
    }

    return result;
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:33,代码来源:TimestampElement.java

示例6: visit

import com.allanbank.mongodb.bson.Element; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void visit(final List<Element> elements) {
    mySize += 4;
    for (final Element element : elements) {
        // Optimization to avoid the array copy.
        if (element.getType() == ElementType.BINARY) {
            final BinaryElement be = (BinaryElement) element;
            doVisitBinary(be.getName(), be.getSubType(), be.length());
        }
        else {
            element.accept(this);
        }
    }
    mySize += 1;
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:19,代码来源:SizeOfVisitor.java

示例7: toCommand

import com.allanbank.mongodb.bson.Element; //导入方法依赖的package包/类
/**
 * Converts the {@link Aggregate} object to an {@link AggregateCommand}.
 *
 * @param command
 *            The {@link Aggregate} to convert.
 * @param explain
 *            If rue then have the server explain the aggregation instead of
 *            performing the aggregation.
 * @return The command to send to the server for the {@link Aggregate}.
 */
protected AggregateCommand toCommand(final Aggregate command,
        final boolean explain) {
    Version minVersion = command.getRequiredVersion();
    Version maxVersion = Version.UNKNOWN;

    final DocumentBuilder builder = BuilderFactory.start();

    builder.addString("aggregate", getName());

    // Pipeline of operations.
    final QueryVersionVisitor visitor = new QueryVersionVisitor();
    final ArrayBuilder pipeline = builder.pushArray("pipeline");
    for (final Element e : command.getPipeline()) {
        if (e.getType() == ElementType.DOCUMENT) {
            visitor.visit(((DocumentElement) e).getElements());
        }
        pipeline.add(e);
    }
    minVersion = Version.later(minVersion,
            visitor.getRequiredServerVersion());
    maxVersion = Version.earlier(maxVersion,
            visitor.getMaximumServerVersion());

    // Options
    if (command.isAllowDiskUsage()) {
        builder.add("allowDiskUse", true);
    }
    if (command.isUseCursor()) {
        final DocumentBuilder cursor = builder.push("cursor");
        if (command.getBatchSize() > 0) {
            cursor.add("batchSize", command.getBatchSize());
        }
    }
    if (explain) {
        minVersion = Version.later(minVersion, Aggregate.EXPLAIN_VERSION);
        builder.add("explain", true);
    }
    if (command.getMaximumTimeMilliseconds() > 0) {
        builder.add("maxTimeMS", command.getMaximumTimeMilliseconds());
    }

    // Should be last since might wrap command in a $query element.
    final ReadPreference readPreference = updateReadPreference(builder,
            command.getReadPreference(), true);

    final AggregateCommand commandMsg = new AggregateCommand(command,
            getDatabaseName(), getName(), builder.build(), readPreference,
            VersionRange.range(minVersion, maxVersion));
    return commandMsg;
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:61,代码来源:AbstractMongoOperations.java


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