java/core/src/main/java/se/lth/cs/docria/Document.java
/**
     * For internal use: Compacts all layers and offsets in texts, used to prepare for serialization.
     */
For internal use: Compacts all layers and offsets in texts, used to prepare for serialization.
For internal use : Compacts all layers and offsets in texts used to prepare for serialization .
public Compiled compile() {
        layerStream().forEach(Layer::compact);
        texts.forEach( (k,v) -> v.reset());
        layerStream().forEach(layer -> {
            List<String> spanFields = new ArrayList<>();
            List<String> spanContexts = new ArrayList<>();
            layer.schema().fields().entrySet().stream().filter(e -> e.getValue().name().equals(DataTypeName.SPAN)).forEach(e -> {
                spanFields.add(e.getKey());
                spanContexts.add((String)e.getValue().args().get("context").stringValue());
            });
            if(spanFields.size() > 0) {
                layer.forEach(n -> {
                    for (String spanField : spanFields) {
                        if(n.has(spanField))
                            n.get(spanField).spanValue().incref();
                    }
                });
            }
        });
        TreeMap<String,List<String>> text2parts = new TreeMap<>();
        texts.forEach( (k,v) -> text2parts.put(k, v.compile()));
        return new Compiled(text2parts);
    }
public Compiled compile ( ) { layerStream ( ) . forEach ( Layer :: compact ) ; texts . forEach ( ( k , v ) -> v . reset ( ) ) ; layerStream ( ) . forEach ( layer -> { List < String > spanFields = new ArrayList < > ( ) ; List < String > spanContexts = new ArrayList < > ( ) ; layer . schema ( ) . fields ( ) . entrySet ( ) . stream ( ) . filter ( e -> e . getValue ( ) . name ( ) . equals ( DataTypeName . SPAN ) ) . forEach ( e -> { spanFields . add ( e . getKey ( ) ) ; spanContexts . add ( ( String ) e . getValue ( ) . args ( ) . get ( "context" ) . stringValue ( ) ) ; } ) ; if ( spanFields . size ( ) > 0 ) { layer . forEach ( n -> { for ( String spanField : spanFields ) { if ( n . has ( spanField ) ) n . get ( spanField ) . spanValue ( ) . incref ( ) ; } } ) ; } } ) ; TreeMap < String , List < String > > text2parts = new TreeMap < > ( ) ; texts . forEach ( ( k , v ) -> text2parts . put ( k , v . compile ( ) ) ) ; return new Compiled ( text2parts ) ; }
For internal use: Compacts all layers and offsets in texts, used to prepare for serialization.
For internal use : Compacts all layers and offsets in texts used to prepare for serialization .