List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:org.apache.geode.geospatial.client.Roads.java
/** * Find the a random road within a 5 mile radius. * * @param coordinate//from ww w .j a v a 2s.c o m * @return */ public Coordinate[] getNextRoad(Coordinate coordinate) { Coordinate[] result = null; Collection<Integer> coordinates = geospatialIndex .query(calculatePolygon(coordinate, 5 * Actor.METERS_IN_MILE)); if (coordinates != null && coordinates.size() > 0) { Integer[] array = coordinates.toArray(new Integer[coordinates.size()]); int index = random.nextInt(array.length); result = multimap.get(array[index]).getCoordinates(); } return result; }
From source file:hudson.plugins.clearcase.ucm.service.BaselineService.java
public Baseline[] getDependentBaselines(Baseline... baselines) throws IOException, InterruptedException { Collection<Baseline> result = new ArrayList<Baseline>(); for (Baseline baseline : baselines) { Baseline[] dependentBaselines = getDependentBaselines(baseline); result.addAll(Arrays.asList(dependentBaselines)); }/*from www. j a v a2 s . c o m*/ return result.toArray(new Baseline[result.size()]); }
From source file:net.micwin.openspace.view.BasePageView.java
/** * adds a list of components to the content body. * /*w w w. j a va2s . c o m*/ * @param components */ protected void addToContentBody(Collection<Component> components) { addToContentBody(components.toArray(new Component[components.size()])); }
From source file:com.jdom.get.stuff.done.android.AndroidApplicationContextFactory.java
public void displayCollectionOfItemsAsRadioButtonGroup(String message, Collection<String> collection, String initialSelection, final RunnableWithResults<String> callback) { final String[] array = collection.toArray(new String[collection.size()]); int selectedItemIndex = -1; if (initialSelection != null) { for (int i = 0; i < array.length; i++) { if (array[i].equals(initialSelection)) { selectedItemIndex = i;/*from w ww.j a v a2 s . c om*/ } } } final List<String> selectedItems = new ArrayList<String>(); if (initialSelection != null) { selectedItems.add(initialSelection); } ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_single_choice, array); AlertDialog.Builder builder = new AlertDialog.Builder(activity); if (!StringUtils.isEmpty(message)) { builder.setTitle(message); } builder.setPositiveButton(OK_BUTTON_TEXT, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (!selectedItems.isEmpty()) { callback.callback(selectedItems.iterator().next()); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }).setSingleChoiceItems(arrayAdapter, selectedItemIndex, new OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { String value = array[arg1]; selectedItems.clear(); selectedItems.add(value); } }).show(); }
From source file:net.community.chest.gitcloud.facade.AbstractContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); MutablePropertySources propSources = environment.getPropertySources(); ExtendedPlaceholderResolver sourcesResolver = ExtendedPlaceholderResolverUtils .toPlaceholderResolver(propSources); File appBase = resolveApplicationBase(propSources, sourcesResolver); File configFile = getApplicationConfigFile(appBase, sourcesResolver); Collection<String> activeProfiles = resolveActiveProfiles(sourcesResolver); if (ExtendedCollectionUtils.size(activeProfiles) > 0) { environment.setActiveProfiles(activeProfiles.toArray(new String[activeProfiles.size()])); }/* w w w . j a va2s . c o m*/ try { ensureFoldersExistence(appBase, configFile, sourcesResolver); } catch (IOException e) { logger.error("ensureFoldersExistence(" + ExtendedFileUtils.toString(appBase) + ")" + " " + e.getClass().getSimpleName() + ": " + e.getMessage()); } if (logger.isDebugEnabled()) { showArtifactsVersions(); } }
From source file:com.glaf.core.util.StringTools.java
public static String[] getStrings(String str) { Collection<String> values = getStringCollection(str); if (values.size() == 0) { return null; }//from w w w . j a v a 2s. c o m return values.toArray(new String[values.size()]); }
From source file:net.ontopia.persistence.proxy.ObjectRelationalMapping.java
/** * INTERNAL: Utility method that converts a collection of class * descriptors to an array of class descriptors. */// www .ja v a 2 s . c o m protected ClassDescriptor[] toClassDescriptorArray(Collection<ClassDescriptor> cdescs) { ClassDescriptor[] _cdescs = new ClassDescriptor[cdescs.size()]; cdescs.toArray(_cdescs); return _cdescs; }
From source file:jp.co.acroquest.endosnipe.web.explorer.entity.InvocationModel.java
/** * ? {@link InvocationModel} ?????<br /> * * @param telegram // w ww. j av a 2s .c o m * @param alarmThreshold ? * @param warningThreshold ? * @return {@link InvocationModel} ? */ public static InvocationModel[] createFromTelegram(final Telegram telegram, final long alarmThreshold, final long warningThreshold) { Map<String, InvocationModel> invocationMap = new HashMap<String, InvocationModel>(); Body[] objBody = telegram.getObjBody(); String strClassMethodName = null; for (int index = 0; index < objBody.length; index++) { ResponseBody responseBody = (ResponseBody) objBody[index]; if (responseBody.getStrObjName() == null) { continue; } // ??? // InvocationModel?? String strItemName = ((ResponseBody) objBody[index]).getStrItemName(); Object[] objTempArr = ((ResponseBody) objBody[index]).getObjItemValueArr(); // ???0???? if (objTempArr.length == 0) { continue; } if (StringUtils.isEmpty(responseBody.getStrObjName()) == false) { strClassMethodName = responseBody.getStrObjName(); } InvocationModel invocation = invocationMap.get(strClassMethodName); if (invocation == null) { // ?????InvocationModel???? invocation = new InvocationModel(); invocation.setDate(new Date()); // ?????????? if (strClassMethodName == null) { continue; } List<String> strClassMethodNameArr = StringUtil.split(strClassMethodName, CLASSMETHOD_SEPARATOR); String strClassName = "unknown"; String strMethodName = "unknown"; if (strClassMethodNameArr.size() > INDEX_METHODNAME) { strClassName = strClassMethodNameArr.get(INDEX_CLASSNAME); strMethodName = strClassMethodNameArr.get(INDEX_METHODNAME); } invocation.setClassName(strClassName); invocation.setMethodName(strMethodName); invocationMap.put(strClassMethodName, invocation); } Long value = 0L; String valid = "false"; if (responseBody.getByteItemMode() == ItemType.ITEMTYPE_LONG) { value = (Long) objTempArr[0]; } else if (responseBody.getByteItemMode() == ItemType.ITEMTYPE_STRING) { valid = (String) objTempArr[0]; } // ?? if (ITEMNAME_CALL_COUNT.equals(strItemName)) { value = getValidValue(value); invocation.setCount(value); } // ? else if (ITEMNAME_ACCUMULATED_MAXIMUM_INTERVAL.equals(strItemName)) { value = getValidValue(value); invocation.setAccumulatedMaximum(value); } // ?? else if (ITEMNAME_ACCUMULATED_MINIMUM_INTERVAL.equals(strItemName)) { value = getValidValue(value); invocation.setAccumulatedMinimum(value); } // ?? else if (ITEMNAME_ACCUMULATED_TOTAL_INTERVAL.equals(strItemName)) { value = getValidValue(value); invocation.setAccumulatedTotal(value); } // CPU else if (ITEMNAME_ACCUMULATED_MAXIMUM_CPU_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setAccumulatedCpuMaximum(value); } // ?CPU else if (ITEMNAME_ACCUMULATED_MINIMUM_CPU_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setAccumulatedCpuMinimum(value); } // ?CPU else if (ITEMNAME_ACCUMULATED_TOTAL_CPU_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setAccumulatedCpuTotal(value); } // else if (ITEMNAME_ACCUMULATED_MAXIMUM_USER_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setAccumulatedUserMaximum(value); } // ? else if (ITEMNAME_ACCUMULATED_MINIMUM_USER_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setAccumulatedUserMinimum(value); } // ? else if (ITEMNAME_ACCUMULATED_TOTAL_USER_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setAccumulatedUserTotal(value); } // ? else if (ITEMNAME_MAXIMUM_INTERVAL.equals(strItemName)) { value = getValidValue(value); invocation.setMaximum(value); } // ?? else if (ITEMNAME_MINIMUM_INTERVAL.equals(strItemName)) { value = getValidValue(value); invocation.setMinimum(value); } // ?? else if (ITEMNAME_TOTAL_INTERVAL.equals(strItemName)) { value = getValidValue(value); invocation.setTotal(value); } // CPU else if (ITEMNAME_MAXIMUM_CPU_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setCpuMaximum(value); } // ?CPU else if (ITEMNAME_MINIMUM_CPU_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setCpuMinimum(value); } // ?CPU else if (ITEMNAME_TOTAL_CPU_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setCpuTotal(value); } // USER else if (ITEMNAME_MAXIMUM_USER_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setUserMaximum(value); } // ?USER else if (ITEMNAME_MINIMUM_USER_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setUserMinimum(value); } // ?USER else if (ITEMNAME_TOTAL_USER_INTERVAL.equals(strItemName)) { value = getValidMegaValue(value); invocation.setUserTotal(value); } // else if (ITEMNAME_JAVAPROCESS_EXCEPTION_OCCURENCE_COUNT.equals(strItemName)) { value = getValidValue(value); invocation.setThrowableCount(value); } // else if (ITEMNAME_JAVAPROCESS_METHOD_STALL_COUNT.equals(strItemName)) { value = getValidValue(value); invocation.setMethodStallCount(value); } // ??? ??????? // CHECKSTYLE:OFF else if (ITEMNAME_ALL_CALLER_NAMES.equals(strItemName)) { // } // CHECKSTYLE:ON else if (ITEMNAME_TARGET.equals(strItemName)) { invocation.setTarget(Boolean.valueOf(valid)); } // ??????? else if (ITEMNAME_TRANSACTION_GRAPH.equals(strItemName)) { invocation.setResponseGraphOutput(Boolean.valueOf(valid)); } // TAT else if (ITEMNAME_ALARM_THRESHOLD.equals(strItemName)) { value = getValidValue(value); invocation.setAlarmThreshold(value); } // CPU else if (ITEMNAME_ALARM_CPU_THRESHOLD.equals(strItemName)) { value = getValidValue(value); invocation.setAlarmCpuThreshold(value); } /* else if (ITEMNAME_JAVAPROCESS_HTTP_EXCEPTION.equals(strItemName)) { value = getValidValue(value); invocation.setHttpStatusCount(value); } */ } Collection<InvocationModel> invocationList = invocationMap.values(); return invocationList.toArray(new InvocationModel[invocationList.size()]); }
From source file:cz.lidinsky.editor.Editor.java
/** * *///from w ww .j a v a2 s.c o m public String letSelectComponent() { // get array of component names Collection<String> componentNames = ComponentFactory.getInstance().getComponentList(); String[] componentNamesArray = componentNames.toArray(new String[componentNames.size()]); System.out.println(componentNamesArray.toString()); // show input dialog String selected = (String) JOptionPane.showInputDialog(frame, "Select component", "Components", JOptionPane.QUESTION_MESSAGE, null, componentNamesArray, componentNamesArray[0]); return selected; }
From source file:com.netflix.simianarmy.basic.conformity.BasicConformityMonkey.java
/** {@inheritDoc} */ @Override/*from w w w. ja v a2s . c om*/ public void doMonkeyBusiness() { cfg.reload(); context().resetEventReport(); if (isConformityMonkeyEnabled()) { nonconformingClusters.clear(); conformingClusters.clear(); failedClusters.clear(); nonexistentClusters.clear(); List<Cluster> clusters = crawler.clusters(); Map<String, Set<String>> existingClusterNamesByRegion = Maps.newHashMap(); for (String region : regions) { existingClusterNamesByRegion.put(region, new HashSet<String>()); } for (Cluster cluster : clusters) { existingClusterNamesByRegion.get(cluster.getRegion()).add(cluster.getName()); } List<Cluster> trackedClusters = clusterTracker .getAllClusters(regions.toArray(new String[regions.size()])); for (Cluster trackedCluster : trackedClusters) { if (!existingClusterNamesByRegion.get(trackedCluster.getRegion()) .contains(trackedCluster.getName())) { addCluster(nonexistentClusters, trackedCluster); } } for (String region : regions) { Collection<Cluster> toDelete = nonexistentClusters.get(region); if (toDelete != null) { clusterTracker.deleteClusters(toDelete.toArray(new Cluster[toDelete.size()])); } } LOGGER.info(String.format("Performing conformity check for %d crawled clusters.", clusters.size())); Date now = calendar.now().getTime(); for (Cluster cluster : clusters) { boolean conforming; try { conforming = ruleEngine.check(cluster); } catch (Exception e) { LOGGER.error( String.format("Failed to perform conformity check for cluster %s", cluster.getName()), e); addCluster(failedClusters, cluster); continue; } cluster.setUpdateTime(now); cluster.setConforming(conforming); if (conforming) { LOGGER.info(String.format("Cluster %s is conforming", cluster.getName())); addCluster(conformingClusters, cluster); } else { LOGGER.info(String.format("Cluster %s is not conforming", cluster.getName())); addCluster(nonconformingClusters, cluster); } if (!leashed) { LOGGER.info(String.format("Saving cluster %s", cluster.getName())); clusterTracker.addOrUpdate(cluster); } else { LOGGER.info(String.format( "The conformity monkey is leashed, no data change is made for cluster %s.", cluster.getName())); } } if (!leashed) { emailNotifier.sendNotifications(); } else { LOGGER.info("Conformity monkey is leashed, no notification is sent."); } if (cfg.getBoolOrElse(NS + "summaryEmail.enabled", true)) { sendConformitySummaryEmail(); } } }