Java Code Examples for java.util.ArrayList#toArray()

The following examples show how to use java.util.ArrayList#toArray() . 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: NuggetEvaluationFilter.java    From OpenEphyra with GNU General Public License v2.0 6 votes vote down vote up
/**	check if some result covers some nugger
 * @param	result	the result String
 * @param	nugget	the nugget string
 * @return the tokens of the specified nugget String not contained in the specified result String
 */
private String[] covers(String result, String nugget) {
	String[] rTokens = NETagger.tokenize(result);
	HashSet<String> rSet = new HashSet<String>();
	for (String r : rTokens)
		if (!FunctionWords.lookup(r) && (r.length() > 1))
			rSet.add(SnowballStemmer.stem(r).toLowerCase());
	
	String[] nTokens = NETagger.tokenize(nugget);
	HashSet<String> nSet = new HashSet<String>();
	for (String n : nTokens)
		if (!FunctionWords.lookup(n) && (n.length() > 1))
			nSet.add(SnowballStemmer.stem(n).toLowerCase());
	
	nSet.removeAll(rSet);
	ArrayList<String> remaining = new ArrayList<String>(nSet);
	
	return remaining.toArray(new String[remaining.size()]);
}
 
Example 2
Source File: SVNUIPlugin.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public MergeFileAssociation[] getMergeFileAssociations() throws BackingStoreException {
	ArrayList associations = new ArrayList();
	String[] childrenNames = MergeFileAssociation.getParentPreferences().childrenNames();
	for (int i = 0; i < childrenNames.length; i++) {
		org.osgi.service.prefs.Preferences node = MergeFileAssociation.getParentPreferences().node(childrenNames[i]);
		MergeFileAssociation association = new MergeFileAssociation();
		association.setFileType(childrenNames[i]);
		association.setMergeProgram(node.get("mergeProgram", "")); //$NON-NLS-1$,  //$NON-NLS-1$
		association.setParameters(node.get("parameters", "")); //$NON-NLS-1$,  //$NON-NLS-1$
		association.setType(node.getInt("type",MergeFileAssociation.BUILT_IN));
		associations.add(association);
	}
	MergeFileAssociation[] associationArray = new MergeFileAssociation[associations.size()];
	associations.toArray(associationArray);	
	Arrays.sort(associationArray);
	return associationArray;
}
 
Example 3
Source File: ProcessTools.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create ProcessBuilder using the java launcher from the jdk to be tested,
 * and with any platform specific arguments prepended.
 *
 * @param addTestVmAndJavaOptions If true, adds test.vm.opts and test.java.opts
 *        to the java arguments.
 * @param command Arguments to pass to the java command.
 * @return The ProcessBuilder instance representing the java command.
 */
public static ProcessBuilder createJavaProcessBuilder(boolean addTestVmAndJavaOptions, String... command) {
    String javapath = JDKToolFinder.getJDKTool("java");

    ArrayList<String> args = new ArrayList<>();
    args.add(javapath);

    args.add("-cp");
    args.add(System.getProperty("java.class.path"));

    if (addTestVmAndJavaOptions) {
        Collections.addAll(args, Utils.getTestJavaOpts());
    }

    Collections.addAll(args, command);

    // Reporting
    StringBuilder cmdLine = new StringBuilder();
    for (String cmd : args)
        cmdLine.append(cmd).append(' ');
    System.out.println("Command line: [" + cmdLine.toString() + "]");

    return new ProcessBuilder(args.toArray(new String[args.size()]));
}
 
Example 4
Source File: AppEngineWebMarkerResolutionGenerator.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
  
  ArrayList<IMarkerResolution> resolutions = new ArrayList<>();
  try {
    if ("com.google.cloud.tools.eclipse.appengine.validation.applicationMarker"
        .equals(marker.getType())) {
      resolutions.add(new ApplicationQuickFix());
    } else if ("com.google.cloud.tools.eclipse.appengine.validation.versionMarker"
        .equals(marker.getType())) {
      resolutions.add(new VersionQuickFix());
    } else if ("com.google.cloud.tools.eclipse.appengine.validation.runtimeMarker"
        .equals(marker.getType())) {
      resolutions.add(new UpgradeRuntimeQuickFix());
    }
  } catch (CoreException ex) {
    logger.log(Level.SEVERE, ex.getMessage());
  }
  return resolutions.toArray(new IMarkerResolution[0]);
}
 
Example 5
Source File: TextEntryWidget.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object[] getChildren() {
    ArrayList<Object> ret = new ArrayList<>();
    if (_adlObject != null) ret.add( _adlObject);
    if (_adlControl != null) ret.add( _adlControl);
    if (_adlLimits != null) ret.add( _adlLimits);
    if (!(color_mode.equals(""))) ret.add(new ADLResource(ADLResource.COLOR_MODE, color_mode));
    if (!(alignment.equals(""))) ret.add(new ADLResource(ADLResource.TEXT_ALIGNMENT, alignment));
    if (!(format.equals(""))) ret.add(new ADLResource(ADLResource.TEXT_FORMAT, format));
    return ret.toArray();
}
 
Example 6
Source File: NLineInputFormat.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/** 
 * Logically splits the set of input files for the job, splits N lines
 * of the input as one split.
 * 
 * @see org.apache.hadoop.mapred.FileInputFormat#getSplits(JobConf, int)
 */
public InputSplit[] getSplits(JobConf job, int numSplits)
throws IOException {
  ArrayList<FileSplit> splits = new ArrayList<FileSplit>();
  for (FileStatus status : listStatus(job)) {
    for (org.apache.hadoop.mapreduce.lib.input.FileSplit split : 
        org.apache.hadoop.mapreduce.lib.input.
        NLineInputFormat.getSplitsForFile(status, job, N)) {
      splits.add(new FileSplit(split));
    }
  }
  return splits.toArray(new FileSplit[splits.size()]);
}
 
Example 7
Source File: DnsManager.java    From happy-dns-android with MIT License 5 votes vote down vote up
private static String[] records2Ip(Record[] records) {
    if (records == null || records.length == 0) {
        return null;
    }
    ArrayList<String> a = new ArrayList<>(records.length);
    for (Record r : records) {
        a.add(r.value);
    }
    if (a.size() == 0) {
        return null;
    }
    return a.toArray(new String[a.size()]);
}
 
Example 8
Source File: DBOutputTable.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setSqlQuery(String[] sqlQuery) {
	// filter empty queries
	ArrayList<String> queries = new ArrayList<>();
	for(int i = 0; i < sqlQuery.length; i++) {
		if (sqlQuery[i] != null && sqlQuery[i].trim().length() > 0) {
			queries.add(sqlQuery[i]);
		}
	}
	this.sqlQuery=queries.toArray(new String[queries.size()]);
}
 
Example 9
Source File: SADLReplacements.java    From chipster with MIT License 5 votes vote down vote up
public String[] processStrings(Collection<String> options) throws IOException {
	ArrayList<String> newOptions = new ArrayList<>();
	for (String option : options) {
		return processReplacements(option).toArray(new String[0]);
	}
	return newOptions.toArray(new String[0]);
}
 
Example 10
Source File: MediaCodecVideoEncoder.java    From webrtc_android with MIT License 5 votes vote down vote up
private static MediaCodecProperties[] vp8HwList() {
    final ArrayList<MediaCodecProperties> supported_codecs = new ArrayList<MediaCodecProperties>();
    supported_codecs.add(qcomVp8HwProperties);
    supported_codecs.add(exynosVp8HwProperties);
    if (PeerConnectionFactory.fieldTrialsFindFullName("WebRTC-IntelVP8").equals("Enabled")) {
        supported_codecs.add(intelVp8HwProperties);
    }
    return supported_codecs.toArray(new MediaCodecProperties[supported_codecs.size()]);
}
 
Example 11
Source File: PluginManagerServer.java    From springreplugin with Apache License 2.0 5 votes vote down vote up
private String[] getRunningProcessesByPluginLocked(String pluginName) {
    ArrayList<String> l = new ArrayList<>();
    for (PluginRunningList prl : mProcess2PluginsMap.values()) {
        if (prl.isRunning(pluginName)) {
            l.add(prl.mProcessName);
        }
    }
    return l.toArray(new String[0]);
}
 
Example 12
Source File: BucketHelper.java    From medialibrary with Apache License 2.0 5 votes vote down vote up
private static BucketEntry[] loadBucketEntriesFromFilesTable(
        ThreadPool.JobContext jc, ContentResolver resolver, int type) {
    Uri uri = getFilesContentUri();
    Cursor cursor = resolver.query(uri,
            PROJECTION_BUCKET, BUCKET_GROUP_BY,
            null, BUCKET_ORDER_BY);
    if (cursor == null) {
        Log.w(TAG, "cannot open local database: " + uri);
        return new BucketEntry[0];
    }
    ArrayList<BucketEntry> buffer = new ArrayList<BucketEntry>();
    int typeBits = 0;
    if ((type & MediaObject.MEDIA_TYPE_IMAGE) != 0) {
        typeBits |= (1 << FileColumns.MEDIA_TYPE_IMAGE);
    }
    if ((type & MediaObject.MEDIA_TYPE_VIDEO) != 0) {
        typeBits |= (1 << FileColumns.MEDIA_TYPE_VIDEO);
    }
    try {
        while (cursor.moveToNext()) {
            if ((typeBits & (1 << cursor.getInt(INDEX_MEDIA_TYPE))) != 0) {
                BucketEntry entry = new BucketEntry(
                        cursor.getInt(INDEX_BUCKET_ID),
                        cursor.getString(INDEX_BUCKET_NAME));
                if (!buffer.contains(entry)) {
                    buffer.add(entry);
                }
            }
            if (jc.isCancelled()) return null;
        }
    } finally {
        Utils.closeSilently(cursor);
    }
    return buffer.toArray(new BucketEntry[buffer.size()]);
}
 
Example 13
Source File: FSImage.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * Return the name of the image file that is uploaded by periodic
 * checkpointing.
 */
File[] getFsImageNameCheckpoint() {
  ArrayList<File> list = new ArrayList<File>();
  for (Iterator<StorageDirectory> it = 
               dirIterator(NameNodeDirType.IMAGE); it.hasNext();) {
    list.add(getImageFile(it.next(), NameNodeFile.IMAGE_NEW));
  }
  return list.toArray(new File[list.size()]);
}
 
Example 14
Source File: LearnerProgress.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Extract the Id from activities and set them into an array.
    *
    * @param activities
    *            the activities that is being used to create the array.
    */
   private Long[] createIdArrayFrom(Set<Activity> activities) {
if (activities == null) {
    throw new IllegalArgumentException("Fail to create id array" + " from null activity set");
}

ArrayList<Long> activitiesIds = new ArrayList<Long>();
for (Iterator<Activity> i = activities.iterator(); i.hasNext();) {
    Activity activity = i.next();
    activitiesIds.add(activity.getActivityId());
}

return activitiesIds.toArray(new Long[activitiesIds.size()]);
   }
 
Example 15
Source File: BlockManagerTestUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static StorageReport[] getStorageReportsForDatanode(
    DatanodeDescriptor dnd) {
  ArrayList<StorageReport> reports = new ArrayList<StorageReport>();
  for (DatanodeStorageInfo storage : dnd.getStorageInfos()) {
    DatanodeStorage dns = new DatanodeStorage(
        storage.getStorageID(), storage.getState(), storage.getStorageType());
    StorageReport report = new StorageReport(
        dns ,false, storage.getCapacity(),
        storage.getDfsUsed(), storage.getRemaining(),
        storage.getBlockPoolUsed());
    reports.add(report);
  }
  return reports.toArray(StorageReport.EMPTY_ARRAY);
}
 
Example 16
Source File: TextMatchUpdater.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private IProject[] getProjectsInScope() {
	IPath[] enclosingProjects= fScope.enclosingProjectsAndJars();
	Set<IPath> enclosingProjectSet= new HashSet<>();
	enclosingProjectSet.addAll(Arrays.asList(enclosingProjects));

	ArrayList<IProject> projectsInScope= new ArrayList<>();
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i =0 ; i < projects.length; i++){
		if (enclosingProjectSet.contains(projects[i].getFullPath())) {
			projectsInScope.add(projects[i]);
		}
	}

	return projectsInScope.toArray(new IProject[projectsInScope.size()]);
}
 
Example 17
Source File: StateGraph.java    From iBioSim with Apache License 2.0 5 votes vote down vote up
public State[] getPrevStates() {
	ArrayList<State> prev = new ArrayList<State>();
	for (StateTransitionPair st : prevStates) {
		if (st.isEnabled()) {
			prev.add(st.getState());
		}
	}
	return prev.toArray(new State[0]);
}
 
Example 18
Source File: CommandHelper.java    From ForgeHax with MIT License 4 votes vote down vote up
/**
 * [code borrowed from ant.jar] Crack a command line.
 *
 * @param toProcess the command line to process.
 * @return the command line broken into strings. An empty or null toProcess parameter results in a
 * zero sized array.
 */
public static String[] translate(String toProcess) {
  if (toProcess == null || toProcess.length() == 0) {
    // no command? no string
    return new String[0];
  }
  // parse with a simple finite state machine
  
  final int normal = 0;
  final int inQuote = 1;
  final int inDoubleQuote = 2;
  int state = normal;
  final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
  final ArrayList<String> result = new ArrayList<String>();
  final StringBuilder current = new StringBuilder();
  boolean lastTokenHasBeenQuoted = false;
  
  while (tok.hasMoreTokens()) {
    String nextTok = tok.nextToken();
    switch (state) {
      case inQuote:
        if ("\'".equals(nextTok)) {
          lastTokenHasBeenQuoted = true;
          state = normal;
        } else {
          current.append(nextTok);
        }
        break;
      case inDoubleQuote:
        if ("\"".equals(nextTok)) {
          lastTokenHasBeenQuoted = true;
          state = normal;
        } else {
          current.append(nextTok);
        }
        break;
      default:
        if ("\'".equals(nextTok)) {
          state = inQuote;
        } else if ("\"".equals(nextTok)) {
          state = inDoubleQuote;
        } else if (" ".equals(nextTok)) {
          if (lastTokenHasBeenQuoted || current.length() != 0) {
            result.add(current.toString());
            current.setLength(0);
          }
        } else {
          current.append(nextTok);
        }
        lastTokenHasBeenQuoted = false;
        break;
    }
  }
  if (lastTokenHasBeenQuoted || current.length() != 0) {
    result.add(current.toString());
  }
  if (state == inQuote || state == inDoubleQuote) {
    throw new RuntimeException("unbalanced quotes in " + toProcess);
  }
  return result.toArray(new String[result.size()]);
}
 
Example 19
Source File: ProfilingPointsManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private ProfilingPoint[] getInvalidProfilingPoints(ProfilingPoint[] profilingPointsArr) {
    ArrayList<ProfilingPoint> invalidProfilingPoints = new ArrayList<ProfilingPoint>();
    for (ProfilingPoint profilingPoint : profilingPointsArr) if(!profilingPoint.isValid()) invalidProfilingPoints.add(profilingPoint);
    return invalidProfilingPoints.toArray(new ProfilingPoint[0]);
}
 
Example 20
Source File: Id3Decoder.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private static ChapterTocFrame decodeChapterTOCFrame(
    ParsableByteArray id3Data,
    int frameSize,
    int majorVersion,
    boolean unsignedIntFrameSizeHack,
    int frameHeaderSize,
    @Nullable FramePredicate framePredicate)
    throws UnsupportedEncodingException {
  int framePosition = id3Data.getPosition();
  int elementIdEndIndex = indexOfZeroByte(id3Data.data, framePosition);
  String elementId = new String(id3Data.data, framePosition, elementIdEndIndex - framePosition,
      "ISO-8859-1");
  id3Data.setPosition(elementIdEndIndex + 1);

  int ctocFlags = id3Data.readUnsignedByte();
  boolean isRoot = (ctocFlags & 0x0002) != 0;
  boolean isOrdered = (ctocFlags & 0x0001) != 0;

  int childCount = id3Data.readUnsignedByte();
  String[] children = new String[childCount];
  for (int i = 0; i < childCount; i++) {
    int startIndex = id3Data.getPosition();
    int endIndex = indexOfZeroByte(id3Data.data, startIndex);
    children[i] = new String(id3Data.data, startIndex, endIndex - startIndex, "ISO-8859-1");
    id3Data.setPosition(endIndex + 1);
  }

  ArrayList<Id3Frame> subFrames = new ArrayList<>();
  int limit = framePosition + frameSize;
  while (id3Data.getPosition() < limit) {
    Id3Frame frame = decodeFrame(majorVersion, id3Data, unsignedIntFrameSizeHack,
        frameHeaderSize, framePredicate);
    if (frame != null) {
      subFrames.add(frame);
    }
  }

  Id3Frame[] subFrameArray = new Id3Frame[subFrames.size()];
  subFrames.toArray(subFrameArray);
  return new ChapterTocFrame(elementId, isRoot, isOrdered, children, subFrameArray);
}