Java Code Examples for java.util.Vector#add()

The following examples show how to use java.util.Vector#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JFileChooser.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the current file filter. The file filter is used by the
 * file chooser to filter out files from the user's view.
 *
 * @beaninfo
 *   preferred: true
 *       bound: true
 * description: Sets the File Filter used to filter out files of type.
 *
 * @param filter the new current file filter to use
 * @see #getFileFilter
 */
public void setFileFilter(FileFilter filter) {
    FileFilter oldValue = fileFilter;
    fileFilter = filter;
    if (filter != null) {
        if (isMultiSelectionEnabled() && selectedFiles != null && selectedFiles.length > 0) {
            Vector<File> fList = new Vector<File>();
            boolean failed = false;
            for (File file : selectedFiles) {
                if (filter.accept(file)) {
                    fList.add(file);
                } else {
                    failed = true;
                }
            }
            if (failed) {
                setSelectedFiles((fList.size() == 0) ? null : fList.toArray(new File[fList.size()]));
            }
        } else if (selectedFile != null && !filter.accept(selectedFile)) {
            setSelectedFile(null);
        }
    }
    firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, oldValue, fileFilter);
}
 
Example 2
Source File: StringUtil.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Split the source into two strings at the first occurrence of the splitter Subsequent occurrences are not treated specially, and may be part of the second string.
 * 
 * @param source
 *        The string to split
 * @param splitter
 *        The string that forms the boundary between the two strings returned.
 * @return An array of two strings split from source by splitter.
 */
public static String[] splitFirst(String source, String splitter)
{
	// hold the results as we find them
	Vector rv = new Vector();
	int last = 0;
	int next = 0;

	// find first splitter in source
	next = source.indexOf(splitter, last);
	if (next != -1)
	{
		// isolate from last thru before next
		rv.add(source.substring(last, next));
		last = next + splitter.length();
	}

	if (last < source.length())
	{
		rv.add(source.substring(last, source.length()));
	}

	// convert to array
	return (String[]) rv.toArray(new String[rv.size()]);
}
 
Example 3
Source File: ExtensionDependency.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static File[] getExtFiles(File[] dirs) throws IOException {
    Vector<File> urls = new Vector<File>();
    for (int i = 0; i < dirs.length; i++) {
        String[] files = dirs[i].list(new JarFilter());
        if (files != null) {
            debug("getExtFiles files.length " + files.length);
            for (int j = 0; j < files.length; j++) {
                File f = new File(dirs[i], files[j]);
                urls.add(f);
                debug("getExtFiles f["+j+"] "+ f);
            }
        }
    }
    File[] ua = new File[urls.size()];
    urls.copyInto(ua);
    debug("getExtFiles ua.length " + ua.length);
    return ua;
}
 
Example 4
Source File: VectorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testHasNextAfterRemoval() {
    Vector<String> strings = new Vector<>();
    strings.add("string1");
    Iterator<String> it = strings.iterator();
    it.next();
    it.remove();
    assertFalse(it.hasNext());

    strings = new Vector<>();
    strings.add("string1");
    strings.add("string2");
    it = strings.iterator();
    it.next();
    it.remove();
    assertTrue(it.hasNext());
    assertEquals("string2", it.next());
}
 
Example 5
Source File: Curve.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void insertLine(Vector<Curve> curves,
                              double x0, double y0,
                              double x1, double y1)
{
    if (y0 < y1) {
        curves.add(new Order1(x0, y0,
                              x1, y1,
                              INCREASING));
    } else if (y0 > y1) {
        curves.add(new Order1(x1, y1,
                              x0, y0,
                              DECREASING));
    } else {
        // Do not add horizontal lines
    }
}
 
Example 6
Source File: TestEQTLDatasetForInteractions.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
private void initGenotypes(boolean permute, HashMap hashSamples, String[] cohorts) {

		datasetGenotypes = new ExpressionDataset(inputDir + "/Genotypes.binary", '\t', null, hashSamples);

		if (permute) {
			System.out.println("WARNING: PERMUTING GENOTYPE DATA!!!!");
			if (cohorts == null) {
				throw new RuntimeException("Cohorts must be specified for permuation. Can be a single cohort");
				//cohorts = new String[]{"LLDeep", "LLS", "RS", "CODAM"};
			}
			int[] permSampleIDs = new int[datasetGenotypes.nrSamples];
			for (int p = 0; p < cohorts.length; p++) {
				Vector vecSamples = new Vector();
				for (int s = 0; s < datasetGenotypes.nrSamples; s++) {
					//if (datasetGenotypes.sampleNames[s].startsWith(cohorts[p])) {
					vecSamples.add(s);
					//}
				}

				for (int s = 0; s < datasetGenotypes.nrSamples; s++) {
					//if (datasetGenotypes.sampleNames[s].startsWith(cohorts[p])) {
					int randomSample = ((Integer) vecSamples.remove((int) ((double) vecSamples.size() * Math.random()))).intValue();
					permSampleIDs[s] = randomSample;
					//}
				}
			}

			ExpressionDataset datasetGenotypes2 = new ExpressionDataset(datasetGenotypes.nrProbes, datasetGenotypes.nrSamples);
			datasetGenotypes2.probeNames = datasetGenotypes.probeNames;
			datasetGenotypes2.sampleNames = datasetGenotypes.sampleNames;
			datasetGenotypes2.recalculateHashMaps();
			for (int p = 0; p < datasetGenotypes2.nrProbes; p++) {
				for (int s = 0; s < datasetGenotypes2.nrSamples; s++) {
					datasetGenotypes2.rawData[p][s] = datasetGenotypes.rawData[p][permSampleIDs[s]];
				}
			}
			datasetGenotypes = datasetGenotypes2;
		}

	}
 
Example 7
Source File: DOMUtil.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void removeAllAttributes(Element element)
{
    Vector<String> names = new Vector<String>();

    int length = element.getAttributes().getLength();
    NamedNodeMap atts = element.getAttributes();

    for(int i = 0; i < length; names.add(atts.item(i).getLocalName()), i++);

    for(String name : names) element.removeAttribute(name);
}
 
Example 8
Source File: Button.java    From jcurses with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected  Vector<InputChar> getShortCutsList() {
	if (getShortCut() == null) {
		return null;
	}
	Vector<InputChar> result = new Vector<InputChar>();
	result.add(getShortCut());
	return result;
}
 
Example 9
Source File: LocusMapDataProvider.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
public void addAll() {
    Vector<CartridgeFile> v = new Vector<>();
    v.add(MainActivity.cartridgeFile);
    addCartridges(v);
    addZones((Vector<Zone>) Engine.instance.cartridge.zones, DetailsActivity.et);
    if (DetailsActivity.et != null && !(DetailsActivity.et instanceof Zone))
        addOther(DetailsActivity.et, true);
}
 
Example 10
Source File: SimpleScan.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return Returns scan datapoints over certain intensity
 */
public @Nonnull DataPoint[] getDataPointsOverIntensity(double intensity) {
  int index;
  Vector<DataPoint> points = new Vector<DataPoint>();

  for (index = 0; index < dataPoints.length; index++) {
    if (dataPoints[index].getIntensity() >= intensity)
      points.add(dataPoints[index]);
  }

  DataPoint pointsOverIntensity[] = points.toArray(new DataPoint[0]);

  return pointsOverIntensity;
}
 
Example 11
Source File: LegalRegistryNames.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * return a vector of valid legal RMI naming URLs.
 */
private static Vector getLegalForms() {
    String localHostAddress = null;
    String localHostName = null;

    // get the local host name and address
    try {
        localHostName = InetAddress.getLocalHost().getHostName();
        localHostAddress = InetAddress.getLocalHost().getHostAddress();
    } catch(UnknownHostException e) {
        TestLibrary.bomb("Test failed: unexpected exception", e);
    }

    Vector legalForms = new Vector();
    legalForms.add("///MyName");
    legalForms.add("//:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("//" + localHostAddress + "/MyName");
    legalForms.add("//" + localHostAddress + ":" +
                   Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("//localhost/MyName");
    legalForms.add("//localhost:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("//" + localHostName + "/MyName");
    legalForms.add("//" + localHostName + ":" + Registry.REGISTRY_PORT +
                   "/MyName");
    legalForms.add("MyName");
    legalForms.add("/MyName");
    legalForms.add("rmi:///MyName");
    legalForms.add("rmi://:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("rmi://" + localHostAddress + "/MyName");
    legalForms.add("rmi://" + localHostAddress + ":" +
                   Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("rmi://localhost/MyName");
    legalForms.add("rmi://localhost:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("rmi://" + localHostName + "/MyName");
    legalForms.add("rmi://" + localHostName + ":" +
                   Registry.REGISTRY_PORT + "/MyName");
    return legalForms;
}
 
Example 12
Source File: XSDHandler.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void addRelatedAttribute(XSAttributeDeclaration decl, Vector componentList, String namespace, Map<String, Vector> dependencies) {
    if (decl.getScope() == XSConstants.SCOPE_GLOBAL) {
        if (!componentList.contains(decl)) {
            Vector importedNamespaces = findDependentNamespaces(namespace, dependencies);
            addNamespaceDependency(namespace, decl.getNamespace(), importedNamespaces);
            componentList.add(decl);
        }
    }
    else {
        expandRelatedAttributeComponents(decl, componentList, namespace, dependencies);
    }
}
 
Example 13
Source File: FileUtility.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
public static Vector<String> loadScriptsInFolder(String path){
	File fileScript = new File(path);
	Vector<String> vec = new Vector();
	File files[] = fileScript.listFiles();
	for(int i=0;i<files.length;i++){
		if(!files[i].isDirectory())
			vec.add(files[i].getAbsolutePath());
	}
	return vec;
}
 
Example 14
Source File: DataService.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public Vector<String> atDbByName(String dbPath){
	String path1 = getRootDir();
	String concatPath = PathUtil.concat(path1, dbPath, '/');
	
	Vector<String> v = new Vector<String>();
	v.add(getHost());
	v.add(concatPath);
	return v;
}
 
Example 15
Source File: FullConnectionLayer.java    From CupDnn with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void forward() {
	// TODO Auto-generated method stub
	Blob input = mNetwork.getDatas().get(id-1);
	Blob output = mNetwork.getDatas().get(id);
	float[] inputData = input.getData();
	float[] outputData = output.getData();
	float[] wData = w.getData();
	float[] bData = b.getData();
	float[] zData = z.getData();
	z.fillValue(0);
	Vector<Task<Object>> workers = new Vector<Task<Object>>();
	int batch = mNetwork.getBatch();
	for(int n=0;n<batch;n++){
		workers.add(new Task<Object>(n) {
			@Override
		    public Object call() throws Exception {
				for(int os=0;os<outSize;os++){//�ж��ٸ��������ǰ����ж��ٸ���Ԫ
					//��ÿ����Ԫ��Ȩ�����
					for(int is=0;is<inSize;is++){
						//zData[n*output.get3DSize()+os] ��ʾһ�������еĵ�n���ĵ�os����Ԫ
						zData[n*outSize+os] += inputData[n*inSize+is]*wData[os*inSize+is];
					}
					//ƫִ
					zData[n*outSize+os] += bData[os];
					//�����
					if(activationFunc!=null){
						outputData[n*outSize+os] = activationFunc.active(zData[n*outSize+os]);
					}else {
						outputData[n*outSize+os] = zData[n*outSize+os];
					}
				}
				return null;
			}
		});
	}
	ThreadPoolManager.getInstance(mNetwork).dispatchTask(workers);
}
 
Example 16
Source File: ExtendedXMLCatalogReader.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
                        String localName,
                        String qName)
  throws SAXException {

  super.endElement(namespaceURI, localName, qName);

  // Check after popping the stack so we don't erroneously think we
  // are our own extension namespace...
  boolean inExtension = inExtensionNamespace();

  int entryType = -1;
  Vector entryArgs = new Vector();

  if (namespaceURI != null
      && (extendedNamespaceName.equals(namespaceURI))
      && !inExtension) {

    String popURI = (String) baseURIStack.pop();
    String baseURI = (String) baseURIStack.peek();

    if (!baseURI.equals(popURI)) {
      entryType = catalog.BASE;
      entryArgs.add(baseURI);

      debug.message(4, "(reset) xml:base", baseURI);

      try {
        CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
        catalog.addEntry(ce);
      } catch (CatalogException cex) {
        if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
          debug.message(1, "Invalid catalog entry type", localName);
        } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
          debug.message(1, "Invalid catalog entry (rbase)", localName);
        }
      }
    }
  }
}
 
Example 17
Source File: SetOfIntegerSyntax.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Accumulate the given range (lb .. ub) into the canonical array form
 * into the given vector of int[] objects.
 */
private static void accumulate(Vector ranges, int lb,int ub) {
    // Make sure range is non-null.
    if (lb <= ub) {
        // Stick range at the back of the vector.
        ranges.add(new int[] {lb, ub});

        // Work towards the front of the vector to integrate the new range
        // with the existing ranges.
        for (int j = ranges.size()-2; j >= 0; -- j) {
        // Get lower and upper bounds of the two ranges being compared.
            int[] rangea = (int[]) ranges.elementAt (j);
            int lba = rangea[0];
            int uba = rangea[1];
            int[] rangeb = (int[]) ranges.elementAt (j+1);
            int lbb = rangeb[0];
            int ubb = rangeb[1];

            /* If the two ranges overlap or are adjacent, coalesce them.
             * The two ranges overlap if the larger lower bound is less
             * than or equal to the smaller upper bound. The two ranges
             * are adjacent if the larger lower bound is one greater
             * than the smaller upper bound.
             */
            if (Math.max(lba, lbb) - Math.min(uba, ubb) <= 1) {
                // The coalesced range is from the smaller lower bound to
                // the larger upper bound.
                ranges.setElementAt(new int[]
                                       {Math.min(lba, lbb),
                                            Math.max(uba, ubb)}, j);
                ranges.remove (j+1);
            } else if (lba > lbb) {

                /* If the two ranges don't overlap and aren't adjacent but
                 * are out of order, swap them.
                 */
                ranges.setElementAt (rangeb, j);
                ranges.setElementAt (rangea, j+1);
            } else {
            /* If the two ranges don't overlap and aren't adjacent and
             * aren't out of order, we're done early.
             */
                break;
            }
        }
    }
}
 
Example 18
Source File: WeaponHandler.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
public int checkTerrain(int nDamage, Entity entityTarget,
        Vector<Report> vPhaseReport) {
    boolean isAboveWoods = ((entityTarget != null) && ((entityTarget
            .relHeight() >= 2) || (entityTarget.isAirborne())));
    if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_WOODS_COVER)
            && !isAboveWoods
            && (game.getBoard().getHex(entityTarget.getPosition())
                    .containsTerrain(Terrains.WOODS) || game.getBoard()
                    .getHex(entityTarget.getPosition())
                    .containsTerrain(Terrains.JUNGLE))
            && !(entityTarget.getSwarmAttackerId() == ae.getId())) {
        ITerrain woodHex = game.getBoard()
                .getHex(entityTarget.getPosition())
                .getTerrain(Terrains.WOODS);
        ITerrain jungleHex = game.getBoard()
                .getHex(entityTarget.getPosition())
                .getTerrain(Terrains.JUNGLE);
        int treeAbsorbs = 0;
        String hexType = "";
        if (woodHex != null) {
            treeAbsorbs = woodHex.getLevel() * 2;
            hexType = "wooded";
        } else if (jungleHex != null) {
            treeAbsorbs = jungleHex.getLevel() * 2;
            hexType = "jungle";
        }

        // Do not absorb more damage than the weapon can do.
        treeAbsorbs = Math.min(nDamage, treeAbsorbs);

        nDamage = Math.max(0, nDamage - treeAbsorbs);
        server.tryClearHex(entityTarget.getPosition(), treeAbsorbs,
                ae.getId());
        Report.addNewline(vPhaseReport);
        Report terrainReport = new Report(6427);
        terrainReport.subject = entityTarget.getId();
        terrainReport.add(hexType);
        terrainReport.add(treeAbsorbs);
        terrainReport.indent(2);
        terrainReport.newlines = 0;
        vPhaseReport.add(terrainReport);
    }
    return nDamage;
}
 
Example 19
Source File: Utils.java    From samoa with Apache License 2.0 4 votes vote down vote up
/**
  * Breaks up the string, if wider than "columns" characters.
  *
  * @param s		the string to process
  * @param columns	the width in columns
  * @return		the processed string
  */
 public static String[] breakUp(String s, int columns) {
   Vector<String>	result;
   String		line;
   BreakIterator	boundary;
   int			boundaryStart;
   int			boundaryEnd;
   String		word;
   String		punctuation;
   int			i;
   String[]		lines;

   result      = new Vector<String>();
   punctuation = " .,;:!?'\"";
   lines       = s.split("\n");

   for (i = 0; i < lines.length; i++) {
     boundary      = BreakIterator.getWordInstance();
     boundary.setText(lines[i]);
     boundaryStart = boundary.first();
     boundaryEnd   = boundary.next();
     line          = "";

     while (boundaryEnd != BreakIterator.DONE) {
word = lines[i].substring(boundaryStart, boundaryEnd);
if (line.length() >= columns) {
  if (word.length() == 1) {
    if (punctuation.indexOf(word.charAt(0)) > -1) {
      line += word;
      word = "";
    }
  }
  result.add(line);
  line = "";
}
line          += word;
boundaryStart  = boundaryEnd;
boundaryEnd    = boundary.next();
     }
     if (line.length() > 0)
result.add(line);
   }

   return result.toArray(new String[result.size()]);
 }
 
Example 20
Source File: Harness.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create new benchmark harness with given configuration and reporter.
 * Throws ConfigFormatException if there was an error parsing the config
 * file.
 * <p>
 * <b>Config file syntax:</b>
 * <p>
 * '#' marks the beginning of a comment.  Blank lines are ignored.  All
 * other lines should adhere to the following format:
 * <pre>
 *     &lt;weight&gt; &lt;name&gt; &lt;class&gt; [&lt;args&gt;]
 * </pre>
 * &lt;weight&gt; is a floating point value which is multiplied times the
 * benchmark's execution time to determine its weighted score.  The
 * total score of the benchmark suite is the sum of all weighted scores
 * of its benchmarks.
 * <p>
 * &lt;name&gt; is a name used to identify the benchmark on the benchmark
 * report.  If the name contains whitespace, the quote character '"' should
 * be used as a delimiter.
 * <p>
 * &lt;class&gt; is the full name (including the package) of the class
 * containing the benchmark implementation.  This class must implement
 * bench.Benchmark.
 * <p>
 * [&lt;args&gt;] is a variable-length list of runtime arguments to pass to
 * the benchmark.  Arguments containing whitespace should use the quote
 * character '"' as a delimiter.
 * <p>
 * <b>Example:</b>
 * <pre>
 *      3.5 "My benchmark" bench.serial.Test first second "third arg"
 * </pre>
 */
public Harness(InputStream in) throws IOException, ConfigFormatException {
    Vector bvec = new Vector();
    StreamTokenizer tokens = new StreamTokenizer(new InputStreamReader(in));

    tokens.resetSyntax();
    tokens.wordChars(0, 255);
    tokens.whitespaceChars(0, ' ');
    tokens.commentChar('#');
    tokens.quoteChar('"');
    tokens.eolIsSignificant(true);

    tokens.nextToken();
    while (tokens.ttype != StreamTokenizer.TT_EOF) {
        switch (tokens.ttype) {
            case StreamTokenizer.TT_WORD:
            case '"':                       // parse line
                bvec.add(parseBenchInfo(tokens));
                break;

            default:                        // ignore
                tokens.nextToken();
                break;
        }
    }
    binfo = (BenchInfo[]) bvec.toArray(new BenchInfo[bvec.size()]);
}