コード例 #1
0
 /**
  * Get the list of ids of sequences in this sequence database
  *
  * @return the list of sequence ids.
  */
 public Set<Integer> getSequenceIDs() {
   Set<Integer> set = new HashSet<Integer>();
   for (Sequence sequence : getSequences()) {
     set.add(sequence.getId());
   }
   return set;
 }
コード例 #2
0
 public Object getNextValue(Sequence sequence, AbstractSession writeSession) {
   String seqName = sequence.getName();
   if (sequence.getPreallocationSize() > 1) {
     Queue sequencesForName = getPreallocationHandler().getPreallocated(seqName);
     // First try to get the next sequence value without locking.
     Object sequenceValue = sequencesForName.poll();
     if (sequenceValue != null) {
       return sequenceValue;
     }
     // Sequences are empty, so must lock and allocate next batch of sequences.
     acquireLock(seqName);
     try {
       sequenceValue = sequencesForName.poll();
       if (sequenceValue != null) {
         return sequenceValue;
       }
       Vector sequences = sequence.getGeneratedVector(null, writeSession);
       // Remove the first value before adding to the global cache to ensure this thread gets
       // one.
       sequenceValue = sequences.remove(0);
       // copy remaining values to global cache.
       getPreallocationHandler().setPreallocated(seqName, sequences);
       logDebugPreallocation(seqName, sequenceValue, sequences);
     } finally {
       releaseLock(seqName);
     }
     return sequenceValue;
   } else {
     // preallocation size is 1 - just return the first (and only) element of the allocated
     // vector.
     return sequence.getGeneratedVector(null, writeSession).firstElement();
   }
 }
コード例 #3
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
    @Override
    public String getAccessibleName() {
      String name = super.getAccessibleName();

      if (seqs.size() > 0 && seqs.get(0).size > 0) {
        String keyValueList = "";
        for (Sequence seq : seqs) {
          if (seq.isPlotted) {
            String value = "null";
            if (seq.size > 0) {
              if (unit == Unit.BYTES) {
                value = Resources.format(Messages.SIZE_BYTES, seq.value(seq.size - 1));
              } else {
                value =
                    getFormattedValue(seq.value(seq.size - 1), false)
                        + ((unit == Unit.PERCENT) ? "%" : "");
              }
            }
            // Assume format string ends with newline
            keyValueList +=
                Resources.format(Messages.PLOTTER_ACCESSIBLE_NAME_KEY_AND_VALUE, seq.key, value);
          }
        }
        name += "\n" + keyValueList + ".";
      } else {
        name += "\n" + Messages.PLOTTER_ACCESSIBLE_NAME_NO_DATA;
      }
      return name;
    }
コード例 #4
0
ファイル: Sequence.java プロジェクト: semitie/wyvern
  /**
   * A filter for the sequence </br> Combines the sequential type and method declarations into a
   * block </br>
   *
   * @return return the sequence after combination.
   */
  private Sequence combine() {
    boolean recBlock = false;
    Sequence normalSeq = new Sequence();
    Sequence recSequence = new DeclSequence();
    for (TypedAST ast : this.getIterator()) {

      if (ast instanceof TypeVarDecl
          || ast instanceof DefDeclaration
          || ast instanceof TypeAbbrevDeclaration) {
        Declaration d = (Declaration) ast;
        if (recBlock == false) {
          recBlock = true;
          recSequence = new DeclSequence();
        }
        recSequence = Sequence.append(recSequence, d);
      } else {
        if (recBlock == true) {
          normalSeq = Sequence.append(normalSeq, recSequence);
        }
        normalSeq = Sequence.append(normalSeq, ast);
        recBlock = false;
      }
    }

    if (recBlock == true) {
      normalSeq = Sequence.append(normalSeq, recSequence);
    }
    return normalSeq;
  }
コード例 #5
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
  public void createSequence(String key, String name, Color color, boolean isPlotted) {
    Sequence seq = getSequence(key);
    if (seq == null) {
      seq = new Sequence(key);
    }
    seq.name = name;
    seq.color = (color != null) ? color : defaultColor;
    seq.isPlotted = isPlotted;

    seqs.add(seq);
  }
コード例 #6
0
 /**
  * Get a string representation of this sequence database
  *
  * @return the string representation
  */
 @Override
 public String toString() {
   StringBuilder r = new StringBuilder();
   for (Sequence sequence : sequences) {
     r.append(sequence.getId());
     r.append(":  ");
     r.append(sequence.toString());
     r.append('\n');
   }
   return r.toString();
 }
コード例 #7
0
  protected void initializeStates() {
    states = new State[NUMBER_OF_STATES];

    Iterator itConnectedSequences = connectedSequences.iterator();
    while (itConnectedSequences.hasNext()) {
      Sequence sequence = (Sequence) itConnectedSequences.next();
      State state = getState(sequence.shouldUsePreallocation(), sequence.shouldUseTransaction());
      if (state == null) {
        createState(sequence.shouldUsePreallocation(), sequence.shouldUseTransaction());
      }
    }
  }
コード例 #8
0
ファイル: Sequence.java プロジェクト: NCIP/cacore-sdk-docs
  public boolean equals(Object obj) {
    boolean eq = false;
    if (obj instanceof Sequence) {
      Sequence c = (Sequence) obj;
      Long thisId = getId();

      if (thisId != null && thisId.equals(c.getId())) {
        eq = true;
      }
    }
    return eq;
  }
コード例 #9
0
ファイル: BaseSequence.java プロジェクト: gaurav/taxondna
 public static Sequence promoteSequence(Sequence x) {
   if (BaseSequence.class.isAssignableFrom(x.getClass())) {
     try {
       return new Sequence(x.getFullName(), x.getSequence());
     } catch (SequenceException e) {
       return x;
     }
   } else
     // if it's not a BaseSequence, there isn't anything
     // to 'promote' to! (yet)
     return x;
 }
コード例 #10
0
ファイル: Sequence.java プロジェクト: semitie/wyvern
  /**
   * Generate IL expression for a top-level declaration sequence</br>
   *
   * @see GenUtil.doGenModuleIL
   * @param ctx the context
   * @param isModule whether is is actually a module expression: true for the body of a module,
   *     false for the body of a script
   * @return the IL expression of a module
   */
  public Expression generateModuleIL(GenContext ctx, boolean isModule) {
    Sequence seqWithBlocks = combine();

    TopLevelContext tlc = new TopLevelContext(ctx);
    seqWithBlocks.genTopLevel(tlc);
    Expression result = isModule ? tlc.getModuleExpression() : tlc.getExpression();

    /*Iterator<TypedAST> ai = seqWithBlocks.iterator();

    if (!ai.hasNext())
    	throw new RuntimeException("expected an expression in the list");

    Expression decl =  GenUtil.doGenModuleIL(ctx, ctx, ctx, ai, isModule);*/
    return result;
  }
コード例 #11
0
ファイル: Sequence.java プロジェクト: semitie/wyvern
  public static Sequence append(Sequence s, TypedAST e) {
    Iterator<TypedAST> innerIter = s.iterator();
    if (s instanceof DeclSequence && e instanceof Declaration) {
      return DeclSequence.simplify(new DeclSequence(s, e));
    }
    return new Sequence(
        () ->
            new Iterator<TypedAST>() {
              private boolean fetched = false;

              @Override
              public boolean hasNext() {
                if (innerIter.hasNext()) return true;
                return !fetched;
              }

              @Override
              public TypedAST next() {
                if (innerIter.hasNext()) return innerIter.next();
                if (!fetched) {
                  fetched = true;
                  return e;
                }
                throw new RuntimeException();
              }
            });
  }
コード例 #12
0
 protected void logDebugSequencingConnected() {
   Vector[] sequenceVectors = new Vector[NUMBER_OF_STATES];
   Iterator itConnectedSequences = connectedSequences.iterator();
   while (itConnectedSequences.hasNext()) {
     Sequence sequence = (Sequence) itConnectedSequences.next();
     int stateId = getStateId(sequence.shouldUsePreallocation(), sequence.shouldUseTransaction());
     Vector v = sequenceVectors[stateId];
     if (v == null) {
       v = new Vector();
       sequenceVectors[stateId] = v;
     }
     v.addElement(sequence);
   }
   for (int i = 0; i < NUMBER_OF_STATES; i++) {
     Vector v = sequenceVectors[i];
     if (v != null) {
       getOwnerSession()
           .log(SessionLog.FINEST, SessionLog.SEQUENCING, "sequencing_connected", states[i]);
       for (int j = 0; j < v.size(); j++) {
         Sequence sequence = (Sequence) v.elementAt(j);
         Object[] args = {
           sequence.getName(),
           Integer.toString(sequence.getPreallocationSize()),
           Integer.toString(sequence.getInitialValue())
         };
         getOwnerSession()
             .log(SessionLog.FINEST, SessionLog.SEQUENCING, "sequence_without_state", args);
       }
     }
   }
 }
コード例 #13
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
  // Called on EDT
  public void propertyChange(PropertyChangeEvent ev) {
    String prop = ev.getPropertyName();

    if (prop == JConsoleContext.CONNECTION_STATE_PROPERTY) {
      ConnectionState newState = (ConnectionState) ev.getNewValue();

      switch (newState) {
        case DISCONNECTED:
          synchronized (this) {
            long time = System.currentTimeMillis();
            times.add(time);
            for (Sequence seq : seqs) {
              seq.add(Long.MIN_VALUE);
            }
          }
          break;
      }
    }
  }
コード例 #14
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
  private void saveDataToFile(File file) {
    try {
      PrintStream out = new PrintStream(new FileOutputStream(file));

      // Print header line
      out.print("Time");
      for (Sequence seq : seqs) {
        out.print("," + seq.name);
      }
      out.println();

      // Print data lines
      if (seqs.size() > 0 && seqs.get(0).size > 0) {
        for (int i = 0; i < seqs.get(0).size; i++) {
          double excelTime = toExcelTime(times.time(i));
          out.print(String.format(Locale.ENGLISH, "%.6f", excelTime));
          for (Sequence seq : seqs) {
            out.print("," + getFormattedValue(seq.value(i), false));
          }
          out.println();
        }
      }

      out.close();
      JOptionPane.showMessageDialog(
          this,
          Resources.format(
              Messages.FILE_CHOOSER_SAVED_FILE, file.getAbsolutePath(), file.length()));
    } catch (IOException ex) {
      String msg = ex.getLocalizedMessage();
      String path = file.getAbsolutePath();
      if (msg.startsWith(path)) {
        msg = msg.substring(path.length()).trim();
      }
      JOptionPane.showMessageDialog(
          this,
          Resources.format(Messages.FILE_CHOOSER_SAVE_FAILED_MESSAGE, path, msg),
          Messages.FILE_CHOOSER_SAVE_FAILED_TITLE,
          JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #15
0
  protected void onDisconnectAllSequences() {
    RuntimeException exception = null;

    // defaultSequence has to disconnect the last
    for (int i = connectedSequences.size() - 1; i >= 0; i--) {
      try {
        Sequence sequenceToDisconnect = (Sequence) connectedSequences.elementAt(i);
        sequenceToDisconnect.onDisconnect(getOwnerSession().getDatasourcePlatform());
      } catch (RuntimeException ex) {
        if (exception == null) {
          exception = ex;
        }
      }
    }
    connectedSequences = null;
    whenShouldAcquireValueForAll = UNDEFINED;
    atLeastOneSequenceShouldUseTransaction = false;
    atLeastOneSequenceShouldUsePreallocation = false;
    if (exception != null) {
      throw exception;
    }
  }
コード例 #16
0
  /**
   * It adds a sequence from an array of string that we have to interpret
   *
   * @param integers
   * @param sequenceID
   */
  public void addSequence(String[] integers, int sequenceID) {
    long timestamp = -1;
    Sequence sequence = new Sequence(sequences.size());
    sequence.setID(sequenceID);
    Itemset itemset = new Itemset();
    int inicio = 0;
    Map<Item, Boolean> counted = new HashMap<Item, Boolean>();

    for (int i = inicio; i < integers.length; i++) {
      if (integers[i].codePointAt(0) == '<') { // Timestamp
        String value = integers[i].substring(1, integers[i].length() - 1);
        timestamp = Long.parseLong(value);
        itemset.setTimestamp(timestamp);
      } else if (integers[i].equals("-1")) { // end of an itemset
        long time = itemset.getTimestamp() + 1;
        sequence.addItemset(itemset);
        itemset = new Itemset();
        itemset.setTimestamp(time);
      } else if (integers[i].equals("-2")) { // end of a sequence
        sequences.add(sequence);
      } else {
        // extract the value for an item
        Item item = itemFactory.getItem(Integer.parseInt(integers[i]));
        if (counted.get(item) == null) {
          counted.put(item, Boolean.TRUE);
          BitSet appearances = frequentItems.get(item);
          if (appearances == null) {
            appearances = new BitSet();
            frequentItems.put(item, appearances);
          }
          appearances.set(sequence.getId());
        }
        itemset.addItem(item);
      }
    }
  }
コード例 #17
0
 public Object getNextValue(AbstractSession writeSession, Class cls) {
   Sequence sequence = getSequence(cls);
   State state = getState(sequence.shouldUsePreallocation(), sequence.shouldUseTransaction());
   return state.getNextValue(sequence, writeSession);
 }
コード例 #18
0
  public void drawSequence(
      Graphics2D g,
      Sequence seq,
      int start,
      int end,
      int x1,
      int y1,
      double width,
      int height,
      boolean showScores,
      boolean displayBoxes,
      boolean displayText,
      Vector pid,
      int seqnum,
      AlignViewport av,
      Hashtable props,
      int intpid[][]) {
    LinkedHashMap conf = av.getGFFConfig();
    boolean confchanged = false;
    int length = seq.getLength();

    Color currentColor = Color.white;

    g.setColor(Color.black);

    int prevx = -1;
    int prevy = -1;

    int prevpixel = 0;

    if (!(seq instanceof GFF)) {
      return;
    }
    height -= 2;

    GFF gff = (GFF) seq;

    double minscore = gff.getMinScore();
    double maxscore = gff.getMaxScore();

    minscore = (int) (minscore - (maxscore - minscore + 1) * 0.1);
    maxscore = (int) (maxscore + (maxscore - minscore + 1) * 0.1);

    if (gff.getType().equals("Patient_Flow")) {
      minscore = 1600;
    }
    // System.out.println("Min/Max " + minscore + " " + maxscore);
    Vector feat = gff.overlaps(start, end);

    // System.out.println("Got features " + feat.size());

    int prev = -1;
    for (int i = 0; i < feat.size(); i++) {

      SequenceFeature sftmp = (SequenceFeature) feat.elementAt(i);

      int coord = sftmp.getStart();

      if (coord >= minscore) {
        Color c = Color.black;

        String key = sftmp.getType();
        if (key.indexOf("::") > 0) {
          key = key.substring(0, key.indexOf("::"));
          sftmp.setType(key);
        }
        if (conf != null && conf.containsKey(sftmp.getType())) {
          c = (Color) (conf.get(sftmp.getType()));
          g.setColor(c);
        } else {

          // c = new
          // Color((int)(Math.random()*200+50),(int)(Math.random()*200+50),(int)(Math.random()*200+50));
          c = Color.black;
          conf.put(sftmp.getType(), c);
          g.setColor(c);
          confchanged = true;
        }

        Vector tmpf = new Vector();

        if (sftmp.getFeatures() != null) {
          tmpf = sftmp.getFeatures();
        } else {
          tmpf.addElement(sftmp);
        }

        int tmpheight = height;
        double score = sftmp.getScore();

        tmpheight = (int) ((score - minscore + 1) * (height) / (maxscore - minscore + 1));

        int tmpx = x1 + (int) ((coord - start) * width) + 1;
        int tmpy = y1 + height - tmpheight + 1;

        if (prevx == -1) {
          prevx = tmpx;
          prevy = tmpy;
        }

        if (tmpx - prevx <= 2) {
          g.drawLine(prevx, prevy, tmpx, tmpy);
        }

        prevx = tmpx;
        prevy = tmpy;
      }
      i++;
    }
  }
コード例 #19
0
 public static PreparedStatement prepareStatement(Connection cxn) throws SQLException {
   String insert = "INSERT INTO probe_platform (id, name, type) VALUES (%s, ?, ?)";
   insert = String.format(insert, Sequence.getInsertSQL(cxn, "probe_platform_id"));
   return cxn.prepareStatement(insert);
 }
コード例 #20
0
ファイル: QueryService.java プロジェクト: GerritBoers/exist
 ItemList executeQuery(String query, WrapperFactory wrapperFactory, Object[] params) {
   long t1 = System.currentTimeMillis(), t2 = 0, t3 = 0, t4 = 0;
   if (presub) query = presub(query, params);
   DBBroker broker = null;
   try {
     broker = db.acquireBroker();
     prepareContext(broker);
     if (overrideDocs != null) docs = overrideDocs;
     final org.exist.source.Source source = buildQuerySource(query, params, "execute");
     final XQuery xquery = broker.getXQueryService();
     final XQueryPool pool = xquery.getXQueryPool();
     CompiledXQuery compiledQuery = pool.borrowCompiledXQuery(broker, source);
     MutableDocumentSet docsToLock = new DefaultDocumentSet();
     if (docs != null) docsToLock.addAll(docs);
     if (base != null) docsToLock.addAll(base.getDocumentSet());
     try {
       XQueryContext context;
       if (compiledQuery == null) {
         context = xquery.newContext(AccessContext.INTERNAL_PREFIX_LOOKUP);
         buildXQueryStaticContext(context, true);
       } else {
         context = compiledQuery.getContext();
         // static context already set
       }
       buildXQueryDynamicContext(context, params, docsToLock, true);
       t2 = System.currentTimeMillis();
       if (compiledQuery == null) {
         compiledQuery = xquery.compile(context, source);
         t3 = System.currentTimeMillis();
       }
       docsToLock.lock(broker, false, false);
       try {
         return new ItemList(
             xquery.execute(wrap(compiledQuery, wrapperFactory, context), base),
             namespaceBindings.extend(),
             db);
       } finally {
         docsToLock.unlock(false);
         t4 = System.currentTimeMillis();
       }
     } finally {
       if (compiledQuery != null) pool.returnCompiledXQuery(source, compiledQuery);
     }
   } catch (XPathException e) {
     LOG.debug(
         "query execution failed --  "
             + query
             + "  -- "
             + (params == null ? "" : " with params " + Arrays.asList(params))
             + (bindings.isEmpty() ? "" : " and bindings " + bindings));
     throw new DatabaseException("failed to execute query", e);
   } catch (IOException e) {
     throw new DatabaseException("unexpected exception", e);
   } catch (LockException e) {
     throw new DatabaseException("deadlock", e);
   } catch (PermissionDeniedException e) {
     throw new DatabaseException("permission denied", e);
   } finally {
     db.releaseBroker(broker);
     STATS.update(query, t1, t2, t3, t4, System.currentTimeMillis());
   }
 }
コード例 #21
0
 public Object getNextValue(Sequence sequence, AbstractSession writeSession) {
   return sequence.getGeneratedValue(null, writeSession);
 }
コード例 #22
0
ファイル: SequenceHandler.java プロジェクト: rnugraha/dazzle
  private void dnaCommand(HttpServletRequest req, DazzleResponse resp, DazzleDataSource dds)
      throws IOException, DataSourceException, ServletException, DazzleException {

    DazzleReferenceSource drs = (DazzleReferenceSource) dds;

    List segments = DazzleTools.getSegments(dds, req, resp);
    if (segments.size() == 0) {
      throw new DazzleException(
          DASStatus.STATUS_BAD_COMMAND_ARGUMENTS, "No segments specified for dna command");
    }

    // Fetch and validate the requests.

    Map segmentResults = new HashMap();
    for (Iterator i = segments.iterator(); i.hasNext(); ) {
      Segment seg = (Segment) i.next();

      try {
        Sequence seq = drs.getSequence(seg.getReference());
        if (seq.getAlphabet() != DNATools.getDNA()) {
          throw new DazzleException(
              DASStatus.STATUS_SERVER_ERROR,
              "Sequence " + seg.toString() + " is not in the DNA alphabet");
        }
        if (seg.isBounded()) {
          if (seg.getMin() < 1 || seg.getMax() > seq.length()) {
            throw new DazzleException(
                DASStatus.STATUS_BAD_COORDS,
                "Segment " + seg.toString() + " doesn't fit sequence of length " + seq.length());
          }
        }
        segmentResults.put(seg, seq);
      } catch (NoSuchElementException ex) {
        throw new DazzleException(DASStatus.STATUS_BAD_REFERENCE, ex);
      } catch (DataSourceException ex) {
        throw new DazzleException(DASStatus.STATUS_SERVER_ERROR, ex);
      }
    }

    //
    // Looks okay -- generate the response document
    //

    XMLWriter xw = resp.startDasXML("DASDNA", "dasdna.dtd");

    try {
      xw.openTag("DASDNA");
      for (Iterator i = segmentResults.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry me = (Map.Entry) i.next();
        Segment seg = (Segment) me.getKey();
        Sequence seq = (Sequence) me.getValue();

        xw.openTag("SEQUENCE");
        xw.attribute("id", seg.getReference());
        xw.attribute("version", drs.getLandmarkVersion(seg.getReference()));
        if (seg.isBounded()) {
          xw.attribute("start", "" + seg.getStart());
          xw.attribute("stop", "" + seg.getStop());
        } else {
          xw.attribute("start", "" + 1);
          xw.attribute("stop", "" + seq.length());
        }

        SymbolList syms = seq;
        if (seg.isBounded()) {
          syms = syms.subList(seg.getMin(), seg.getMax());
        }
        if (seg.isInverted()) {
          syms = DNATools.reverseComplement(syms);
        }

        xw.openTag("DNA");
        xw.attribute("length", "" + syms.length());

        for (int pos = 1; pos <= syms.length(); pos += 60) {
          int maxPos = Math.min(syms.length(), pos + 59);
          xw.println(syms.subStr(pos, maxPos));
        }

        xw.closeTag("DNA");
        xw.closeTag("SEQUENCE");
      }
      xw.closeTag("DASDNA");
      xw.close();
    } catch (Exception ex) {
      throw new DazzleException(ex, "Error writing DNA document");
    }
  }
コード例 #23
0
ファイル: InputProcessor.java プロジェクト: kazschuri/LogThis
  /**
   * @param scene the scene to filter
   * @param filter the filter to use
   * @param containsFilter true to exclusively use the arguments or false to exclude filter
   *     arguments
   * @return the filteredSequence
   */
  public static Scene filterScene(Scene scene, String[] filter, boolean containsFilter) {

    Sequence[] originalSequences = scene.getSequences();
    List<Sequence> sequenceList = new ArrayList<Sequence>();
    List<Sequence> aggregatedList = new ArrayList<Sequence>();

    for (int i = 0; i < originalSequences.length; i++) {

      Sequence tmpSequence = originalSequences[i].filterSequence(filter, containsFilter);
      sequenceList.add(tmpSequence);
    }

    if (originalSequences.length != sequenceList.size()) {

      System.out.println("ALARM Ungleiche Größe!");
    }
    //		aggregatedList = sequenceList;

    Sequence tmpBaseSequence = sequenceList.get(0);

    for (int i = 1; i < sequenceList.size(); i++) {

      if (tmpBaseSequence.equalTo(sequenceList.get(i))) {

        tmpBaseSequence.setLastTimestamp(sequenceList.get(i).getLastTimestamp());
        tmpBaseSequence.setNumberOfFrames(
            tmpBaseSequence.getNumberOfFrames() + sequenceList.get(i).getNumberOfFrames());

        if (sequenceList.get(i).getConcatenatedTypeNames().length != 0) {

          String[] tmpTypes = sequenceList.get(i).getConcatenatedTypeNames();

          for (int j = 0; j < tmpTypes.length; j++) {

            // increase age from previousSequence by numberOfFrames
            tmpBaseSequence.setElementOfTypeToAgeMap(
                tmpTypes[j],
                sequenceList.get(i).getNumberOfFrames()
                    + tmpBaseSequence.getElementOfTypeToAgeMap(tmpTypes[j]));
          }
        }

      } else {

        aggregatedList.add(tmpBaseSequence);
        tmpBaseSequence = sequenceList.get(i);
      }
    }

    aggregatedList.add(tmpBaseSequence);

    /*
     * added a final sequence to set all types to dying
     */
    Sequence nextToLastSeq = aggregatedList.get(aggregatedList.size() - 1);
    Sequence lastSequence = new Sequence();
    lastSequence.setDyingTypes(nextToLastSeq.getConcatenatedTypeNames());
    lastSequence.setFirstTimestamp(nextToLastSeq.getFirstTimestamp());
    lastSequence.setLastTimestamp(nextToLastSeq.getLastTimestamp());
    lastSequence.setNumberOfFrames(1);
    lastSequence.setTypeToAgeMap(nextToLastSeq.getTypeToAgeMap());

    aggregatedList.add(lastSequence);

    Sequence[] filteredSequences = new Sequence[aggregatedList.size()];
    filteredSequences = aggregatedList.toArray(filteredSequences);

    Scene filteredScene =
        new Scene(
            filteredSequences, scene.getNumberOfFrames(), scene.getStartTime(), scene.getEndTime());

    return filteredScene;
  }
コード例 #24
0
ファイル: EntryController.java プロジェクト: chimaerase/ice
  protected PartData retrieveEntryDetails(String userId, Entry entry) {
    // user must be able to read if not public entry
    if (!permissionsController.isPubliclyVisible(entry)) authorization.expectRead(userId, entry);

    PartData partData = ModelToInfoFactory.getInfo(entry);
    if (partData == null) return null;
    boolean hasSequence = sequenceDAO.hasSequence(entry.getId());

    partData.setHasSequence(hasSequence);
    boolean hasOriginalSequence = sequenceDAO.hasOriginalSequence(entry.getId());
    partData.setHasOriginalSequence(hasOriginalSequence);

    // permissions
    partData.setCanEdit(authorization.canWriteThoroughCheck(userId, entry));
    partData.setPublicRead(permissionsController.isPubliclyVisible(entry));

    // create audit event if not owner
    // todo : remote access check
    if (userId != null
        && authorization.getOwner(entry) != null
        && !authorization.getOwner(entry).equalsIgnoreCase(userId)) {
      try {
        Audit audit = new Audit();
        audit.setAction(AuditType.READ.getAbbrev());
        audit.setEntry(entry);
        audit.setUserId(userId);
        audit.setLocalUser(true);
        audit.setTime(new Date(System.currentTimeMillis()));
        auditDAO.create(audit);
      } catch (Exception e) {
        Logger.error(e);
      }
    }

    // retrieve more information about linked entries if any (default only contains id)
    if (partData.getLinkedParts() != null) {
      ArrayList<PartData> newLinks = new ArrayList<>();
      for (PartData link : partData.getLinkedParts()) {
        Entry linkedEntry = dao.get(link.getId());
        if (!authorization.canRead(userId, linkedEntry)) continue;

        link = ModelToInfoFactory.createTipView(linkedEntry);
        Sequence sequence = sequenceDAO.getByEntry(linkedEntry);
        if (sequence != null) {
          link.setBasePairCount(sequence.getSequence().length());
          link.setFeatureCount(sequence.getSequenceFeatures().size());
        }

        newLinks.add(link);
      }
      partData.getLinkedParts().clear();
      partData.getLinkedParts().addAll(newLinks);
    }

    // check if there is a parent available
    List<Entry> parents = dao.getParents(entry.getId());
    if (parents == null) return partData;

    for (Entry parent : parents) {
      if (!authorization.canRead(userId, parent)) continue;

      if (parent.getVisibility() != Visibility.OK.getValue()
          && !authorization.canWriteThoroughCheck(userId, entry)) continue;

      EntryType type = EntryType.nameToType(parent.getRecordType());
      PartData parentData = new PartData(type);
      parentData.setId(parent.getId());
      parentData.setName(parent.getName());
      parentData.setVisibility(Visibility.valueToEnum(parent.getVisibility()));
      partData.getParents().add(parentData);
    }

    return partData;
  }
コード例 #25
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
 long getLastValue(String key) {
   Sequence seq = getSequence(key);
   return (seq != null && seq.size > 0) ? seq.value(seq.size - 1) : 0L;
 }
コード例 #26
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int width = getWidth() - rightMargin - leftMargin - 10;
    int height = getHeight() - topMargin - bottomMargin;
    if (width <= 0 || height <= 0) {
      // not enough room to paint anything
      return;
    }

    Color oldColor = g.getColor();
    Font oldFont = g.getFont();
    Color fg = getForeground();
    Color bg = getBackground();
    boolean bgIsLight = (bg.getRed() > 200 && bg.getGreen() > 200 && bg.getBlue() > 200);

    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    if (smallFont == null) {
      smallFont = oldFont.deriveFont(9.0F);
    }

    r.x = leftMargin - 5;
    r.y = topMargin - 8;
    r.width = getWidth() - leftMargin - rightMargin;
    r.height = getHeight() - topMargin - bottomMargin + 16;

    if (border == null) {
      // By setting colors here, we avoid recalculating them
      // over and over.
      border =
          new BevelBorder(
              BevelBorder.LOWERED,
              getBackground().brighter().brighter(),
              getBackground().brighter(),
              getBackground().darker().darker(),
              getBackground().darker());
    }

    border.paintBorder(this, g, r.x, r.y, r.width, r.height);

    // Fill background color
    g.setColor(bgColor);
    g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4);
    g.setColor(oldColor);

    long tMin = Long.MAX_VALUE;
    long tMax = Long.MIN_VALUE;
    long vMin = Long.MAX_VALUE;
    long vMax = 1;

    int w = getWidth() - rightMargin - leftMargin - 10;
    int h = getHeight() - topMargin - bottomMargin;

    if (times.size > 1) {
      tMin = Math.min(tMin, times.time(0));
      tMax = Math.max(tMax, times.time(times.size - 1));
    }
    long viewRangeMS;
    if (viewRange > 0) {
      viewRangeMS = viewRange * MINUTE;
    } else {
      // Display full time range, but no less than a minute
      viewRangeMS = Math.max(tMax - tMin, 1 * MINUTE);
    }

    // Calculate min/max values
    for (Sequence seq : seqs) {
      if (seq.size > 0) {
        for (int i = 0; i < seq.size; i++) {
          if (seq.size == 1 || times.time(i) >= tMax - viewRangeMS) {
            long val = seq.value(i);
            if (val > Long.MIN_VALUE) {
              vMax = Math.max(vMax, val);
              vMin = Math.min(vMin, val);
            }
          }
        }
      } else {
        vMin = 0L;
      }
      if (unit == Unit.BYTES || !seq.isPlotted) {
        // We'll scale only to the first (main) value set.
        // TODO: Use a separate property for this.
        break;
      }
    }

    // Normalize scale
    vMax = normalizeMax(vMax);
    if (vMin > 0) {
      if (vMax / vMin > 4) {
        vMin = 0;
      } else {
        vMin = normalizeMin(vMin);
      }
    }

    g.setColor(fg);

    // Axes
    // Draw vertical axis
    int x = leftMargin - 18;
    int y = topMargin;
    FontMetrics fm = g.getFontMetrics();

    g.drawLine(x, y, x, y + h);

    int n = 5;
    if (("" + vMax).startsWith("2")) {
      n = 4;
    } else if (("" + vMax).startsWith("3")) {
      n = 6;
    } else if (("" + vMax).startsWith("4")) {
      n = 4;
    } else if (("" + vMax).startsWith("6")) {
      n = 6;
    } else if (("" + vMax).startsWith("7")) {
      n = 7;
    } else if (("" + vMax).startsWith("8")) {
      n = 8;
    } else if (("" + vMax).startsWith("9")) {
      n = 3;
    }

    // Ticks
    ArrayList<Long> tickValues = new ArrayList<Long>();
    tickValues.add(vMin);
    for (int i = 0; i < n; i++) {
      long v = i * vMax / n;
      if (v > vMin) {
        tickValues.add(v);
      }
    }
    tickValues.add(vMax);
    n = tickValues.size();

    String[] tickStrings = new String[n];
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      tickStrings[i] = getSizeString(v, vMax);
    }

    // Trim trailing decimal zeroes.
    if (decimals > 0) {
      boolean trimLast = true;
      boolean removedDecimalPoint = false;
      do {
        for (String str : tickStrings) {
          if (!(str.endsWith("0") || str.endsWith("."))) {
            trimLast = false;
            break;
          }
        }
        if (trimLast) {
          if (tickStrings[0].endsWith(".")) {
            removedDecimalPoint = true;
          }
          for (int i = 0; i < n; i++) {
            String str = tickStrings[i];
            tickStrings[i] = str.substring(0, str.length() - 1);
          }
        }
      } while (trimLast && !removedDecimalPoint);
    }

    // Draw ticks
    int lastY = Integer.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
      g.drawLine(x - 2, y, x + 2, y);
      String s = tickStrings[i];
      if (unit == Unit.PERCENT) {
        s += "%";
      }
      int sx = x - 6 - fm.stringWidth(s);
      if (y < lastY - 13) {
        if (checkLeftMargin(sx)) {
          // Wait for next repaint
          return;
        }
        g.drawString(s, sx, y + 4);
      }
      // Draw horizontal grid line
      g.setColor(Color.lightGray);
      g.drawLine(r.x + 4, y, r.x + r.width - 4, y);
      g.setColor(fg);
      lastY = y;
    }

    // Draw horizontal axis
    x = leftMargin;
    y = topMargin + h + 15;
    g.drawLine(x, y, x + w, y);

    long t1 = tMax;
    if (t1 <= 0L) {
      // No data yet, so draw current time
      t1 = System.currentTimeMillis();
    }
    long tz = timeDF.getTimeZone().getOffset(t1);
    long tickInterval = calculateTickInterval(w, 40, viewRangeMS);
    if (tickInterval > 3 * HOUR) {
      tickInterval = calculateTickInterval(w, 80, viewRangeMS);
    }
    long t0 = tickInterval - (t1 - viewRangeMS + tz) % tickInterval;
    while (t0 < viewRangeMS) {
      x = leftMargin + (int) (w * t0 / viewRangeMS);
      g.drawLine(x, y - 2, x, y + 2);

      long t = t1 - viewRangeMS + t0;
      String str = formatClockTime(t);
      g.drawString(str, x, y + 16);
      // if (tickInterval > (1 * HOUR) && t % (1 * DAY) == 0) {
      if ((t + tz) % (1 * DAY) == 0) {
        str = formatDate(t);
        g.drawString(str, x, y + 27);
      }
      // Draw vertical grid line
      g.setColor(Color.lightGray);
      g.drawLine(x, topMargin, x, topMargin + h);
      g.setColor(fg);
      t0 += tickInterval;
    }

    // Plot values
    int start = 0;
    int nValues = 0;
    int nLists = seqs.size();
    if (nLists > 0) {
      nValues = seqs.get(0).size;
    }
    if (nValues == 0) {
      g.setColor(oldColor);
      return;
    } else {
      Sequence seq = seqs.get(0);
      // Find starting point
      for (int p = 0; p < seq.size; p++) {
        if (times.time(p) >= tMax - viewRangeMS) {
          start = p;
          break;
        }
      }
    }

    // Optimization: collapse plot of more than four values per pixel
    int pointsPerPixel = (nValues - start) / w;
    if (pointsPerPixel < 4) {
      pointsPerPixel = 1;
    }

    // Draw graphs
    // Loop backwards over sequences because the first needs to be painted on top
    for (int i = nLists - 1; i >= 0; i--) {
      int x0 = leftMargin;
      int y0 = topMargin + h + 1;

      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Paint twice, with white and with color
        for (int pass = 0; pass < 2; pass++) {
          g.setColor((pass == 0) ? Color.white : seq.color);
          int x1 = -1;
          long v1 = -1;
          for (int p = start; p < nValues; p += pointsPerPixel) {
            // Make sure we get the last value
            if (pointsPerPixel > 1 && p >= nValues - pointsPerPixel) {
              p = nValues - 1;
            }
            int x2 = (int) (w * (times.time(p) - (t1 - viewRangeMS)) / viewRangeMS);
            long v2 = seq.value(p);
            if (v2 >= vMin && v2 <= vMax) {
              int y2 = (int) (h * (v2 - vMin) / (vMax - vMin));
              if (x1 >= 0 && v1 >= vMin && v1 <= vMax) {
                int y1 = (int) (h * (v1 - vMin) / (vMax - vMin));

                if (y1 == y2) {
                  // fillrect is much faster
                  g.fillRect(x0 + x1, y0 - y1 - pass, x2 - x1, 1);
                } else {
                  Graphics2D g2d = (Graphics2D) g;
                  Stroke oldStroke = null;
                  if (seq.transitionStroke != null) {
                    oldStroke = g2d.getStroke();
                    g2d.setStroke(seq.transitionStroke);
                  }
                  g.drawLine(x0 + x1, y0 - y1 - pass, x0 + x2, y0 - y2 - pass);
                  if (oldStroke != null) {
                    g2d.setStroke(oldStroke);
                  }
                }
              }
            }
            x1 = x2;
            v1 = v2;
          }
        }

        // Current value
        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          // a small triangle/arrow
          g.fillPolygon(new int[] {x + 2, x + 6, x + 6}, new int[] {y, y + 3, y - 3}, 3);
        }
        g.setColor(fg);
      }
    }

    int[] valueStringSlots = new int[nLists];
    for (int i = 0; i < nLists; i++) valueStringSlots[i] = -1;
    for (int i = 0; i < nLists; i++) {
      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Draw current value

        // TODO: collapse values if pointsPerPixel >= 4

        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          int y2 = getValueStringSlot(valueStringSlots, y, 2 * 10, i);
          g.setFont(smallFont);
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          String curValue = getFormattedValue(v, true);
          if (unit == Unit.PERCENT) {
            curValue += "%";
          }
          int valWidth = fm.stringWidth(curValue);
          String legend = (displayLegend ? seq.name : "");
          int legendWidth = fm.stringWidth(legend);
          if (checkRightMargin(valWidth) || checkRightMargin(legendWidth)) {
            // Wait for next repaint
            return;
          }
          g.drawString(legend, x + 17, Math.min(topMargin + h, y2 + 3 - 10));
          g.drawString(curValue, x + 17, Math.min(topMargin + h + 10, y2 + 3));

          // Maybe draw a short line to value
          if (y2 > y + 3) {
            g.drawLine(x + 9, y + 2, x + 14, y2);
          } else if (y2 < y - 3) {
            g.drawLine(x + 9, y - 2, x + 14, y2);
          }
        }
        g.setFont(oldFont);
        g.setColor(fg);
      }
    }
    g.setColor(oldColor);
  }
コード例 #27
0
  protected void onConnectAllSequences() {
    connectedSequences = new Vector();
    boolean shouldUseTransaction = false;
    boolean shouldUsePreallocation = false;
    boolean shouldAcquireValueAfterInsert = false;
    Iterator descriptors = getOwnerSession().getDescriptors().values().iterator();
    while (descriptors.hasNext()) {
      ClassDescriptor descriptor = (ClassDescriptor) descriptors.next();
      // Find root sequence, because inheritance needs to be resolved here.
      // TODO: The way we initialize sequencing needs to be in line with descriptor init.
      ClassDescriptor parentDescriptor = descriptor;
      while (!parentDescriptor.usesSequenceNumbers() && parentDescriptor.isChildDescriptor()) {
        ClassDescriptor newDescriptor =
            getOwnerSession()
                .getDescriptor(parentDescriptor.getInheritancePolicy().getParentClass());
        // Avoid issue with error cases of self parent, or null parent.
        if ((newDescriptor == null) || (newDescriptor == parentDescriptor)) {
          break;
        }
        parentDescriptor = newDescriptor;
      }
      if (!parentDescriptor.usesSequenceNumbers()) {
        continue;
      }
      String seqName = parentDescriptor.getSequenceNumberName();
      Sequence sequence = getSequence(seqName);
      if (sequence == null) {
        sequence = new DefaultSequence(seqName);
        getOwnerSession().getDatasourcePlatform().addSequence(sequence);
      }
      // PERF: Initialize the sequence, this avoid having to look it up every time.
      descriptor.setSequence(sequence);
      if (connectedSequences.contains(sequence)) {
        continue;
      }
      try {
        if (sequence instanceof DefaultSequence
            && !connectedSequences.contains(getDefaultSequence())) {
          getDefaultSequence().onConnect(getOwnerSession().getDatasourcePlatform());
          connectedSequences.add(0, getDefaultSequence());
          shouldUseTransaction |= getDefaultSequence().shouldUseTransaction();
          shouldUsePreallocation |= getDefaultSequence().shouldUsePreallocation();
          shouldAcquireValueAfterInsert |= getDefaultSequence().shouldAcquireValueAfterInsert();
        }
        sequence.onConnect(getOwnerSession().getDatasourcePlatform());
        connectedSequences.addElement(sequence);
        shouldUseTransaction |= sequence.shouldUseTransaction();
        shouldUsePreallocation |= sequence.shouldUsePreallocation();
        shouldAcquireValueAfterInsert |= sequence.shouldAcquireValueAfterInsert();
      } catch (RuntimeException ex) {
        // defaultSequence has to disconnect the last
        for (int i = connectedSequences.size() - 1; i >= 0; i--) {
          try {
            Sequence sequenceToDisconnect = (Sequence) connectedSequences.elementAt(i);
            sequenceToDisconnect.onDisconnect(getOwnerSession().getDatasourcePlatform());
          } catch (RuntimeException ex2) {
            // ignore
          }
        }
        connectedSequences = null;
        throw ex;
      }
    }

    if (shouldAcquireValueAfterInsert && !shouldUsePreallocation) {
      whenShouldAcquireValueForAll = AFTER_INSERT;
    } else if (!shouldAcquireValueAfterInsert && shouldUsePreallocation) {
      whenShouldAcquireValueForAll = BEFORE_INSERT;
    }
    atLeastOneSequenceShouldUseTransaction = shouldUseTransaction;
    atLeastOneSequenceShouldUsePreallocation = shouldUsePreallocation;
  }
コード例 #28
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
 public void setIsPlotted(String key, boolean isPlotted) {
   Sequence seq = getSequence(key);
   if (seq != null) {
     seq.isPlotted = isPlotted;
   }
 }
コード例 #29
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
 public void setUseDashedTransitions(String key, boolean b) {
   Sequence seq = getSequence(key);
   if (seq != null) {
     seq.transitionStroke = b ? getDashedStroke() : null;
   }
 }
コード例 #30
0
 public Object getNextValue(Sequence sequence, AbstractSession writeSession) {
   String seqName = sequence.getName();
   if (sequence.getPreallocationSize() > 1) {
     Queue sequencesForName = getPreallocationHandler().getPreallocated(seqName);
     // First try to get the next sequence value without locking.
     Object sequenceValue = sequencesForName.poll();
     if (sequenceValue != null) {
       return sequenceValue;
     }
     // Sequences are empty, so must lock and allocate next batch of sequences.
     acquireLock(seqName);
     try {
       sequenceValue = sequencesForName.poll();
       if (sequenceValue != null) {
         return sequenceValue;
       }
       // note that accessor.getLogin().shouldUseExternalTransactionController()
       // should be set to false
       Accessor accessor = getConnectionHandler().acquireAccessor();
       try {
         accessor.beginTransaction(writeSession);
         try {
           Vector sequences = sequence.getGeneratedVector(accessor, writeSession);
           accessor.commitTransaction(writeSession);
           // Remove the first value before adding to the global cache to ensure this thread gets
           // one.
           sequenceValue = sequences.remove(0);
           // copy remaining values to global cache.
           getPreallocationHandler().setPreallocated(seqName, sequences);
           logDebugPreallocation(seqName, sequenceValue, sequences);
         } catch (RuntimeException ex) {
           try {
             // make sure to rollback the transaction we've begun
             accessor.rollbackTransaction(writeSession);
           } catch (Exception rollbackException) {
             // ignore rollback exception
           }
           // don't eat the original exception
           throw ex;
         }
       } finally {
         getConnectionHandler().releaseAccessor(accessor);
       }
     } finally {
       releaseLock(seqName);
     }
     return sequenceValue;
   } else {
     // note that accessor.getLogin().shouldUseExternalTransactionController()
     // should be set to false
     Accessor accessor = getConnectionHandler().acquireAccessor();
     try {
       accessor.beginTransaction(writeSession);
       try {
         // preallocation size is 1 - just return the first (and only) element of the allocated
         // vector.
         Object sequenceValue =
             sequence.getGeneratedVector(accessor, writeSession).firstElement();
         accessor.commitTransaction(writeSession);
         return sequenceValue;
       } catch (RuntimeException ex) {
         try {
           // make sure to rollback the transaction we've begun
           accessor.rollbackTransaction(writeSession);
         } catch (Exception rollbackException) {
           // ignore rollback exception
         }
         // don't eat the original exception
         throw ex;
       }
     } finally {
       getConnectionHandler().releaseAccessor(accessor);
     }
   }
 }