List of usage examples for java.util Vector toArray
@SuppressWarnings("unchecked") public synchronized <T> T[] toArray(T[] a)
From source file:it.acubelab.smaph.entityfilters.LibSvmEntityFilter.java
/** * Turns a frature_name-feature_value mapping to an array of features. * /*from www .jav a 2 s. c om*/ * @param features * the mapping from feature names to feature values. * @return an array of feature values. */ public static double[] featuresToFtrVectStatic(HashMap<String, Double> features) { if (!checkFeatures(features)) { for (String ftrName : features.keySet()) System.err.printf("%s -> %f%n", ftrName, features.get(ftrName)); throw new RuntimeException("Implementation error -- check the features"); } Vector<Double> ftrValues = new Vector<>(); for (String ftrName : ftrNames) ftrValues.add(getOrDefault(features, ftrName, 0.0)); return ArrayUtils.toPrimitive(ftrValues.toArray(new Double[] {})); }
From source file:Main.java
public static synchronized String[] getElementValues(Element element) { if (element == null) { return null; }/* w w w . jav a2 s. co m*/ Vector childs = new Vector(); for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) { if (node instanceof Text) { childs.add(node.getNodeValue()); } } String[] values = new String[childs.size()]; childs.toArray(values); return values; }
From source file:Main.java
public static synchronized Element[] getChildElements(Element element) { if (element == null) { return null; }/*from w w w.j a v a 2 s .c om*/ Vector childs = new Vector(); for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) { if (node instanceof Element) { childs.add((Element) node); } } Element[] elmt = new Element[childs.size()]; childs.toArray(elmt); return elmt; }
From source file:Main.java
public static synchronized Element[] getChildElements(Element element, String childName) { if (element == null || childName == null || childName.length() == 0) { return null; }//from w ww .ja v a2 s . c o m Vector childs = new Vector(); for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) { if (node instanceof Element) { childs.add((Element) node); } } Element[] elmt = new Element[childs.size()]; childs.toArray(elmt); return elmt; }
From source file:Main.java
/** * @param context//w w w . j a va2 s .c o m * this method is used for retrieving email accounts of device * @return */ public static String[] getAccount(Context context) { final AccountManager accountManager = AccountManager.get(context); final Account[] accounts = accountManager.getAccounts(); final Vector<String> accountVector = new Vector<String>(); for (int i = 0; i < accounts.length; i++) { if (!accountVector.contains(accounts[i].name) && isValidEmail(accounts[i].name)) { accountVector.addElement(accounts[i].name); } } final String accountArray[] = new String[accountVector.size()]; return accountVector.toArray(accountArray); }
From source file:org.parosproxy.paros.core.spider.Base.java
/** * Get an array of "BASE" tags.//from w ww . j av a 2 s . c om * @param doc * The html document to be parsed. * @return array of "A" */ public static Base[] getBases(String doc) { Vector bases = new Vector(); parser.parse(doc); while (parser.nextTag()) { String content = parser.getContent(); String attrs = parser.getAttrs(); Base base = new Base(); base.buildAttrs(attrs); base.build(content); bases.addElement(base); } Base[] result = new Base[bases.size()]; result = (Base[]) bases.toArray(result); return result; }
From source file:net.rim.ejde.internal.model.BlackBerryPropertiesFactory.java
/** * Initialize from a given legacy project. * * @param properties/*from w w w . ja va 2s . com*/ * * @param project * the project * @param javaProj * the java proj */ static private void initializeFromLegacy(BlackBerryProperties properties, final Project project, final IJavaProject javaProj) { // Initialize the general section properties._general.setTitle(project.getTitle()); properties._general.setVersion(project.getVersion()); properties._general.setDescription(project.getDescription()); properties._general.setVendor(project.getVendor()); // Initialize the application section properties._application.setHomeScreenPosition(project.getRibbonPosition()); properties._application.setIsAutostartup(project.getRunOnStartup()); properties._application.setIsSystemModule(project.getSystemModule()); switch (project.getType()) { case Project.MIDLET: { properties._application.setMainArgs(IConstants.EMPTY_STRING); properties._application.setMainMIDletName(project.getMidletClass()); break; } case Project.CLDC_APPLICATION: { properties._application.setMainArgs(project.getMidletClass()); properties._application.setMainMIDletName(IConstants.EMPTY_STRING); break; } case Project.LIBRARY: { properties._application.setIsSystemModule(Boolean.TRUE); // No break falling through to default case } default: { properties._application.setMainArgs(IConstants.EMPTY_STRING); properties._application.setMainMIDletName(IConstants.EMPTY_STRING); } } properties._application .setStartupTier(Math.max(project.getStartupTier(), ProjectUtils.getStartupTiers()[0])); properties._application.setType(GeneralSection.projectTypeChoiceList[project.getType()]); // Initialize the resources section properties._resources.setHasTitleResource(project.isTitleResourceBundleActive()); properties._resources.setTitleResourceBundleName(project.getTitleResourceBundleName()); properties._resources.setTitleResourceBundleKey(project.getTitleResourceTitleKey()); properties._resources.setTitleResourceBundleClassName(project.getTitleResourceBundleClassName()); final IProject iProject = javaProj.getProject(); final String resourceBundlePath = project.getTitleResourceBundlePath(); if (!StringUtils.isBlank(resourceBundlePath)) { final String resourceBundleFilePath = Util.makeAbsolute(resourceBundlePath, project.getFile()); properties._resources.setTitleResourceBundleRelativePath( getTargetRelFilePath(new File(resourceBundleFilePath), project, JavaCore.create(iProject))); } else { properties._resources.setTitleResourceBundleRelativePath(IConstants.EMPTY_STRING); } properties._resources.setDescriptionId(project.getTitleResourceDescriptionKey()); properties._resources.setIconFiles(getIcons(project, iProject)); // Initialize the keyword section // TODO we use the KeywordResourceBundleKey to store ID for now, later on when we implemented the UI part, we need to // change properties.getKeywordResources().setKeywordResourceBundleKey(project.getKeywordResourceBundleId()); properties.getKeywordResources() .setKeywordResourceBundleClassName(project.getKeywordResourceBundleClassName()); // Initialize the compiler section properties._compile.setAliasList(project.getAlias()); properties._compile.setCompressResources(project.getWorkspace().getResourcesCompressed()); properties._compile.setConvertImages(!project.getIsNoConvertPng()); properties._compile.setCreateWarningForNoExportedRoutine(!project.getIsNoMainWarn()); properties._compile.setOutputCompilerMessages(project.getIsNoWarn()); final Vector<String> defines = project.getDefines(); properties._compile.setPreprocessorDefines( PreprocessorTag.create(defines.toArray(new String[defines.size()]), PreprocessorTag.PJ_SCOPE)); // Initialize the packaging section final Vector<File> alxFileVector = project.getAlxImports(); final String[] alxFiles = new String[alxFileVector.size()]; for (int i = 0; i < alxFileVector.size(); i++) { final File alxFile = alxFileVector.get(i); alxFiles[i] = alxFile.getPath(); } properties._packaging.setAlxFiles(alxFiles); properties._packaging.setCleanStep(project.getCleanBuild()); properties.setValidOutputFileName(project.getOutputFileName()); properties._packaging.setPostBuildStep(project.getPostBuild()); properties._packaging.setPreBuildStep(project.getPreBuild()); properties._packaging.setGenerateALXFile(PackagingUtils.getDefaultGenerateAlxFile()); // Initialize alternate entry points final int AEPNumber = project.getNumEntries(); properties._alternateEntryPoints = new AlternateEntryPoint[AEPNumber]; for (int i = 0; i < AEPNumber; i++) { final Project entry = project.getEntry(i); try { properties._alternateEntryPoints[i] = createAlternateEntryPoint(entry, iProject); } catch (final CoreException e) { _log.error(e.getMessage(), e); } } // Initialize hidden properties properties._hiddenProperties.setClassProtection(project.getClassProtection()); properties._hiddenProperties.setPackageProtection(project.getPackageProtection()); }
From source file:StringUtil.java
/** * 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. * /* w w w . j a v a 2 s.c o m*/ * @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()]); }
From source file:org.mrgeo.rasterops.GeoTiffExporter.java
public static Vector<TIFFField> toTiffField(final XTIFFField[] fields) { final Vector<TIFFField> result = new Vector<TIFFField>(); for (final XTIFFField field : fields) { int count = field.getCount(); Object obj;//from ww w . ja va 2 s .c o m switch (field.getType()) { case XTIFFField.TIFF_BYTE: case XTIFFField.TIFF_SBYTE: obj = field.getAsBytes(); break; case XTIFFField.TIFF_SHORT: obj = field.getAsChars(); break; case XTIFFField.TIFF_ASCII: obj = field.getAsStrings(); final String[] tmp = (String[]) obj; final Vector<String> newStr = new Vector<String>(); for (final String element : tmp) { if (element != null) { newStr.add(element); } } obj = newStr.toArray(new String[] {}); count = newStr.size(); break; case XTIFFField.TIFF_DOUBLE: obj = field.getAsDoubles(); break; case XTIFFField.TIFF_FLOAT: obj = field.getAsFloats(); break; case XTIFFField.TIFF_LONG: obj = field.getAsInts(); break; case XTIFFField.TIFF_SLONG: obj = field.getAsLongs(); break; case XTIFFField.TIFF_RATIONAL: obj = field.getAsRationals(); break; case XTIFFField.TIFF_SSHORT: obj = field.getAsShorts(); break; case XTIFFField.TIFF_SRATIONAL: obj = field.getAsSRationals(); break; default: throw new ClassCastException(); } result.add(new TIFFField(field.getTag(), field.getType(), count, obj)); } return result; }
From source file:org.infoglue.deliver.portal.PathParser.java
/** * Extract control-params from path//from w w w. ja v a2 s. c om * * @param prefix Prefix of control-param * @param encodedParameters Path * @param preserveNamespace Keep prefix in key * @return */ public static Map parsePathParameters(String prefix, String encodedParameters, boolean preserveNamespace) { log.debug("Parsing '" + encodedParameters + "' for " + prefix); HashMap map = new HashMap(10); StringTokenizer tok = new StringTokenizer(encodedParameters, "/"); String name = (tok.hasMoreTokens() ? tok.nextToken() : null); while (name != null) { if (name.startsWith(prefix)) { Vector buffer = new Vector(); String nextName = decodeValues(tok, buffer); if (buffer.size() > 0) { if (!preserveNamespace) { name = name.substring(prefix.length()); } log.debug("Adding " + name + "=" + buffer); map.put(name, (String[]) buffer.toArray(new String[buffer.size()])); } name = nextName; } else { //log.debug("Unknown token: " + name); name = (tok.hasMoreTokens() ? tok.nextToken() : null); } } return map; }