@Override
 public boolean isEmpty() {
   for (Segment<K, V> segment : segments) {
     if (segment.size() > 0) return false;
   }
   return true;
 }
Ejemplo n.º 2
0
 public Segment getSegmentDefinition(String segmentId) {
   Segment definition = persistenceService.load(segmentId, Segment.class);
   if (definition != null) {
     ParserHelper.resolveConditionType(definitionsService, definition.getCondition());
   }
   return definition;
 }
Ejemplo n.º 3
0
  /**
   * Method description
   *
   * @param heading
   * @return
   */
  public List<LocusScore> getWholeGenomeScores(String heading) {

    List<LocusScore> wholeGenomeScores = wholeGenomeScoresCache.get(heading);
    if ((wholeGenomeScores == null) || wholeGenomeScores.isEmpty()) {
      int locationUnit = 1000;

      // Compute the smallest concievable feature that could be viewed on the
      // largest screen.  Be conservative.   The smallest feature is one at
      // the screen resolution scale in <chr units> / <pixel>
      int maxScreenSize = 4000;
      double minFeatureSize = 0; // ((double) genome.getLength()) / (maxScreenSize * locationUnit);

      long offset = 0;
      wholeGenomeScores = new ArrayList(1000);
      for (String chr : genome.getChromosomeNames()) {
        List<LocusScore> chrSegments = getSegments(heading, chr);
        if (chrSegments != null) {
          int lastgEnd = -1;
          for (LocusScore score : chrSegments) {
            Segment seg = (Segment) score;
            int gStart = (int) ((offset + score.getStart()) / locationUnit);
            int gEnd = (int) ((offset + score.getEnd()) / locationUnit);
            if ((gEnd - gStart) > minFeatureSize) {
              wholeGenomeScores.add(
                  new Segment(gStart, gStart, gEnd, gEnd, seg.getScore(), seg.getDescription()));
            }
          }
        }
        offset += genome.getChromosome(chr).getLength();
      }
      wholeGenomeScoresCache.put(heading, wholeGenomeScores);
    }
    return wholeGenomeScores;
  }
Ejemplo n.º 4
0
 private List<Segment> getAllSegmentDefinitions() {
   List<Segment> allItems = persistenceService.getAllItems(Segment.class);
   for (Segment segment : allItems) {
     ParserHelper.resolveConditionType(definitionsService, segment.getCondition());
   }
   return allItems;
 }
Ejemplo n.º 5
0
  public static Segment shallowCopy(Segment segment, Factory factory) {
    Segment clone = factory.newSegment();
    for (String key : segment.keys()) {
      clone.setAttribute(key, segment.getAttribute(key));
    }

    return clone;
  }
 @Override
 public int size() {
   long total = 0;
   for (Segment<K, V> segment : segments) {
     total += segment.size();
   }
   return (int) Math.min(Integer.MAX_VALUE, total);
 }
 @Override
 public long offHeapUsed() {
   long total = 0;
   for (Segment<K, V> segment : segments) {
     total += segment.offHeapUsed();
   }
   return total;
 }
Ejemplo n.º 8
0
 public void addVariable(DapVariable var, List<Slice> slices) throws DapException {
   if (findVariableIndex(var) < 0) {
     Segment segment = new Segment(var);
     segment.setSlices(slices);
     this.segments.add(segment);
     this.variables.add(var);
   }
 }
Ejemplo n.º 9
0
 private Set<Segment> getScoringDependentSegments(String scoringId) {
   Set<Segment> impactedSegments = new HashSet<>(this.allSegments.size());
   for (Segment segment : this.allSegments) {
     if (checkScoringDeletionImpact(segment.getCondition(), scoringId)) {
       impactedSegments.add(segment);
     }
   }
   return impactedSegments;
 }
Ejemplo n.º 10
0
  public void setSegmentDefinition(Segment segment) {
    ParserHelper.resolveConditionType(definitionsService, segment.getCondition());
    if (segment.getMetadata().isEnabled() && !segment.getMetadata().isMissingPlugins()) {
      updateAutoGeneratedRules(segment.getMetadata(), segment.getCondition());
    }
    // make sure we update the name and description metadata that might not match, so first we
    // remove the entry from the map
    persistenceService.save(segment);

    updateExistingProfilesForSegment(segment);
  }
Ejemplo n.º 11
0
 public PartialList<Metadata> getSegmentMetadatas(
     String scope, int offset, int size, String sortBy) {
   PartialList<Segment> segments =
       persistenceService.query("metadata.scope", scope, sortBy, Segment.class, offset, size);
   List<Metadata> details = new LinkedList<>();
   for (Segment definition : segments.getList()) {
     details.add(definition.getMetadata());
   }
   return new PartialList<>(
       details, segments.getOffset(), segments.getPageSize(), segments.getTotalSize());
 }
Ejemplo n.º 12
0
 public DependentMetadata getScoringDependentMetadata(String scoringId) {
   List<Metadata> segments = new LinkedList<>();
   List<Metadata> scorings = new LinkedList<>();
   for (Segment definition : getScoringDependentSegments(scoringId)) {
     segments.add(definition.getMetadata());
   }
   for (Scoring definition : getScoringDependentScorings(scoringId)) {
     scorings.add(definition.getMetadata());
   }
   return new DependentMetadata(segments, scorings);
 }
Ejemplo n.º 13
0
  public List<Metadata> getSegmentMetadatasForProfile(Profile profile) {
    List<Metadata> metadatas = new ArrayList<>();

    List<Segment> allSegments = this.allSegments;
    for (Segment segment : allSegments) {
      if (persistenceService.testMatch(segment.getCondition(), profile)) {
        metadatas.add(segment.getMetadata());
      }
    }

    return metadatas;
  }
Ejemplo n.º 14
0
  private Segment addRelativeDendrite(Segment parent, Point3f relPosition) {
    Point3f newPosition = (new Point3f(parent.getEndPointPosition()));
    newPosition.add(relPosition);

    float newRadius = parent.getRadius() * .6f;

    String newName = "Dend_" + getOnlyDendriticSegments().size();

    Segment tempDend =
        addDendriticSegment(newRadius, newName, newPosition, parent, 1, newName + "_Sec", true);
    return tempDend;
  }
Ejemplo n.º 15
0
    @Override
    @SuppressWarnings("SleepWhileHoldingLock")
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum(doc.getLength());
        status.add(progress);
        status.revalidate();

        // start writing
        Writer out = new FileWriter(f);
        Segment text = new Segment();
        text.setPartialReturn(true);
        int charsLeft = doc.getLength();
        int offset = 0;
        while (charsLeft > 0) {
          doc.getText(offset, Math.min(4096, charsLeft), text);
          out.write(text.array, text.offset, text.count);
          charsLeft -= text.count;
          offset += text.count;
          progress.setValue(offset);
          try {
            Thread.sleep(10);
          } catch (InterruptedException e) {
            Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, e);
          }
        }
        out.flush();
        out.close();
      } catch (IOException e) {
        final String msg = e.getMessage();
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                JOptionPane.showMessageDialog(
                    getFrame(),
                    "Could not save file: " + msg,
                    "Error saving file",
                    JOptionPane.ERROR_MESSAGE);
              }
            });
      } catch (BadLocationException e) {
        System.err.println(e.getMessage());
      }
      // we are done... get rid of progressbar
      status.removeAll();
      status.revalidate();
    }
Ejemplo n.º 16
0
  /**
   * Compute dimension related information using slicing and redef info. In effect, this is where
   * projection constraints are applied
   *
   * <p>Assume that the constraint compiler has given us the following info:
   *
   * <ol>
   *   <li>A list of the variables to include.
   *   <li>A pair (DapDimension,Slice) for each redef
   *   <li>For each variable in #1, a list of slices taken from the constraint expression
   * </ol>
   *
   * <p>Two products will be produced.
   *
   * <ol>
   *   <li>The variables map will be modified so that the slices properly reflect any original or
   *       redef dimensions.
   *   <li>A set, dimrefs, of all referenced original dimensions.
   * </ol>
   *
   * <p>The processing is as follows
   *
   * <ol>
   *   <li>For each redef create a new redef dimension
   *   <li>For each variable:
   *       <ol>
   *         <li>if the variable is scalar, do nothing.
   *         <li>if the variable has no associated slices, then make its new dimensions be the
   *             original dimensions.
   *         <li>otherwise, walk the slices and create new dimensions from them; use redefs where
   *             indicated
   *         <li>
   *       </ol>
   * </ol>
   */
  protected void computedimensions() throws DapException {
    // Build the redefmap
    for (DapDimension key : redefslice.keySet()) {
      Slice slice = redefslice.get(key);
      DapDimension newdim = (DapDimension) key.clone();
      newdim.setSize(slice.getCount());
      redef.put(key, newdim);
    }

    // Process each variable
    for (int i = 0; i < segments.size(); i++) {
      Segment seg = segments.get(i);
      if (seg.var.getRank() == 0) continue;
      List<Slice> slices = seg.slices;
      List<DapDimension> orig = seg.var.getDimensions();
      List<DapDimension> newdims = new ArrayList<>();
      // If the slice list is short then pad it with
      // default slices
      if (slices == null) slices = new ArrayList<Slice>();
      while (slices.size() < orig.size()) // pad
      {
        slices.add(new Slice().setConstrained(false));
      }
      assert (slices != null && slices.size() == orig.size());
      for (int j = 0; j < slices.size(); j++) {
        Slice slice = slices.get(j);
        DapDimension dim0 = orig.get(j);
        DapDimension newdim = redef.get(dim0);
        if (newdim == null) newdim = dim0;
        // fill in the undefined last value
        slice.setMaxSize(newdim.getSize());
        slice.finish();

        Slice newslice = null;
        if (slice.isConstrained()) {
          // Construct an anonymous dimension for this slice
          newdim = new DapDimension(slice.getCount());
        } else { // replace with a new slice from the dim
          newslice = new Slice(newdim);
          if (newslice != null) {
            // track set of referenced non-anonymous dimensions
            if (!dimrefs.contains(dim0)) dimrefs.add(dim0);
            slices.set(j, newslice);
          }
        }
        // record the dimension per variable
        newdims.add(newdim);
      }
      seg.setDimset(newdims);
    }
  }
Ejemplo n.º 17
0
  @Override
  public void startTag(String name, Attributes atts, Stack<String> context) {
    if (name.equalsIgnoreCase(Constants.PERSONS_TAG)) {
      persons = new HashSet<>();

    } else if (name.equalsIgnoreCase(Constants.PERSON_TAG)) {
      person = factory.newPerson(getAttribute(Constants.ID_KEY, atts));

      for (int i = 0; i < atts.getLength(); i++) {
        String type = atts.getLocalName(i);
        if (!type.equalsIgnoreCase(Constants.ID_KEY)) {
          if (!blacklist.contains(type)) {
            person.setAttribute(type, getAttribute(type, atts));
          }
        }
      }

    } else if (name.equalsIgnoreCase(Constants.PLAN_TAG)) {
      plan = factory.newEpisode();

      for (int i = 0; i < atts.getLength(); i++) {
        String type = atts.getLocalName(i);

        if (!blacklist.contains(type)) {
          plan.setAttribute(type, getAttribute(type, atts));
        }
      }

    } else if (name.equalsIgnoreCase(Constants.ACTIVITY_TAG)) {
      Segment act = factory.newSegment();

      for (int i = 0; i < atts.getLength(); i++) {
        String type = atts.getLocalName(i);
        if (!blacklist.contains(type)) {
          act.setAttribute(type, getAttribute(type, atts));
        }
      }
      plan.addActivity(act);

    } else if (name.equalsIgnoreCase(Constants.LEG_TAG)) {
      Segment leg = factory.newSegment();

      for (int i = 0; i < atts.getLength(); i++) {
        String type = atts.getLocalName(i);
        if (!blacklist.contains(type)) {
          leg.setAttribute(type, getAttribute(type, atts));
        }
      }
      plan.addLeg(leg);
    }
  }
 private K nextSegmentKey() {
   while (segmentIndex >= 0) {
     Segment<K, V> segment = segments[segmentIndex];
     K key = segment.getNextKey(lastSegmentKey);
     if (key == null) {
       segmentIndex--;
       lastSegmentKey = null;
     } else {
       lastSegmentKey = key;
       return key;
     }
   }
   return null;
 }
 public static void main(String[] args) throws Exception {
   String sourceUrlString = "data/test.html";
   if (args.length == 0)
     System.err.println("Using default argument of \"" + sourceUrlString + '"');
   else sourceUrlString = args[0];
   if (sourceUrlString.indexOf(':') == -1) sourceUrlString = "file:" + sourceUrlString;
   StreamedSource streamedSource = new StreamedSource(new URL(sourceUrlString));
   // streamedSource.setBuffer(new char[65000]); // uncomment this to use a fixed buffer size
   Writer writer = null;
   try {
     writer =
         new OutputStreamWriter(
             new FileOutputStream("StreamedSourceCopyOutput.html"), streamedSource.getEncoding());
     System.out.println("Processing segments:");
     int lastSegmentEnd = 0;
     for (Segment segment : streamedSource) {
       System.out.println(segment.getDebugInfo());
       if (segment.getEnd() <= lastSegmentEnd)
         continue; // if this tag is inside the previous tag (e.g. a server tag) then ignore it as
                   // it was already output along with the previous tag.
       lastSegmentEnd = segment.getEnd();
       if (segment instanceof Tag) {
         Tag tag = (Tag) segment;
         // HANDLE TAG
         // Uncomment the following line to ensure each tag is valid XML:
         // writer.write(tag.tidy()); continue;
       } else if (segment instanceof CharacterReference) {
         CharacterReference characterReference = (CharacterReference) segment;
         // HANDLE CHARACTER REFERENCE
         // Uncomment the following line to decode all character references instead of copying them
         // verbatim:
         // characterReference.appendCharTo(writer); continue;
       } else {
         // HANDLE PLAIN TEXT
       }
       // unless specific handling has prevented getting to here, simply output the segment as is:
       writer.write(segment.toString());
     }
     writer.close();
     System.err.println(
         "\nA copy of the source document has been output to StreamedSourceCopyOuput.html");
   } catch (Exception ex) {
     if (writer != null)
       try {
         writer.close();
       } catch (IOException ex2) {
       }
     throw ex;
   }
 }
 private Entry<K, V> nextSegmentEntry() {
   while (segmentIndex >= 0) {
     Segment<K, V> segment = segments[segmentIndex];
     Entry<K, V> entry = segment.getNextEntry(lastSegmentKey);
     if (entry == null) {
       segmentIndex--;
       lastSegmentKey = null;
     } else {
       lastSegmentKey = entry.getKey();
       return entry;
     }
   }
   return null;
 }
Ejemplo n.º 21
0
  public DependentMetadata removeScoringDefinition(String scoringId, boolean validate) {
    Set<Segment> impactedSegments = getScoringDependentSegments(scoringId);
    Set<Scoring> impactedScorings = getScoringDependentScorings(scoringId);
    if (!validate || (impactedSegments.isEmpty() && impactedScorings.isEmpty())) {
      // update profiles
      updateExistingProfilesForRemovedScoring(scoringId);

      // update impacted segments
      for (Segment segment : impactedSegments) {
        Condition updatedCondition =
            updateScoringDependentCondition(segment.getCondition(), scoringId);
        segment.setCondition(updatedCondition);
        if (updatedCondition == null) {
          clearAutoGeneratedRules(
              persistenceService.query(
                  "linkedItems", segment.getMetadata().getId(), null, Rule.class),
              segment.getMetadata().getId());
          segment.getMetadata().setEnabled(false);
        }
        setSegmentDefinition(segment);
      }

      // update impacted scorings
      for (Scoring scoring : impactedScorings) {
        List<ScoringElement> updatedScoringElements = new ArrayList<>();
        for (ScoringElement scoringElement : scoring.getElements()) {
          Condition updatedCondition =
              updateScoringDependentCondition(scoringElement.getCondition(), scoringId);
          if (updatedCondition != null) {
            scoringElement.setCondition(updatedCondition);
            updatedScoringElements.add(scoringElement);
          }
        }
        scoring.setElements(updatedScoringElements);
        if (updatedScoringElements.isEmpty()) {
          clearAutoGeneratedRules(
              persistenceService.query(
                  "linkedItems", scoring.getMetadata().getId(), null, Rule.class),
              scoring.getMetadata().getId());
          scoring.getMetadata().setEnabled(false);
        }
        setScoringDefinition(scoring);
      }

      persistenceService.remove(scoringId, Scoring.class);
      List<Rule> previousRules =
          persistenceService.query("linkedItems", scoringId, null, Rule.class);
      clearAutoGeneratedRules(previousRules, scoringId);
    }

    List<Metadata> segments = new LinkedList<>();
    List<Metadata> scorings = new LinkedList<>();
    for (Segment definition : impactedSegments) {
      segments.add(definition.getMetadata());
    }
    for (Scoring definition : impactedScorings) {
      scorings.add(definition.getMetadata());
    }
    return new DependentMetadata(segments, scorings);
  }
 @Override
 public boolean replace(@NotNull K key, @NotNull V oldValue, @NotNull V newValue) {
   long h = hasher.hash(key);
   int segment = hasher.getSegment();
   Segment<K, V> segment2 = segments[segment];
   //noinspection SynchronizationOnLocalVariableOrMethodParameter
   synchronized (segment2) {
     V value2 = get(key);
     if (value2 != null && oldValue.equals(value2)) {
       segment2.put(h, key, newValue, true, true);
       return true;
     }
     return false;
   }
 }
 @Override
 public boolean remove(@NotNull Object key, Object value) {
   long h = hasher.hash(key);
   int segment = hasher.getSegment();
   Segment<K, V> segment2 = segments[segment];
   //noinspection SynchronizationOnLocalVariableOrMethodParameter
   synchronized (segment2) {
     V value2 = get(key);
     if (value2 != null && value.equals(value2)) {
       segment2.remove(h, (K) key);
       return true;
     }
     return false;
   }
 }
Ejemplo n.º 24
0
  protected String getField(
      Segment pSegment, int pFieldNum, boolean pMandatoryFl, String pErrorMessage) {
    DataElement de = null;
    String val = null;
    String err = null;

    try {
      de = pSegment.getDataElement(pFieldNum);
    } catch (Exception exc) {
      if (pMandatoryFl) {
        err = pErrorMessage + " (1)";
      }
    }
    if (err == null && de == null && pMandatoryFl) {
      err = pErrorMessage + " (2)";
    }
    if (err == null && de != null) {
      try {
        val = de.get();
      } catch (Exception exc) {
      }
      if (!Utility.isSet(val) && pMandatoryFl) {
        err = pErrorMessage + " (3)";
      }
    }
    if (err != null) {
      errorMsgs.add(err);
    }
    return val;
  }
Ejemplo n.º 25
0
 private void writeTextCollapseWhiteSpace(final int end, final int depth) throws IOException {
   // sets index to end
   // assert index < end
   boolean lastWasWhiteSpace = false;
   updateNextTag();
   while (index < end) {
     while (nextTag != null && index == nextTag.begin) {
       if (lastWasWhiteSpace) {
         writer.write(' ');
         lastWasWhiteSpace = false;
       }
       writeTag(nextTag, depth, end);
       if (index == end) return;
     }
     final char ch = sourceText.charAt(index++);
     if (Segment.isWhiteSpace(ch)) {
       lastWasWhiteSpace = true;
     } else {
       if (lastWasWhiteSpace) {
         writer.write(' ');
         lastWasWhiteSpace = false;
       }
       writer.write(ch);
     }
   }
   if (lastWasWhiteSpace) writer.write(' ');
 }
 private V nextSegmentValue() {
   while (segmentIndex >= 0) {
     Segment<K, V> segment = segments[segmentIndex];
     Map.Entry<K, V> entry =
         segment.getNextEntry(
             lastSegmentKey); // todo: not the most efficient to work through Entries...
     if (entry == null) {
       segmentIndex--;
       lastSegmentKey = null;
     } else {
       lastSegmentKey = entry.getKey();
       return entry.getValue();
     }
   }
   return null;
 }
Ejemplo n.º 27
0
 public void writeTo(final Writer writer) throws IOException {
   this.writer = writer;
   if (segment instanceof Source) ((Source) segment).fullSequentialParse();
   nextTag = segment.source.findNextTag(segment.begin);
   index = segment.begin;
   writeContent(segment.end, segment.getChildElements(), 0);
   writer.flush();
 }
  private void validateRegions() {
    if (region_map == null) return;

    synchronized (region_map) {
      if (regions_valid) return;

      Segment s = new Segment();

      region_map.clear();

      for (BaleRegion br : fragment_regions) {
        RegionData rd = new RegionData(indent_size);
        region_map.put(br, rd);
        int soff = br.getStart();
        int eoff = br.getEnd();
        if (eoff < soff) continue;
        try {
          base_document.getText(soff, eoff - soff, s);
        } catch (BadLocationException e) {
          BoardLog.logE("BALE", "Problem getting region indentation", e);
          continue;
        }
        int ln = s.length();

        LineData ld;
        boolean sol = true;
        for (int i = 0; i < ln; ++i) {
          char c = s.charAt(i);
          if (sol) {
            ld = computeLineData(i, s);
            rd.add(ld);
            sol = false;
          }
          if (c == '\n') sol = true;
        }
        if (!sol) {
          ld = computeLineData(ln, s);
          rd.add(ld);
          ++ln;
        }
      }

      regions_valid = true;
    }
  }
  public static void renameNonCodeUsages(
      @NotNull Project project, @NotNull NonCodeUsageInfo[] usages) {
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    Map<Document, List<UsageOffset>> docsToOffsetsMap = new HashMap<Document, List<UsageOffset>>();
    final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
    for (NonCodeUsageInfo usage : usages) {
      PsiElement element = usage.getElement();

      if (element == null) continue;
      element = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(element, true);
      if (element == null) continue;

      final ProperTextRange rangeInElement = usage.getRangeInElement();
      if (rangeInElement == null) continue;

      final PsiFile containingFile = element.getContainingFile();
      final Document document = psiDocumentManager.getDocument(containingFile);

      final Segment segment = usage.getSegment();
      LOG.assertTrue(segment != null);
      int fileOffset = segment.getStartOffset();

      List<UsageOffset> list = docsToOffsetsMap.get(document);
      if (list == null) {
        list = new ArrayList<UsageOffset>();
        docsToOffsetsMap.put(document, list);
      }

      list.add(new UsageOffset(fileOffset, fileOffset + rangeInElement.getLength(), usage.newText));
    }

    for (Document document : docsToOffsetsMap.keySet()) {
      List<UsageOffset> list = docsToOffsetsMap.get(document);
      LOG.assertTrue(list != null, document);
      UsageOffset[] offsets = list.toArray(new UsageOffset[list.size()]);
      Arrays.sort(offsets);

      for (int i = offsets.length - 1; i >= 0; i--) {
        UsageOffset usageOffset = offsets[i];
        document.replaceString(usageOffset.startOffset, usageOffset.endOffset, usageOffset.newText);
      }
      PsiDocumentManager.getInstance(project).commitDocument(document);
    }
    PsiDocumentManager.getInstance(project).commitAllDocuments();
  }
Ejemplo n.º 30
0
  private Segment addRelativeAxon(Segment parent, Point3f relPosition, float radius) {
    Point3f newPosition = (new Point3f(parent.getEndPointPosition()));
    newPosition.add(relPosition);

    String newName = "Axon_" + getOnlyAxonalSegments().size();

    Segment tempAxon = addAxonalSegment(radius, newName, newPosition, parent, 1, newName + "_Sec");
    return tempAxon;
  }