예제 #1
0
  @SuppressWarnings("unchecked")
  public ConcurrentSkipListSet<RefexMember<?, ?>> entryToObject(
      TupleInput input, int enclosingConceptNid) {
    int listSize = input.readShort();

    if (listSize == 0) {
      return null;
    }

    ConcurrentSkipListSet<RefexMember<?, ?>> newRefsetMemberList =
        new ConcurrentSkipListSet<>(
            new Comparator<RefexChronicleBI<?>>() {
              @Override
              public int compare(RefexChronicleBI<?> t, RefexChronicleBI<?> t1) {
                return t.getNid() - t1.getNid();
              }
            });

    for (int index = 0; index < listSize; index++) {
      int typeNid = input.readInt();

      input.mark(8);

      int nid = input.readInt();

      input.reset();

      RefexMember<?, ?> refsetMember = (RefexMember<?, ?>) ConceptChronicle.componentsCRHM.get(nid);

      if (refsetMember == null) {
        try {
          refsetMember = factory.create(nid, typeNid, enclosingConceptNid, input);

          if (refsetMember.getTime() != Long.MIN_VALUE) {
            RefexMember<?, ?> oldMember =
                (RefexMember<?, ?>) ConceptChronicle.componentsCRHM.putIfAbsent(nid, refsetMember);

            if (oldMember != null) {
              refsetMember = oldMember;
            }
          }
        } catch (IOException ex) {
          throw new RuntimeException(ex);
        }
      } else {
        try {
          refsetMember.merge(
              factory.create(nid, typeNid, enclosingConceptNid, input),
              new HashSet<ConceptChronicleBI>());
        } catch (IOException ex) {
          throw new RuntimeException(ex);
        }
      }

      if (refsetMember.getTime() != Long.MIN_VALUE) {
        newRefsetMemberList.add(refsetMember);
      }
    }

    return newRefsetMemberList;
  }
  @Override
  public Collection<RefsetMember<?, ?>> entryToObject(TupleInput input) {
    assert enclosingConcept != null;
    int listSize = input.readInt();
    Collection<RefsetMember<?, ?>> newRefsetMemberList;
    HashMap<Integer, RefsetMember<?, ?>> nidToRefsetMemberMap = null;
    if (refsetMemberList != null) {
      newRefsetMemberList = refsetMemberList;
      nidToRefsetMemberMap = new HashMap<Integer, RefsetMember<?, ?>>(listSize);
      for (RefsetMember<?, ?> component : refsetMemberList) {
        nidToRefsetMemberMap.put(component.nid, component);
      }
    } else {
      newRefsetMemberList = new ArrayList<RefsetMember<?, ?>>(listSize);
    }

    for (int index = 0; index < listSize; index++) {
      int typeNid = input.readInt();

      // Can be removed in the future, here strictly for read/write conformance testing.
      try {
        REFSET_TYPES.nidToType(typeNid);
      } catch (IOException e1) {
        AceLog.getAppLog()
            .alertAndLogException(new Exception("For concept: " + enclosingConcept.toString(), e1));
        AceLog.getAppLog().info("List prior to exception: " + newRefsetMemberList);
        return newRefsetMemberList;
      }
      input.mark(8);
      int nid = input.readInt();
      input.reset();
      RefsetMember<?, ?> refsetMember = (RefsetMember<?, ?>) Concept.componentsCRHM.get(nid);
      if (nidToRefsetMemberMap != null && nidToRefsetMemberMap.containsKey(nid)) {
        if (refsetMember == null) {
          refsetMember = nidToRefsetMemberMap.get(nid);
          RefsetMember<?, ?> oldMember =
              (RefsetMember<?, ?>) Concept.componentsCRHM.putIfAbsent(nid, refsetMember);
          if (oldMember != null) {
            refsetMember = oldMember;
            if (nidToRefsetMemberMap != null) {
              nidToRefsetMemberMap.put(nid, refsetMember);
            }
          }
        }
        refsetMember.readComponentFromBdb(input);
      } else {
        try {
          if (refsetMember == null) {
            refsetMember = factory.create(nid, typeNid, enclosingConcept, input);
            if (refsetMember.getTime() != Long.MIN_VALUE) {
              Concept.componentsCRHM.putIfAbsent(nid, refsetMember);
              RefsetMember<?, ?> oldMember =
                  (RefsetMember<?, ?>) Concept.componentsCRHM.putIfAbsent(nid, refsetMember);
              if (oldMember != null) {
                refsetMember = oldMember;
                if (nidToRefsetMemberMap != null) {
                  nidToRefsetMemberMap.put(nid, refsetMember);
                }
              }
            } else {
              AceLog.getAppLog()
                  .warning(
                      "\n########## Suppressing refset member:\n     "
                          + refsetMember
                          + "\n##########");
            }
          } else {
            refsetMember.merge(factory.create(nid, typeNid, enclosingConcept, input));
          }
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
        if (refsetMember.getTime() != Long.MIN_VALUE) {
          newRefsetMemberList.add(refsetMember);
        }
      }
    }
    return newRefsetMemberList;
  }