當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。