Java 类org.bson.BsonDateTime 实例源码

项目:BsonMapper    文件:TestUtil.java   
public static BsonDocument getBsonDocument() {
    BsonDocument bsonObj = new BsonDocument().append("testDouble", new BsonDouble(20.777));
    List<BsonDocument> list = new ArrayList<BsonDocument>();
    list.add(bsonObj);
    list.add(bsonObj);
    byte[] bytes = new byte[3];
    bytes[0] = 3;
    bytes[1] = 2;
    bytes[2] = 1;
    BsonDocument bsonDocument = new BsonDocument().append("testDouble", new BsonDouble(20.99))
            .append("testString", new BsonString("testStringV"))
            .append("testArray", new BsonArray(list));
    return new BsonDocument().append("testDouble", new BsonDouble(20.99))
            .append("testString", new BsonString("testStringV"))
            .append("testArray", new BsonArray(list))
            .append("bson_test", bsonDocument)
            .append("testBinary", new BsonBinary(bytes))
            .append("testBsonUndefined", new BsonUndefined())
            .append("testObjectId", new BsonObjectId())
            .append("testStringObjectId", new BsonObjectId())
            .append("testBoolean", new BsonBoolean(true))
            .append("testDate", new BsonDateTime(time))
            .append("testNull", new BsonNull())
            .append("testInt", new BsonInt32(233))
            .append("testLong", new BsonInt64(233332));
}
项目:oson    文件:DocumentTest.java   
@Test
public void testBsonDocumentDeSerialize() {
    BsonDocument document = new BsonDocument().append("a", new BsonString("MongoDB"))
               .append("b", new BsonArray(Arrays.asList(new BsonInt32(1), new BsonInt32(2))))
               .append("c", new BsonBoolean(true))
               .append("d", new BsonDateTime(0));

    String json = oson.useAttribute(false).setValueOnly(true).serialize(document);

    String expected = "{\"a\":\"MongoDB\",\"b\":[1,2],\"c\":true,\"d\":0}";

    assertEquals(expected, json);

    BsonDocument document2 = oson.deserialize(json, BsonDocument.class);

    assertEquals(expected, oson.serialize(document2));
}
项目:epcis    文件:LongInterval.java   
public static BsonDocument addTemporalRelationFilterQuery(BsonDocument filter, LongInterval left, AC ss, AC se,
        AC es, AC ee) {
    if (filter == null)
        filter = new BsonDocument();

    BsonArray and = new BsonArray();
    if (ss != null)
        and.add(new BsonDocument(Tokens.START, new BsonDocument(ss.toString(), new BsonDateTime(left.getStart()))));
    if (se != null)
        and.add(new BsonDocument(Tokens.START, new BsonDocument(es.toString(), new BsonDateTime(left.getEnd()))));
    if (es != null)
        and.add(new BsonDocument(Tokens.END, new BsonDocument(se.toString(), new BsonDateTime(left.getStart()))));
    if (ee != null)
        and.add(new BsonDocument(Tokens.END, new BsonDocument(ee.toString(), new BsonDateTime(left.getEnd()))));
    return filter.append(C.$and.toString(), and);
}
项目:epcis    文件:ChronoGraph.java   
/**
 * Return non-redundant timestamps of all graph element events
 * 
 * @return HashSet<Long> timestamps
 */
public TreeSet<Long> getTimestamps() {
    TreeSet<Long> timestampSet = new TreeSet<Long>();

    Function<BsonDateTime, Long> mapper = new Function<BsonDateTime, Long>() {
        @Override
        public Long apply(BsonDateTime val) {
            return val.getValue();
        }

    };
    edgeEvents.distinct(Tokens.TIMESTAMP, BsonDateTime.class)
            .filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
            .map(mapper).into(timestampSet);
    Set<Long> vtSet = new TreeSet<Long>();

    vertexEvents.distinct(Tokens.TIMESTAMP, BsonDateTime.class)
            .filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
            .map(mapper).into(vtSet);
    timestampSet.addAll(vtSet);

    return timestampSet;
}
项目:epcis    文件:ChronoGraph.java   
public TreeSet<Long> getTimestamps(Long startTime, Long endTime) {
    TreeSet<Long> timestampSet = new TreeSet<Long>();

    Function<BsonDateTime, Long> mapper = new Function<BsonDateTime, Long>() {
        @Override
        public Long apply(BsonDateTime val) {
            return val.getValue();
        }

    };
    edgeEvents.distinct(Tokens.TIMESTAMP, BsonDateTime.class)
            .filter(new BsonDocument(Tokens.TIMESTAMP,
                    new BsonDocument(Tokens.FC.$gt.toString(), new BsonDateTime(startTime))
                            .append(Tokens.FC.$lt.toString(), new BsonDateTime(endTime))))
            .map(mapper).into(timestampSet);
    Set<Long> vtSet = new TreeSet<Long>();

    vertexEvents.distinct(Tokens.TIMESTAMP, BsonDateTime.class)
            .filter(new BsonDocument(Tokens.TIMESTAMP,
                    new BsonDocument(Tokens.FC.$gt.toString(), new BsonDateTime(startTime))
                            .append(Tokens.FC.$lt.toString(), new BsonDateTime(endTime))))
            .map(mapper).into(timestampSet);
    timestampSet.addAll(vtSet);

    return timestampSet;
}
项目:epcis    文件:ChronoGraph.java   
public HashSet<Long> getTimestampsHashSet() {
    HashSet<Long> timestampSet = new HashSet<Long>();

    Function<BsonDateTime, Long> mapper = new Function<BsonDateTime, Long>() {
        @Override
        public Long apply(BsonDateTime val) {
            return val.getValue();
        }

    };
    edges.distinct(Tokens.TIMESTAMP, BsonDateTime.class)
            .filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
            .map(mapper).into(timestampSet);

    return timestampSet;
}
项目:epcis    文件:ChronoElement.java   
/**
 * set timestamp properties (replace) for the given timestamp
 * 
 * @param timestamp
 * @param timestampProperties
 */
public void setTimestampProperties(final Long timestamp, BsonDocument timestampProperties) {
    if (timestampProperties == null)
        timestampProperties = new BsonDocument();
    if (this instanceof ChronoVertex) {
        graph.getVertexEvents().findOneAndReplace(
                new BsonDocument(Tokens.VERTEX, new BsonString(this.id)).append(Tokens.TIMESTAMP,
                        new BsonDateTime(timestamp)),
                Converter.makeTimestampVertexEventDocumentWithoutID(timestampProperties, this.id, timestamp),
                new FindOneAndReplaceOptions().upsert(true));
    } else {
        ChronoEdge e = (ChronoEdge) this;
        graph.getEdgeEvents().findOneAndReplace(
                new BsonDocument(Tokens.OUT_VERTEX, new BsonString(e.getOutVertex().toString()))
                        .append(Tokens.LABEL, new BsonString(e.getLabel()))
                        .append(Tokens.TIMESTAMP, new BsonDateTime(timestamp))
                        .append(Tokens.IN_VERTEX, new BsonString(e.getInVertex().toString())),
                Converter.makeTimestampEdgeEventDocumentWithoutID(timestampProperties, this.id, timestamp),
                new FindOneAndReplaceOptions().upsert(true));
    }
}
项目:epcis    文件:ChronoElement.java   
/**
 * @param timestamp
 * @param projection
 * @return TimestampProperties BsonDocument only containing projection keys
 */
public BsonDocument getTimestampProperties(final Long timestamp, final String[] projection) {
    BsonDocument bsonProjection = new BsonDocument();
    if (projection != null) {
        for (String string : projection) {
            bsonProjection.append(string, new BsonBoolean(true));
        }
    }

    if (this instanceof ChronoVertex)
        return graph.getVertexEvents()
                .find(new BsonDocument(Tokens.VERTEX, new BsonString(this.id)).append(Tokens.TIMESTAMP, new BsonDateTime(timestamp)))
                .projection(bsonProjection).first();
    else
        return graph.getEdgeCollection()
                .find(new BsonDocument(Tokens.ID, new BsonString(this.id + "-" + timestamp)))
                .projection(bsonProjection).first();
}
项目:epcis    文件:Converter.java   
public static BsonDocument makeTimestampEdgeEventDocument(BsonDocument base, String eID, long timestamp) {
    if (base == null)
        base = new BsonDocument();

    String[] arr = eID.split("\\|");
    String outV = arr[0];
    String inV = arr[2];
    String label = arr[1];
    base.put(Tokens.ID, new BsonString(eID + "-" + timestamp));
    base.put(Tokens.OUT_VERTEX, new BsonString(outV));
    base.put(Tokens.LABEL, new BsonString(label));
    base.put(Tokens.IN_VERTEX, new BsonString(inV));
    base.put(Tokens.EDGE, new BsonString(eID));
    base.put(Tokens.TIMESTAMP, new BsonDateTime(timestamp));
    base.put(Tokens.TYPE, Tokens.TYPE_TIMESTAMP);
    return base;
}
项目:epcis    文件:Converter.java   
public static BsonDocument makeTimestampEdgeEventDocumentWithoutID(BsonDocument base, String eID, long timestamp) {
    if (base == null)
        base = new BsonDocument();

    String[] arr = eID.split("\\|");
    String outV = arr[0];
    String inV = arr[2];
    String label = arr[1];
    base.put(Tokens.OUT_VERTEX, new BsonString(outV));
    base.put(Tokens.LABEL, new BsonString(label));
    base.put(Tokens.IN_VERTEX, new BsonString(inV));
    // base.put(Tokens.EDGE, new BsonString(eID));
    base.put(Tokens.TIMESTAMP, new BsonDateTime(timestamp));
    // base.put(Tokens.TYPE, Tokens.TYPE_TIMESTAMP);
    return base;
}
项目:BsonMapper    文件:TDocument.java   
@Override
public Date getDate(Object key) {
    BsonDateTime dateTime = innerBsonDocument.getDateTime(key);
    if (dateTime != null) {
        return (Date) BsonValueConverterRepertory.getValueConverterByBsonType(dateTime.getBsonType()).decode(dateTime);
    } else {
        return null;
    }
}
项目:drill    文件:TestBsonRecordReader.java   
@Test
public void testDateTimeType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  bsonDoc.append("dateTimeKey", new BsonDateTime(5262729712L));
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  assertEquals(5262729712L, mapReader.reader("dateTimeKey").readDateTime().getMillis());
}
项目:oap    文件:JsonCodec.java   
@SneakyThrows
@Override
public void encode( BsonWriter bsonWriter, T data, EncoderContext encoderContext ) {
    val doc = Document.parse( fileWriter.writeValueAsString( data ) );

    val id = idFunc.apply( data );

    doc.put( "_id", new ObjectId( id ) );

    val modified = doc.get( "modified" );
    doc.put( "modified", new BsonDateTime( ( Long ) modified ) );

    documentCodec.encode( bsonWriter, doc, encoderContext );
}
项目:epcis    文件:MongoReaderUtil.java   
static XMLGregorianCalendar getXMLGregorianCalendar(BsonDateTime bdt) {
    try {
        GregorianCalendar eventCalendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        eventCalendar.setTimeInMillis(bdt.getValue());
        XMLGregorianCalendar xmlEventTime;
        xmlEventTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(eventCalendar);
        return xmlEventTime;
    } catch (DatatypeConfigurationException e) {
        Configuration.logger.error(e.toString());
    }
    return null;
}
项目:epcis    文件:MongoWriterUtil.java   
public static BsonValue converseType(String value) {
    String[] valArr = value.split("\\^");
    if (valArr.length != 2) {
        return new BsonString(value);
    }
    try {
        String type = valArr[1];
        if (type.equals("int")) {
            return new BsonInt32(Integer.parseInt(valArr[0]));
        } else if (type.equals("long")) {
            return new BsonInt64(Long.parseLong(valArr[0]));
        } else if (type.equals("double")) {
            return new BsonDouble(Double.parseDouble(valArr[0]));
        } else if (type.equals("boolean")) {
            return new BsonBoolean(Boolean.parseBoolean(valArr[0]));
        } else if (type.equals("float")) {
            return new BsonDouble(Double.parseDouble(valArr[0]));
        } else if (type.equals("dateTime")) {
            BsonDateTime time = getBsonDateTime(valArr[0]);
            if (time != null)
                return time;
            return new BsonString(value);
        } else if (type.equals("geoPoint")) {
            BsonDocument point = getBsonGeoPoint(valArr[0]);
            if (point == null)
                return new BsonString(value);
            return point;
        } else if (type.equals("geoArea")) {
            BsonDocument area = getBsonGeoArea(valArr[0]);
            if (area == null)
                return new BsonString(value);
            return area;
        } else {
            return new BsonString(value);
        }
    } catch (NumberFormatException e) {
        return new BsonString(value);
    }
}
项目:epcis    文件:MongoWriterUtil.java   
static BsonDocument getErrorDeclaration(ErrorDeclarationType edt) {
    BsonDocument errorBson = new BsonDocument();
    long declarationTime = edt.getDeclarationTime().toGregorianCalendar().getTimeInMillis();
    errorBson.put("declarationTime", new BsonDateTime(declarationTime));
    // (Optional) reason
    if (edt.getReason() != null) {
        errorBson.put("reason", new BsonString(edt.getReason()));
    }
    // (Optional) correctiveEventIDs
    if (edt.getCorrectiveEventIDs() != null) {
        CorrectiveEventIDsType cIDs = edt.getCorrectiveEventIDs();
        List<String> cIDStringList = cIDs.getCorrectiveEventID();
        BsonArray correctiveIDBsonArray = new BsonArray();
        for (String cIDString : cIDStringList) {
            correctiveIDBsonArray.add(new BsonString(cIDString));
        }
        if (correctiveIDBsonArray.size() != 0) {
            errorBson.put("correctiveEventIDs", correctiveIDBsonArray);
        }
    }
    if (edt.getAny() != null) {
        BsonDocument map2Save = getAnyMap(edt.getAny());
        if (map2Save != null && map2Save.isEmpty() == false) {
            errorBson.put("any", map2Save);
        }
    }

    return errorBson;
}
项目:epcis    文件:MongoQueryUtil.java   
static BsonValue converseType(String value) {
    String[] valArr = value.split("\\^");
    if (valArr.length != 2) {
        return new BsonString(value);
    }
    try {
        String type = valArr[1].trim();
        if (type.equals("int")) {
            return new BsonInt32(Integer.parseInt(valArr[0]));
        } else if (type.equals("long")) {
            return new BsonInt64(Long.parseLong(valArr[0]));
        } else if (type.equals("double")) {
            return new BsonDouble(Double.parseDouble(valArr[0]));
        } else if (type.equals("boolean")) {
            return new BsonBoolean(Boolean.parseBoolean(valArr[0]));
        } else if (type.equals("regex")) {
            return new BsonRegularExpression("^" + valArr[0] + "$");
        } else if (type.equals("float")) {
            return new BsonDouble(Double.parseDouble(valArr[0]));
        } else if (type.equals("dateTime")) {
            BsonDateTime time = MongoQueryService.getTimeMillis(valArr[0]);
            if (time != null)
                return time;
            return new BsonString(value);
        } else {
            return new BsonString(value);
        }
    } catch (NumberFormatException e) {
        return new BsonString(value);
    }
}
项目:epcis    文件:ECReportCapture.java   
private Map<String, BsonValue> getExtensionMap(List<ECReportMemberField> fields) {
    Map<String, BsonValue> extMap = new HashMap<String, BsonValue>();
    for (int l = 0; l < fields.size(); l++) {
        ECReportMemberField field = fields.get(l);
        String key = field.getName();
        String value = field.getValue();
        String[] valArr = value.split("\\^");
        if (valArr.length != 2) {
            extMap.put(key, new BsonString(value));
            continue;
        }
        try {
            String type = valArr[1];
            if (type.equals("int")) {
                extMap.put(key, new BsonInt32(Integer.parseInt(valArr[0])));
            } else if (type.equals("long")) {
                extMap.put(key, new BsonInt64(Long.parseLong(valArr[0])));
            } else if (type.equals("double")) {
                extMap.put(key, new BsonDouble(Double.parseDouble(valArr[0])));
            } else if (type.equals("boolean")) {
                extMap.put(key, new BsonBoolean(Boolean.parseBoolean(valArr[0])));
            } else if (type.equals("dateTime")) {
                extMap.put(key, new BsonDateTime(Long.parseLong(valArr[0])));
            } else {
                extMap.put(key, new BsonString(valArr[0]));
            }
        } catch (NumberFormatException e) {
            extMap.put(key, new BsonString(valArr[0]));
        }
    }
    return extMap;
}
项目:epcis    文件:MongoReaderUtil.java   
static XMLGregorianCalendar getXMLGregorianCalendar(BsonDateTime bdt) {
    try {
        GregorianCalendar eventCalendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        eventCalendar.setTimeInMillis(bdt.getValue());
        XMLGregorianCalendar xmlEventTime;
        xmlEventTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(eventCalendar);
        return xmlEventTime;
    } catch (DatatypeConfigurationException e) {
        Configuration.logger.error(e.toString());
    }
    return null;
}
项目:epcis    文件:MongoWriterUtil.java   
public static BsonValue converseType(String value) {
    String[] valArr = value.split("\\^");
    if (valArr.length != 2) {
        return new BsonString(value);
    }
    try {
        String type = valArr[1];
        if (type.equals("int")) {
            return new BsonInt32(Integer.parseInt(valArr[0]));
        } else if (type.equals("long")) {
            return new BsonInt64(Long.parseLong(valArr[0]));
        } else if (type.equals("double")) {
            return new BsonDouble(Double.parseDouble(valArr[0]));
        } else if (type.equals("boolean")) {
            return new BsonBoolean(Boolean.parseBoolean(valArr[0]));
        } else if (type.equals("float")) {
            return new BsonDouble(Double.parseDouble(valArr[0]));
        } else if (type.equals("dateTime")) {
            BsonDateTime time = getBsonDateTime(valArr[0]);
            if (time != null)
                return time;
            return new BsonString(value);
        } else if (type.equals("geoPoint")) {
            BsonDocument point = getBsonGeoPoint(valArr[0]);
            if (point == null)
                return new BsonString(value);
            return point;
        } else if (type.equals("geoArea")) {
            BsonDocument area = getBsonGeoArea(valArr[0]);
            if (area == null)
                return new BsonString(value);
            return area;
        } else {
            return new BsonString(value);
        }
    } catch (NumberFormatException e) {
        return new BsonString(value);
    }
}
项目:epcis    文件:MongoWriterUtil.java   
static BsonDocument getErrorDeclaration(ErrorDeclarationType edt) {
    BsonDocument errorBson = new BsonDocument();
    long declarationTime = edt.getDeclarationTime().toGregorianCalendar().getTimeInMillis();
    errorBson.put("declarationTime", new BsonDateTime(declarationTime));
    // (Optional) reason
    if (edt.getReason() != null) {
        errorBson.put("reason", new BsonString(edt.getReason()));
    }
    // (Optional) correctiveEventIDs
    if (edt.getCorrectiveEventIDs() != null) {
        CorrectiveEventIDsType cIDs = edt.getCorrectiveEventIDs();
        List<String> cIDStringList = cIDs.getCorrectiveEventID();
        BsonArray correctiveIDBsonArray = new BsonArray();
        for (String cIDString : cIDStringList) {
            correctiveIDBsonArray.add(new BsonString(cIDString));
        }
        if (correctiveIDBsonArray.size() != 0) {
            errorBson.put("correctiveEventIDs", correctiveIDBsonArray);
        }
    }
    if (edt.getAny() != null) {
        BsonDocument map2Save = getAnyMap(edt.getAny());
        if (map2Save != null && map2Save.isEmpty() == false) {
            errorBson.put("any", map2Save);
        }
    }

    return errorBson;
}
项目:epcis    文件:MongoQueryUtil.java   
static BsonValue converseType(String value) {
    String[] valArr = value.split("\\^");
    if (valArr.length != 2) {
        return new BsonString(value);
    }
    try {
        String type = valArr[1].trim();
        if (type.equals("int")) {
            return new BsonInt32(Integer.parseInt(valArr[0]));
        } else if (type.equals("long")) {
            return new BsonInt64(Long.parseLong(valArr[0]));
        } else if (type.equals("double")) {
            return new BsonDouble(Double.parseDouble(valArr[0]));
        } else if (type.equals("boolean")) {
            return new BsonBoolean(Boolean.parseBoolean(valArr[0]));
        } else if (type.equals("regex")) {
            return new BsonRegularExpression("^" + valArr[0] + "$");
        } else if (type.equals("float")) {
            return new BsonDouble(Double.parseDouble(valArr[0]));
        } else if (type.equals("dateTime")) {
            BsonDateTime time = MongoQueryService.getTimeMillis(valArr[0]);
            if (time != null)
                return time;
            return new BsonString(value);
        } else {
            return new BsonString(value);
        }
    } catch (NumberFormatException e) {
        return new BsonString(value);
    }
}
项目:epcis    文件:ECReportCapture.java   
private Map<String, BsonValue> getExtensionMap(List<ECReportMemberField> fields) {
    Map<String, BsonValue> extMap = new HashMap<String, BsonValue>();
    for (int l = 0; l < fields.size(); l++) {
        ECReportMemberField field = fields.get(l);
        String key = field.getName();
        String value = field.getValue();
        String[] valArr = value.split("\\^");
        if (valArr.length != 2) {
            extMap.put(key, new BsonString(value));
            continue;
        }
        try {
            String type = valArr[1];
            if (type.equals("int")) {
                extMap.put(key, new BsonInt32(Integer.parseInt(valArr[0])));
            } else if (type.equals("long")) {
                extMap.put(key, new BsonInt64(Long.parseLong(valArr[0])));
            } else if (type.equals("double")) {
                extMap.put(key, new BsonDouble(Double.parseDouble(valArr[0])));
            } else if (type.equals("boolean")) {
                extMap.put(key, new BsonBoolean(Boolean.parseBoolean(valArr[0])));
            } else if (type.equals("dateTime")) {
                extMap.put(key, new BsonDateTime(Long.parseLong(valArr[0])));
            } else {
                extMap.put(key, new BsonString(valArr[0]));
            }
        } catch (NumberFormatException e) {
            extMap.put(key, new BsonString(valArr[0]));
        }
    }
    return extMap;
}
项目:epcis    文件:LongInterval.java   
public static BsonDocument getTemporalRelationFilterQuery(long left, AC ss, AC se) {
    BsonDocument filter = new BsonDocument();
    if (ss != null)
        filter.append(Tokens.START, new BsonDocument(ss.toString(), new BsonDateTime(left)));
    if (se != null)
        filter.append(Tokens.END, new BsonDocument(se.toString(), new BsonDateTime(left)));
    return filter;
}
项目:epcis    文件:LongInterval.java   
public static BsonDocument addTemporalRelationFilterQuery(BsonDocument filter, long left, AC ss, AC se) {
    if (filter == null)
        filter = new BsonDocument();
    if (ss != null)
        filter.append(Tokens.START, new BsonDocument(ss.toString(), new BsonDateTime(left)));
    if (se != null)
        filter.append(Tokens.END, new BsonDocument(se.toString(), new BsonDateTime(left)));
    return filter;
}
项目:epcis    文件:LongInterval.java   
public static BsonDocument getTemporalRelationFilterQuery(LongInterval left, AC ss, AC se, AC es, AC ee) {
    BsonArray and = new BsonArray();
    if (ss != null)
        and.add(new BsonDocument(Tokens.START, new BsonDocument(ss.toString(), new BsonDateTime(left.getStart()))));
    if (se != null)
        and.add(new BsonDocument(Tokens.START, new BsonDocument(es.toString(), new BsonDateTime(left.getEnd()))));
    if (es != null)
        and.add(new BsonDocument(Tokens.END, new BsonDocument(se.toString(), new BsonDateTime(left.getStart()))));
    if (ee != null)
        and.add(new BsonDocument(Tokens.END, new BsonDocument(ee.toString(), new BsonDateTime(left.getEnd()))));
    return new BsonDocument(C.$and.toString(), and);
}
项目:epcis    文件:ChronoGraph.java   
public CachedChronoGraph getSnapshot(Long t) {
    CachedChronoGraph g = new CachedChronoGraph();
    MongoCursor<BsonDocument> c = this.getEdgeEvents().find(new BsonDocument(Tokens.TIMESTAMP, new BsonDateTime(t)))
            .iterator();
    while (c.hasNext()) {
        BsonDocument doc = c.next();
        String outV = doc.getString(Tokens.OUT_VERTEX).getValue();
        String label = doc.getString(Tokens.LABEL).getValue();
        String inV = doc.getString(Tokens.IN_VERTEX).getValue();
        CachedChronoEdge e = g.addEdge(outV, inV, label);
        e.setProperties(doc);
    }
    return g;
}
项目:epcis    文件:ChronoElement.java   
/**
 * @param timestamp
 * @return TimestampProperties BsonDocument
 */
public BsonDocument getTimestampProperties(final Long timestamp) {
    if (this instanceof ChronoVertex)
        return graph.getVertexEvents().find(new BsonDocument(Tokens.VERTEX, new BsonString(this.id))
                .append(Tokens.TIMESTAMP, new BsonDateTime(timestamp))).first();
    else {
        String[] idArr = this.id.split("\\|");
        String outV = idArr[0];
        String label = idArr[1];
        String inV = idArr[2];
        return graph.getEdgeEvents().find(new BsonDocument(Tokens.OUT_VERTEX, new BsonString(outV))
                .append(Tokens.LABEL, new BsonString(label)).append(Tokens.TIMESTAMP, new BsonDateTime(timestamp))
                .append(Tokens.IN_VERTEX, new BsonString(inV))).projection(Tokens.PRJ_NOT_ID).first();
    }
}
项目:epcis    文件:VertexEvent.java   
public Set<VertexEvent> getOutVertexEventSet(final String label, final AC tt) {

        // db.edges.createIndex({"_outV" : 1, "_label" : 1, "_t" : 1, "_inV" : 1})
        BsonDocument query = new BsonDocument(Tokens.OUT_VERTEX, new BsonString(vertex.toString()));
        query.append(Tokens.LABEL, new BsonString(label));
        query.append(Tokens.TIMESTAMP, new BsonDocument(tt.toString(), new BsonDateTime(timestamp)));
        BsonDocument proj = new BsonDocument(Tokens.TIMESTAMP, new BsonBoolean(true))
                .append(Tokens.IN_VERTEX, new BsonBoolean(true)).append(Tokens.ID, new BsonBoolean(false));

        HashSet<VertexEvent> ret = new HashSet<VertexEvent>();
        Iterator<BsonDocument> x = vertex.graph.getEdgeEvents().find(query).projection(proj).iterator();
        HashMap<String, Long> map = new HashMap<String, Long>();
        while (x.hasNext()) {
            BsonDocument d = x.next();
            String inV = d.getString(Tokens.IN_VERTEX).getValue();
            Long t = d.getDateTime(Tokens.TIMESTAMP).getValue();
            if (map.containsKey(inV)) {
                // TODO:
                if (map.get(inV) > t)
                    map.put(inV, t);
            } else
                map.put(inV, t);
        }

        map.entrySet().parallelStream().forEach(entry -> {
            VertexEvent ve = new VertexEvent(graph, entry.getKey() + "-" + entry.getValue());
            ret.add(ve);
        });
        return ret;
    }
项目:epcis    文件:VertexEvent.java   
public Set<VertexEvent> getInVertexEventSet(final String label, final AC tt) {

        // db.edges.createIndex({"_outV" : 1, "_label" : 1, "_t" : 1, "_inV" : 1})
        BsonDocument query = new BsonDocument(Tokens.IN_VERTEX, new BsonString(vertex.toString()));
        query.append(Tokens.LABEL, new BsonString(label));
        query.append(Tokens.TIMESTAMP, new BsonDocument(tt.toString(), new BsonDateTime(timestamp)));
        BsonDocument proj = new BsonDocument(Tokens.TIMESTAMP, new BsonBoolean(true))
                .append(Tokens.OUT_VERTEX, new BsonBoolean(true)).append(Tokens.ID, new BsonBoolean(false));

        HashSet<VertexEvent> ret = new HashSet<VertexEvent>();
        Iterator<BsonDocument> x = vertex.graph.getEdgeCollection().find(query).projection(proj).iterator();
        HashMap<String, Long> map = new HashMap<String, Long>();
        while (x.hasNext()) {
            BsonDocument d = x.next();
            String outV = d.getString(Tokens.OUT_VERTEX).getValue();
            Long t = d.getDateTime(Tokens.TIMESTAMP).getValue();
            if (map.containsKey(outV)) {
                // TODO:
                if (map.get(outV) > t)
                    map.put(outV, t);
            } else
                map.put(outV, t);
        }

        map.entrySet().parallelStream().forEach(entry -> {
            VertexEvent ve = new VertexEvent(graph, entry.getKey() + "-" + entry.getValue());
            ret.add(ve);
        });
        return ret;
    }
项目:epcis    文件:VertexEvent.java   
public Set<VertexEvent> getOutVertexEventSet(final AC tt) {
    while (true) {
        try {
            // db.tEdgeEvents.aggregate([{$match:{"_o":"1","_t":{ $lt : ISODate(0)
            // }}},{$project:{"_i":1,"_t":1,"_id":0}},{$group:{"_id":"$_i", "_mt": {$min:
            // "$_t"}}}])
            BsonDocument match = new BsonDocument("$match",
                    new BsonDocument(Tokens.OUT_VERTEX, new BsonString(vertex.toString())).append(Tokens.TIMESTAMP,
                            new BsonDocument("$gt", new BsonDateTime(timestamp))));
            BsonDocument project = new BsonDocument("$project",
                    new BsonDocument(Tokens.IN_VERTEX, new BsonBoolean(true))
                            .append(Tokens.TIMESTAMP, new BsonBoolean(true))
                            .append(Tokens.ID, new BsonBoolean(false)));
            BsonDocument group = new BsonDocument("$group",
                    new BsonDocument(Tokens.ID, new BsonString("$" + Tokens.IN_VERTEX)).append(Tokens.TIMESTAMP,
                            new BsonDocument("$min", new BsonString("$" + Tokens.TIMESTAMP))));

            ArrayList<BsonDocument> aggregateQuery = new ArrayList<BsonDocument>();
            aggregateQuery.add(match);
            aggregateQuery.add(project);
            aggregateQuery.add(group);

            HashSet<VertexEvent> ret = new HashSet<VertexEvent>();
            Function<BsonDocument, VertexEvent> mapper = new Function<BsonDocument, VertexEvent>() {
                @Override
                public VertexEvent apply(BsonDocument d) {
                    String inV = d.getString(Tokens.ID).getValue();
                    Long t = d.getDateTime(Tokens.TIMESTAMP).getValue();
                    return new VertexEvent(graph, new ChronoVertex(inV, graph), t);
                }
            };
            vertex.graph.getEdgeEvents().aggregate(aggregateQuery).map(mapper).into(ret);

            return ret;

        } catch (MongoCursorNotFoundException e1) {
            System.out.println(e1.getErrorMessage());
        }
    }
}
项目:epcis    文件:Converter.java   
public static BsonDocument getBaseTimestampVertexEventDocument(String vID, long timestamp) {
    BsonDocument base = new BsonDocument();
    base.put(Tokens.ID, new BsonString(vID + "-" + timestamp));
    base.put(Tokens.VERTEX, new BsonString(vID));
    base.put(Tokens.TIMESTAMP, new BsonDateTime(timestamp));
    base.put(Tokens.TYPE, Tokens.TYPE_TIMESTAMP);
    return base;
}
项目:epcis    文件:Converter.java   
public static BsonDocument getBaseTimestampEdgeEventDocument(String eID, long timestamp) {
    BsonDocument base = new BsonDocument();
    base.put(Tokens.ID, new BsonString(eID + "-" + timestamp));
    base.put(Tokens.EDGE, new BsonString(eID));
    base.put(Tokens.TIMESTAMP, new BsonDateTime(timestamp));
    base.put(Tokens.TYPE, Tokens.TYPE_TIMESTAMP);
    return base;
}
项目:epcis    文件:Converter.java   
public static BsonDocument makeTimestampVertexEventDocument(BsonDocument base, String vID, long timestamp) {
    if (base == null)
        base = new BsonDocument();
    base.put(Tokens.ID, new BsonString(vID + "-" + timestamp));
    base.put(Tokens.VERTEX, new BsonString(vID));
    base.put(Tokens.TIMESTAMP, new BsonDateTime(timestamp));
    base.put(Tokens.TYPE, Tokens.TYPE_TIMESTAMP);
    return base;
}
项目:epcis    文件:Converter.java   
public static BsonDocument makeTimestampVertexEventDocumentWithoutID(BsonDocument base, String vID,
        long timestamp) {
    if (base == null)
        base = new BsonDocument();
    base.put(Tokens.VERTEX, new BsonString(vID));
    base.put(Tokens.TIMESTAMP, new BsonDateTime(timestamp));
    base.put(Tokens.TYPE, Tokens.TYPE_TIMESTAMP);
    return base;
}
项目:epcis    文件:Converter.java   
public static BsonDocument getBaseIntervalVertexEventDocument(String vID, LongInterval interval) {
    BsonDocument base = new BsonDocument();
    base.put(Tokens.ID, new BsonString(vID + "-" + interval.toString()));
    base.put(Tokens.VERTEX, new BsonString(vID));
    base.put(Tokens.START, new BsonDateTime(interval.getStart()));
    base.put(Tokens.END, new BsonDateTime(interval.getEnd()));
    base.put(Tokens.TYPE, Tokens.TYPE_INTERVAL);
    return base;
}
项目:epcis    文件:Converter.java   
public static BsonDocument getBaseIntervalEdgeEventDocument(String eID, LongInterval interval) {
    BsonDocument base = new BsonDocument();
    base.put(Tokens.ID, new BsonString(eID + "-" + interval.toString()));
    base.put(Tokens.EDGE, new BsonString(eID));
    base.put(Tokens.START, new BsonDateTime(interval.getStart()));
    base.put(Tokens.END, new BsonDateTime(interval.getEnd()));
    base.put(Tokens.TYPE, Tokens.TYPE_INTERVAL);
    return base;
}
项目:epcis    文件:Converter.java   
public static BsonDocument makeIntervalVertexEventDocument(BsonDocument base, String vID, LongInterval interval) {
    if (base == null)
        base = new BsonDocument();
    base.put(Tokens.ID, new BsonString(vID + "-" + interval.toString()));
    base.put(Tokens.VERTEX, new BsonString(vID));
    base.put(Tokens.START, new BsonDateTime(interval.getStart()));
    base.put(Tokens.END, new BsonDateTime(interval.getEnd()));
    base.put(Tokens.TYPE, Tokens.TYPE_INTERVAL);
    return base;
}
项目:epcis    文件:Converter.java   
public static BsonDocument makeIntervalEdgeEventDocument(BsonDocument base, String eID, LongInterval interval) {
    if (base == null)
        base = new BsonDocument();
    base.put(Tokens.ID, new BsonString(eID + "-" + interval.toString()));
    base.put(Tokens.EDGE, new BsonString(eID));
    base.put(Tokens.START, new BsonDateTime(interval.getStart()));
    base.put(Tokens.END, new BsonDateTime(interval.getEnd()));
    base.put(Tokens.TYPE, Tokens.TYPE_INTERVAL);
    return base;
}
项目:restheart    文件:URLUtils.java   
private static BsonDateTime getIdAsDate(String id) throws IllegalArgumentException {
    BsonValue ret = JsonUtils.parse(id);

    if (ret.isDateTime()) {
        return ret.asDateTime();
    } else if (ret.isInt32()) {
        return new BsonDateTime(0l + ret.asInt32().getValue());
    } else if (ret.isInt64()) {
        return new BsonDateTime(ret.asInt64().getValue());
    } else {
        throw new IllegalArgumentException("The id is not a valid number " + id);
    }

}