protected static FastVector merge(Sequence seq1, Sequence seq2, boolean oneElements, boolean mergeElements) {
    FastVector mergeResult = new FastVector();

    //merge 1-sequences
    if (oneElements) {
      Element element1 = (Element) seq1.getElements().firstElement();
      Element element2 = (Element) seq2.getElements().firstElement();
      Element element3 = null;
      if (mergeElements) {
	for (int i = 0; i < element1.getEvents().length; i++) {
	  if (element1.getEvents()[i] > -1) {
	    if (element2.getEvents()[i] > -1) {
	      break;
	    } else {
	      element3 = Element.merge(element1, element2);
	    }
	  }
	}
      }
      FastVector newElements1 = new FastVector();
      //generate <{x}{y}>
      newElements1.addElement(element1);
      newElements1.addElement(element2);
      mergeResult.addElement(new Sequence(newElements1));
      //generate <{x,y}>
      if (element3 != null) {
	FastVector newElements2 = new FastVector();
	newElements2.addElement(element3);
	mergeResult.addElement(new Sequence(newElements2));
      }

      return mergeResult;
      //merge k-sequences, k > 1
    } else {
      Element lastElementSeq1 = (Element) seq1.getElements().lastElement();
      Element lastElementSeq2 = (Element) seq2.getElements().lastElement();
      Sequence resultSeq = new Sequence();
      FastVector resultSeqElements = resultSeq.getElements();

      //if last two events/items belong to the same element/itemset
      if (lastElementSeq2.containsOverOneEvent()) {
	for (int i = 0; i < (seq1.getElements().size()-1); i++) {
	  resultSeqElements.addElement(seq1.getElements().elementAt(i));
	}
	resultSeqElements.addElement(Element.merge(lastElementSeq1, lastElementSeq2));
	mergeResult.addElement(resultSeq);

	return mergeResult;
	//if last two events/items belong to different elements/itemsets
      } else {
	for (int i = 0; i < (seq1.getElements().size()); i++) {
	  resultSeqElements.addElement(seq1.getElements().elementAt(i));
	}
	resultSeqElements.addElement(lastElementSeq2);
	mergeResult.addElement(resultSeq);

	return mergeResult;
      }
    }
  }