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


Java Element类代码示例

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


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

示例1: testCompareTo

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Test method for {@link MongoTimestampElement#compareTo(Element)}.
 */
@Test
public void testCompareTo() {
    final MongoTimestampElement a1 = new MongoTimestampElement("a", 1);
    final MongoTimestampElement a11 = new MongoTimestampElement("a", 11);
    final MongoTimestampElement b1 = new MongoTimestampElement("b", 1);

    final TimestampElement i = new TimestampElement("a", 2);

    final Element other = new MaxKeyElement("a");

    assertEquals(0, a1.compareTo(a1));

    assertTrue(a1.compareTo(a11) < 0);
    assertTrue(a11.compareTo(a1) > 0);

    assertTrue(a1.compareTo(b1) < 0);
    assertTrue(b1.compareTo(a1) > 0);

    assertTrue(a1.compareTo(i) < 0);
    assertTrue(i.compareTo(a1) > 0);

    assertTrue(a1.compareTo(other) < 0);
    assertTrue(other.compareTo(a1) > 0);
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:28,代码来源:MongoTimestampElementTest.java

示例2: failedDurability

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Checks for a failure in the durability requirements (e.g., did not
 * replicate to sufficient servers within the timeout) and updates the
 * failed operations map if any are found.
 *
 * @param bundle
 *            The bundle for the reply.
 * @param reply
 *            The reply from the server.
 * @return True if there are failed writes and we should not send any
 *         additional requests.
 */
private boolean failedDurability(final Bundle bundle, final Reply reply) {
    final List<Document> results = reply.getResults();
    if (results.size() == 1) {
        final Document doc = results.get(0);
        final DocumentElement error = doc.get(DocumentElement.class,
                "writeConcernError");
        if (error != null) {
            final int code = toInt(error.get(NumericElement.class, "code"));
            final String errmsg = asString(error.get(Element.class,
                    "errmsg"));
            final MongoDbException exception = asError(reply, 0, code,
                    true, errmsg, null);
            for (final WriteOperation op : bundle.getWrites()) {
                myFailedOperations.put(op, exception);
            }
        }
    }

    return (myWrite.getMode() == BatchedWriteMode.SERIALIZE_AND_STOP)
            && !myFailedOperations.isEmpty();
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:34,代码来源:BatchedWriteCallback.java

示例3: testNearDocumentAssignableDouble

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Test method for {@link ConditionBuilder#near(DocumentAssignable,double)}.
 */
@Test
public void testNearDocumentAssignableDouble() {

    final ConditionBuilder b = QueryBuilder.where("foo");

    final double v1 = myRandom.nextDouble();
    final double v2 = myRandom.nextDouble();

    b.equals(false); // Make sure equals is removed.
    b.near(GeoJson.point(GeoJson.p(v1, v2)), 42.1);

    final Element e = b.buildFieldCondition();

    assertThat(e, instanceOf(DocumentElement.class));

    final DocumentBuilder db = BuilderFactory.start();
    db.push(GeospatialOperator.NEAR.getToken())
            .add(GeospatialOperator.GEOMETRY,
                    GeoJson.point(GeoJson.p(v1, v2)))
            .add(GeospatialOperator.MAX_DISTANCE_MODIFIER.getToken(), 42.1);

    assertEquals(new DocumentElement("foo", db.build()), e);
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:27,代码来源:ConditionBuilderTest.java

示例4: convert

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Overridden to return the reply document.
 * </p>
 *
 * @see AbstractReplyCallback#convert(Reply)
 */
@Override
protected MongoIterator<Element> convert(final Reply reply)
        throws MongoDbException {
    final List<Document> results = reply.getResults();
    if (results.size() == 1) {
        List<Element> entries = Collections.emptyList();
        final Document document = results.get(0);
        final ArrayElement array = document.findFirst(ArrayElement.class,
                myName);
        if (array != null) {
            entries = array.getEntries();
        }

        return new SimpleMongoIteratorImpl<Element>(entries);
    }

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

示例5: testEqualsDocument

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Test method for {@link ConditionBuilder#equals(DocumentAssignable)}.
 */
@Test
public void testEqualsDocument() {

    final ConditionBuilder b = QueryBuilder.where("foo");

    final Document value = BuilderFactory
            .start()
            .addInteger(String.valueOf(myRandom.nextInt()),
                    myRandom.nextInt()).build();

    b.greaterThan(23); // Make sure non-equals is removed.
    b.equals(value);

    final Element e = b.buildFieldCondition();

    assertThat(e, instanceOf(DocumentElement.class));
    assertEquals(e, new DocumentElement("foo", value));
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:22,代码来源:ConditionBuilderTest.java

示例6: testNearIntIntInt

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Test method for {@link ConditionBuilder#near(int, int, int)}.
 */
@Test
public void testNearIntIntInt() {

    final ConditionBuilder b = QueryBuilder.where("foo");

    final int v1 = myRandom.nextInt();
    final int v2 = myRandom.nextInt();
    final int v3 = myRandom.nextInt();

    b.equals(false); // Make sure equals is removed.
    b.near(v1, v2, v3);

    final Element e = b.buildFieldCondition();

    assertThat(e, instanceOf(DocumentElement.class));

    final DocumentBuilder db = BuilderFactory.start();
    db.pushArray(GeospatialOperator.NEAR.getToken()).addInteger(v1)
            .addInteger(v2);
    db.addInteger(GeospatialOperator.MAX_DISTANCE_MODIFIER.getToken(), v3);

    assertEquals(new DocumentElement("foo", db.build()), e);
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:27,代码来源:ConditionBuilderTest.java

示例7: testNearSphereIntIntInt

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Test method for {@link ConditionBuilder#nearSphere(int, int, int)}.
 */
@Test
public void testNearSphereIntIntInt() {

    final ConditionBuilder b = QueryBuilder.where("foo");

    final int v1 = myRandom.nextInt();
    final int v2 = myRandom.nextInt();
    final int v3 = myRandom.nextInt();

    b.equals(false); // Make sure equals is removed.
    b.nearSphere(v1, v2, v3);

    final Element e = b.buildFieldCondition();

    assertThat(e, instanceOf(DocumentElement.class));

    final DocumentBuilder db = BuilderFactory.start();
    db.pushArray(GeospatialOperator.NEAR_SPHERE.getToken()).addInteger(v1)
            .addInteger(v2);
    db.addInteger(GeospatialOperator.MAX_DISTANCE_MODIFIER.getToken(), v3);

    assertEquals(new DocumentElement("foo", db.build()), e);
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:27,代码来源:ConditionBuilderTest.java

示例8: doVerifyFileMd5

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Verifies the MD5 result for the filemd5 command.
 *
 * @param faults
 *            The faults for to update if the verify fails.
 * @param fileDoc
 *            The document representing the file.
 * @param cmdResult
 *            The document returned from the 'filemd5' command.
 * @return True if the file was successful.
 */
protected boolean doVerifyFileMd5(final Map<Object, List<String>> faults,
        final Document fileDoc, final Document cmdResult) {
    boolean ok = false;
    final Element idElement = fileDoc.get(ID_FIELD);

    final Element md5 = fileDoc.get(MD5_FIELD);
    final Element commandMd5 = cmdResult.findFirst(MD5_FIELD);

    ok = (md5 != null) && md5.equals(commandMd5);
    if (!ok) {
        doAddFault(faults, idElement,
                "MD5 sums do not match. File document contains '" + md5
                        + "' and the filemd5 command produced '"
                        + commandMd5 + "'.");
    }

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

示例9: testEqualsLegacyUUID

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Test method for {@link ConditionBuilder#equalsLegacy(UUID)}.
 */
@Test
public void testEqualsLegacyUUID() {

    final ConditionBuilder b = QueryBuilder.where("foo");

    final UUID value = UUID.randomUUID();

    b.greaterThan(23); // Make sure non-equals is removed.
    b.equalsLegacy(value);

    final Element e = b.buildFieldCondition();

    assertThat(e, instanceOf(UuidElement.class));
    assertEquals(e, new UuidElement("foo",
            UuidElement.LEGACY_UUID_SUBTTYPE, value));
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:20,代码来源:ConditionBuilderTest.java

示例10: readDBPointerElement

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Reads a {@code DBPointerElement} from the stream.
 *
 * @return The {@code DBPointerElement}.
 * @throws IOException
 *             On a failure to read the contents of the
 *             {@code DBPointerElement}.
 * @deprecated Per the BSON specification.
 */
@Deprecated
protected Element readDBPointerElement() throws IOException {
    final long start = getBytesRead() - 1; // Token already read.

    final String name = readCString();
    final String dbDotCollection = readString();
    final int timestamp = EndianUtils.swap(readInt());
    final long machineId = EndianUtils.swap(readLong());

    final long size = getBytesRead() - start;

    String db = dbDotCollection;
    String collection = "";
    final int firstDot = dbDotCollection.indexOf('.');
    if (0 <= firstDot) {
        db = dbDotCollection.substring(0, firstDot);
        collection = dbDotCollection.substring(firstDot + 1);
    }
    return new com.allanbank.mongodb.bson.element.DBPointerElement(name,
            db, collection, new ObjectId(timestamp, machineId), size);
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:31,代码来源:BsonInputStream.java

示例11: compareTo

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Overridden to compare the values if the base class comparison is equals.
 * False is less than true.
 * </p>
 */
@Override
public int compareTo(final Element otherElement) {
    int result = super.compareTo(otherElement);

    if (result == 0) {
        final BooleanElement other = (BooleanElement) otherElement;

        final int value = myValue ? 1 : 0;
        final int otherValue = other.myValue ? 1 : 0;

        result = value - otherValue;
    }

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

示例12: testCompareTo

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Test method for {@link ArrayElement#compareTo(Element)}.
 */
@Test
public void testCompareTo() {
    final ArrayElement a1 = new ArrayElement("a", new StringElement("a",
            "1"));
    final ArrayElement a11 = new ArrayElement("a", new StringElement("a",
            "1"), new StringElement("a", "1"));
    final ArrayElement a2 = new ArrayElement("a", new StringElement("a",
            "2"));
    final ArrayElement b1 = new ArrayElement("b", new StringElement("a",
            "1"));
    final Element other = new MaxKeyElement("a");

    assertEquals(0, a1.compareTo(a1));
    assertTrue(a1.compareTo(a11) < 0);
    assertTrue(a11.compareTo(a1) > 0);
    assertTrue(a1.compareTo(a2) < 0);
    assertTrue(a2.compareTo(a1) > 0);
    assertTrue(a1.compareTo(b1) < 0);
    assertTrue(b1.compareTo(a1) > 0);
    assertTrue(a1.compareTo(other) < 0);
    assertTrue(other.compareTo(a1) > 0);
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:26,代码来源:ArrayElementTest.java

示例13: compareTo

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Overridden to compare the values if the base class comparison is equals.
 * </p>
 * <p>
 * Note that for MongoDB integers, longs, and doubles will return equal
 * based on the type. Care is taken here to make sure that double, integer,
 * and long values return the same value regardless of comparison order by
 * using the lowest resolution representation of the value.
 * </p>
 */
@Override
public int compareTo(final Element otherElement) {
    int result = super.compareTo(otherElement);

    if (result == 0) {
        // Might be a IntegerElement, LongElement, or DoubleElement.
        // Compare as integer or long.
        final NumericElement other = (NumericElement) otherElement;
        final ElementType otherType = other.getType();

        if (otherType == ElementType.DOUBLE) {
            result = Double.compare(getDoubleValue(),
                    other.getDoubleValue());
        }
        else {
            result = compare(getLongValue(), other.getLongValue());
        }
    }

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

示例14: testWithinDocumentAssignable

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * Test method for {@link ConditionBuilder#within(DocumentAssignable)}.
 */
@Test
public void testWithinDocumentAssignable() {
    final ConditionBuilder b = QueryBuilder.where("foo");

    final double x1 = myRandom.nextInt(1024);
    final double y1 = myRandom.nextInt(1024);
    final double x2 = x1 + myRandom.nextInt(1024);
    final double y2 = y1 + myRandom.nextInt(1024);

    b.equals(false); // Make sure equals is removed.
    b.within(GeoJson.polygon(Arrays.asList(GeoJson.p(x1, y1),
            GeoJson.p(x1, y2), GeoJson.p(x2, y2), GeoJson.p(x2, y1),
            GeoJson.p(x1, y1))));

    final Element e = b.buildFieldCondition();

    assertThat(e, instanceOf(DocumentElement.class));

    final DocumentBuilder db = BuilderFactory.start();
    final DocumentBuilder wb = db
            .push(GeospatialOperator.WITHIN.getToken());
    wb.add(GeospatialOperator.GEOMETRY, GeoJson.polygon(Arrays.asList(
            GeoJson.p(x1, y1), GeoJson.p(x1, y2), GeoJson.p(x2, y2),
            GeoJson.p(x2, y1), GeoJson.p(x1, y1))));

    assertEquals(new DocumentElement("foo", db.build()), e);
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:31,代码来源:ConditionBuilderTest.java

示例15: getOperationName

import com.allanbank.mongodb.bson.Element; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Overridden to return the command name.
 * </p>
 */
@Override
public String getOperationName() {
    // Return the value for the first element in the document.
    final Iterator<Element> iter = myCommand.iterator();
    if (iter.hasNext()) {
        return iter.next().getName();
    }
    // Not expected. Command documents should have atleast one element. Just
    // return a generic name here.
    return "command";
}
 
开发者ID:allanbank,项目名称:mongodb-async-driver,代码行数:18,代码来源:Command.java


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