コード例 #1
1
ファイル: AbstractDirectory.java プロジェクト: NanoGame/jnode
  /**
   * Add a directory entry.
   *
   * @param nameExt
   * @throws IOException
   */
  protected synchronized FatDirEntry addFatFile(String nameExt) throws IOException {
    if (getFileSystem().isReadOnly()) {
      throw new ReadOnlyFileSystemException("addFile in readonly filesystem");
    }

    if (getFatEntry(nameExt) != null) {
      throw new IOException("File already exists" + nameExt);
    }
    final FatDirEntry newEntry = new FatDirEntry(this, splitName(nameExt), splitExt(nameExt));
    int size = entries.size();
    for (int i = 0; i < size; i++) {
      FatBasicDirEntry e = entries.get(i);
      if (e == null) {
        entries.set(i, newEntry);
        setDirty();
        flush();
        return newEntry;
      }
    }
    int newSize = size + 512 / 32;
    if (canChangeSize(newSize)) {
      entries.ensureCapacity(newSize);
      setDirty();
      flush();
      return newEntry;
    }
    throw new IOException("Directory is full");
  }
コード例 #2
1
 /**
  * create a new vertex, with the exact same name and weights, and only the depth is like the old
  * one + its length
  *
  * @param id
  * @param v
  */
 public SeqVertex(int id, SeqVertex v) {
   this(id, v.getName());
   int len = v.getWeights().size();
   _weights.ensureCapacity(len);
   for (int i = 0; i < len; i++) _weights.add(i, v.getWeights().get(i));
   _depth = v.getDepth() + v.getName().length();
 }
コード例 #3
1
 public SeqVertex(Integer id, String name, double wei) {
   this(id, name);
   int len = name.length();
   _weights.ensureCapacity(len);
   for (int i = 0; i < len; i++) {
     _weights.add(i, wei);
   }
 }
コード例 #4
1
ファイル: Vector.java プロジェクト: sherckuith/jop
 /**
  * Inserts a new element into the Vector at <code>index</code>. Any elements at or greater than
  * index are shifted up one position.
  *
  * @param obj the object to insert
  * @param index the index at which the object is inserted
  * @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt; size()
  * @see #add(int, Object)
  */
 public synchronized void insertElementAt(Object obj, int index) {
   checkBoundInclusive(index);
   if (elementCount == elementData.length) ensureCapacity(elementCount + 1);
   modCount++;
   System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
   elementCount++;
   elementData[index] = obj;
 }
コード例 #5
1
ファイル: Vector.java プロジェクト: sherckuith/jop
 /**
  * Explicitly sets the size of the vector (but not necessarily the size of the internal data
  * array). If the new size is smaller than the old one, old values that don't fit are lost. If the
  * new size is larger than the old one, the vector is padded with null entries.
  *
  * @param newSize The new size of the internal array
  * @throws ArrayIndexOutOfBoundsException if the new size is negative
  */
 public synchronized void setSize(int newSize) {
   // Don't bother checking for the case where size() == the capacity of the
   // vector since that is a much less likely case; it's more efficient to
   // not do the check and lose a bit of performance in that infrequent case
   modCount++;
   ensureCapacity(newSize);
   if (newSize < elementCount) Arrays.fill(elementData, newSize, elementCount, null);
   elementCount = newSize;
 }
コード例 #6
1
  /**
   * Constructs a DefaultComboBoxModel object initialized with an array of objects.
   *
   * @param items an array of Object objects
   */
  public ExtendedComboBoxModel(final Object items[]) {
    objects = new Vector();
    objects.ensureCapacity(items.length);

    int i, c;
    for (i = 0, c = items.length; i < c; i++) {
      objects.addElement(items[i]);
    }

    if (getSize() > 0) {
      selectedObject = getElementAt(0);
    }
  }
コード例 #7
1
ファイル: Vector.java プロジェクト: sherckuith/jop
  /**
   * Inserts all elements of the given collection at the given index of this Vector. Behavior is
   * undefined if the collection is modified during this operation (for example, if this == c).
   *
   * @param c the collection to append
   * @return true if this vector changed, in other words c was not empty
   * @throws NullPointerException if c is null
   * @throws ArrayIndexOutOfBoundsException index &lt; 0 || index &gt; size()
   * @since 1.2
   */
  public synchronized boolean addAll(int index, Collection c) {
    checkBoundInclusive(index);
    Iterator itr = c.iterator();
    int csize = c.size();

    modCount++;
    ensureCapacity(elementCount + csize);
    int end = index + csize;
    if (elementCount > 0 && index != elementCount)
      System.arraycopy(elementData, index, elementData, end, elementCount - index);
    elementCount += csize;
    for (; index < end; index++) elementData[index] = itr.next();
    return (csize > 0);
  }
コード例 #8
1
ファイル: ParameterBlock.java プロジェクト: Bludge0n/ajvm
 public ParameterBlock setSource(Object source, int index) {
   sources.ensureCapacity(index);
   sources.set(index, source);
   return this;
 }
コード例 #9
1
ファイル: ParameterBlock.java プロジェクト: Bludge0n/ajvm
 public ParameterBlock set(Object o, int index) {
   parameters.ensureCapacity(index);
   parameters.set(index, o);
   return this;
 }
コード例 #10
1
  /**
   * Initialises the list of Spectra with the next Set of Spectra
   *
   * @throws JSpecViewException
   */
  public void initNextSetOfSpectra() throws JSpecViewException {

    Vector<JDXSpectrum> jdxSpectra = this.getSpectra();
    jdxSpectra.clear();
    jdxSpectra.ensureCapacity(MAX_NUMBER_SPECTRA);

    String tabularSpecData = null;
    JDXSpectrum spectrum;
    HashMap<String, String> LDRTable;

    double offset = Graph.ERROR;
    double obFreq = Graph.ERROR;
    double firstX, lastX, xFactor = 1;
    double deltaX = 0, yFactor = 1;
    boolean continuous = true;
    int nPoints;
    String xUnits = "", title = "", yUnits = "";
    String page = "";

    int dataPointNum = -1;
    int shiftRefType = -1;
    String[] plotSymbols = new String[2];

    Coordinate[] xyCoords;

    JDXSourceStringTokenizer t = new JDXSourceStringTokenizer(sourceContents);

    String label = "";

    if (!hasMoreSpectra()) return;
    int setIndex = currentSpectraSetIndex;
    int spectrumIndex = 0;

    boolean found = false;
    while (t.hasMoreTokens()) {
      if (found) break;
      if (label.equals("##PAGE")) {
        if ((spectrumIndex % numberOfSets) != setIndex) {
          spectrumIndex++;
          t.nextToken();
          label = JSpecViewUtils.cleanLabel(t.label);
          continue;
        }
      } else {
        t.nextToken();
        label = JSpecViewUtils.cleanLabel(t.label);
      }
    }

    spectrum = new JDXSpectrum();
    while (t.hasMoreTokens()) {

      if (label.equals("##ENDNTUPLES")) {
        break;
      }

      if (label.equals("##PAGE")) {
        page = t.value;
        t.nextToken(); // ignore ##PAGE
        label = JSpecViewUtils.cleanLabel(t.label);
        continue;
      }

      LDRTable = new HashMap<String, String>();
      while (!label.equals("##DATATABLE")) {
        LDRTable.put(t.label, t.value);
        t.nextToken();
        label = JSpecViewUtils.cleanLabel(t.label);
      }

      if (label.equals("##DATATABLE")) {
        // determine if continuous
        String dtblStr = t.value;
        try {
          BufferedReader reader = new BufferedReader(new StringReader(dtblStr));
          String line = reader.readLine();
          if (line.trim().indexOf("PEAKS") > 0) {
            continuous = false;
          }

          // parse variable list
          int index1 = line.indexOf('(');
          int index2 = line.lastIndexOf(')');
          if (index1 == -1 || index2 == -1) throw new JDXSourceException("Variable List not Found");
          String varList = line.substring(index1, index2 + 1);

          ArrayList<String> symbols = (ArrayList<String>) nTupleTable.get("##SYMBOL");
          int countSyms = 0;
          for (int i = 0; i < symbols.size(); i++) {
            String sym = ((String) symbols.get(i)).trim();
            if (varList.indexOf(sym) != -1) {
              plotSymbols[countSyms++] = sym;
            }
            if (countSyms == 2) break;
          }

        } catch (IOException ioe) {
        }

        if (continuous) {
          spectrum.setContinuous(true);
          spectrum.setDataClass("XYDATA");
        } else {
          spectrum.setContinuous(false);
          spectrum.setDataClass("PEAKTABLE");
        }
      }

      // Get Tabular Spectral Data
      tabularSpecData = t.value;
      if (tabularSpecData == null) throw new JSpecViewException("Error Reading Data Set");

      String tmp = tabularSpecData;

      try {
        char chr;
        do {
          tmp = tmp.substring(tmp.indexOf("\n") + 1);
          chr = tmp.trim().charAt(0);
        } while (!Character.isDigit(chr) && chr != '+' && chr != '-' && chr != '.');
      } catch (IndexOutOfBoundsException iobe) {
        throw new JSpecViewException("Error Reading Data Set");
      }
      tabularSpecData = tmp;

      ArrayList<String> list;
      if (spectrum.getDataClass().equals("XYDATA")) {
        // Get Label Values

        list = (ArrayList<String>) nTupleTable.get("##SYMBOL");
        int index1 = list.indexOf(plotSymbols[0]);
        int index2 = list.indexOf(plotSymbols[1]);

        list = (ArrayList<String>) nTupleTable.get("##FACTOR");
        xFactor = Double.parseDouble((String) list.get(index1));
        yFactor = Double.parseDouble((String) list.get(index2));

        list = (ArrayList<String>) nTupleTable.get("##LAST");
        lastX = Double.parseDouble((String) list.get(index1));
        // lastY = Double.parseDouble((String)list.get(index1));

        list = (ArrayList<String>) nTupleTable.get("##FIRST");
        firstX = Double.parseDouble((String) list.get(index1));
        // firstY = Double.parseDouble((String)list.get(index2));

        list = (ArrayList<String>) nTupleTable.get("##VARDIM");
        nPoints = Integer.parseInt((String) list.get(index1));

        list = (ArrayList<String>) nTupleTable.get("##UNITS");
        xUnits = (String) list.get(index1);
        yUnits = (String) list.get(index2);

        deltaX = (lastX - firstX) / (nPoints - 1);

        JDXDecompressor decompressor =
            new JDXDecompressor(tabularSpecData, xFactor, yFactor, deltaX);

        xyCoords = decompressor.decompressData();

        if (xyCoords == null) xyCoords = JSpecViewUtils.parseDSV(tabularSpecData, xFactor, yFactor);

        // apply offset
        if (offset != Graph.ERROR && obFreq != Graph.ERROR) {
          JSpecViewUtils.applyShiftReference(
              xyCoords, dataPointNum, firstX, lastX, offset, obFreq, shiftRefType);
        }

        if (obFreq != Graph.ERROR && xUnits.toUpperCase().equals("HZ")) {
          double xScale = obFreq;
          JSpecViewUtils.applyScale(xyCoords, (1 / xScale), 1);
          xUnits = "PPM";
          spectrum.setHZtoPPM(true);
          spectrum.setObservedFreq(obFreq);
        }
      } else if (spectrum.getDataClass().equals("PEAKTABLE")
          || spectrum.getDataClass().equals("XYPOINTS")) {
        list = (ArrayList<String>) nTupleTable.get("##SYMBOL");
        int index1 = list.indexOf(plotSymbols[0]);
        int index2 = list.indexOf(plotSymbols[1]);

        list = (ArrayList<String>) nTupleTable.get("##UNITS");
        xUnits = (String) list.get(index1);
        yUnits = (String) list.get(index2);
        xyCoords = JSpecViewUtils.parseDSV(tabularSpecData, xFactor, yFactor);
      } else throw new JDXSourceException("Unable to read Ntuple Source");

      spectrum.setXUnits(xUnits);
      spectrum.setYUnits(yUnits);
      spectrum.setTitle(
          title.substring(0, (title.length() >= 20 ? 21 : title.length())) + "..." + " : " + page);

      for (Iterator<String> iter = sourceLDRTable.keySet().iterator(); iter.hasNext(); ) {
        String key = (String) iter.next();
        if (!JSpecViewUtils.cleanLabel(key).equals("##TITLE")
            && !JSpecViewUtils.cleanLabel(key).equals("##DATACLASS")
            && !JSpecViewUtils.cleanLabel(key).equals("##NTUPLES"))
          LDRTable.put(key, sourceLDRTable.get(key));
      }
      spectrum.setHeaderTable(LDRTable);
      spectrum.setXYCoords(xyCoords);

      addJDXSpectrum(spectrum);

      found = false;
      while (t.hasMoreTokens()) {
        if (found) break;
        t.nextToken();
        label = JSpecViewUtils.cleanLabel(t.label);
        if (label.equals("##PAGE")) {
          spectrumIndex++;
          if ((spectrumIndex % numberOfSets) != setIndex) continue;
        }
      }

      spectrum = new JDXSpectrum();
    }

    currentSpectraSetIndex++;
  }
コード例 #11
1
ファイル: Vector.java プロジェクト: sherckuith/jop
 /**
  * Adds an element to the Vector at the end of the Vector. The vector is increased by
  * ensureCapacity(size() + 1) if needed.
  *
  * @param obj the object to add to the Vector
  */
 public synchronized void addElement(Object obj) {
   if (elementCount == elementData.length) ensureCapacity(elementCount + 1);
   modCount++;
   elementData[elementCount++] = obj;
 }
コード例 #12
1
 /**
  * Increases the capacity of this list, if necessary, to ensure that it can hold at least the
  * number of components specified by the minimum capacity argument.
  *
  * @param minCapacity the desired minimum capacity
  * @see Vector#ensureCapacity(int)
  */
 public void ensureCapacity(int minCapacity) {
   delegate.ensureCapacity(minCapacity);
 }
コード例 #13
0
 public void ensureCapacity(int capacity) {
   _values.ensureCapacity(capacity);
 }