List of usage examples for java.util List toArray
<T> T[] toArray(T[] a);
From source file:com.bosscs.spark.commons.utils.AnnotationUtils.java
/** * Return a pair of Field[] whose left element is * the array of keys fields./* w ww . j a va 2 s .c o m*/ * The right element contains the array of all other non-key fields. * * @param clazz the Class object * @return a pair object whose first element contains key fields, and whose second element contains all other columns. */ public static Pair<Field[], Field[]> filterKeyFields(Class clazz) { Field[] filtered = filterDeepFields(clazz); List<Field> keys = new ArrayList<>(); List<Field> others = new ArrayList<>(); for (Field field : filtered) { if (isKey(field.getAnnotation(HadoopField.class))) { keys.add(field); } else { others.add(field); } } return Pair.create(keys.toArray(new Field[keys.size()]), others.toArray(new Field[others.size()])); }
From source file:com.palantir.ptoss.cinch.swing.JListWiringHarness.java
private static void updateListModel(JList list, List<?> newContents) { if (newContents == null) { newContents = ImmutableList.of(); }//from w ww.j a v a2 s. com ListModel oldModel = list.getModel(); List<Object> old = Lists.newArrayListWithExpectedSize(oldModel.getSize()); for (int i = 0; i < oldModel.getSize(); i++) { old.add(oldModel.getElementAt(i)); } if (old.equals(newContents)) { return; } Object[] selected = list.getSelectedValues(); DefaultListModel listModel = new DefaultListModel(); for (Object obj : newContents) { listModel.addElement(obj); } list.setModel(listModel); List<Integer> newIndices = Lists.newArrayListWithCapacity(selected.length); Set<Object> selectedSet = Sets.newHashSet(selected); for (int i = 0; i < listModel.size(); i++) { if (selectedSet.contains(listModel.elementAt(i))) { newIndices.add(i); } } list.setSelectedIndices(ArrayUtils.toPrimitive(newIndices.toArray(new Integer[0]))); }
From source file:app.commons.ReflectionUtils.java
public static Field[] getAllDeclaredFields(Class clazz) { Class currentClass = clazz;/*from ww w .j av a 2 s .co m*/ List<Field> fields = new ArrayList<Field>(); while (currentClass != null) { fields.addAll(Arrays.asList(currentClass.getDeclaredFields())); currentClass = currentClass.getSuperclass(); } return fields.toArray(new Field[fields.size()]); }
From source file:com.google.api.ads.adwords.awalerting.AwAlerting.java
/** * Initialize the application context, adding the properties configuration file depending on the * specified path./*w w w . ja v a 2 s .co m*/ * * @param propertiesResource the properties resource * @return the resource loaded from the properties file * @throws IOException error opening the properties file */ private static Properties initApplicationContextAndProperties(Resource propertiesResource) throws IOException { LOGGER.trace("Innitializing Spring application context."); DynamicPropertyPlaceholderConfigurer.setDynamicResource(propertiesResource); Properties properties = PropertiesLoaderUtils.loadProperties(propertiesResource); // Selecting the XMLs to choose the Spring Beans to load. List<String> listOfClassPathXml = new ArrayList<String>(); listOfClassPathXml.add("classpath:aw-alerting-processor-beans.xml"); appCtx = new ClassPathXmlApplicationContext( listOfClassPathXml.toArray(new String[listOfClassPathXml.size()])); return properties; }
From source file:org.eclipse.virgo.ide.jdt.internal.core.classpath.ServerClasspathUtils.java
/** * Reads the persisted classpath entries for the given <code>project</code> and returns the * {@link IClasspathEntry}s./*from w w w .j ava2 s. c o m*/ * <p> * This method returns <code>null</code> to indicate that the file could not be read. */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected static IClasspathEntry[] readPersistedClasspathEntries(IJavaProject project) { File file = new File(ServerCorePlugin.getDefault().getStateLocation().toFile(), project.getProject().getName() + CLASSPATH_FILE); String xmlClasspath = null; if (file.exists()) { try { byte[] bytes = FileCopyUtils.copyToByteArray(file); xmlClasspath = new String(bytes, org.eclipse.jdt.internal.compiler.util.Util.UTF_8); } catch (UnsupportedEncodingException e) { // can't happen as default UTF-8 is used } catch (IOException e) { } } if (xmlClasspath == null) { return null; } if (project instanceof JavaProject) { JavaProject javaProject = (JavaProject) project; try { Object decodedClassPath; try { // needs reflection since return type of decodeClasspath has changed in Eclipse 3.6 Method method = javaProject.getClass().getMethod("decodeClasspath", String.class, Map.class); decodedClassPath = method.invoke(javaProject, xmlClasspath, new HashMap()); if (decodedClassPath instanceof IClasspathEntry[][]) { List<IClasspathEntry> decodedEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry[] entry : (IClasspathEntry[][]) decodedClassPath) { decodedEntries.addAll(Arrays.asList(entry)); } return decodedEntries.toArray(new IClasspathEntry[decodedEntries.size()]); } else if (decodedClassPath instanceof IClasspathEntry[]) { return (IClasspathEntry[]) decodedClassPath; } } catch (Exception e) { JdtCorePlugin.log(e); } } catch (AssertionFailedException e) { JdtCorePlugin.log(e); } } return null; }
From source file:eu.annocultor.utils.SparqlQueryHelper.java
public static void filter(Namespaces namespaces, String namespacePrefix, String outputFilePrefix, String query, String... inputFilePattern) throws Exception { List<File> files = new ArrayList<File>(); for (String pattern : inputFilePattern) { files.addAll(Utils.expandFileTemplateFrom(new File("."), pattern)); }//from w w w. j a va2s. co m SparqlQueryHelper sqh = new SparqlQueryHelper(namespacePrefix); try { sqh.open(); sqh.load(namespacePrefix, files.toArray(new File[] {})); sqh.query(query); sqh.save(namespaces, outputFilePrefix); } finally { sqh.close(); } }
From source file:org.alfresco.test.wqs.uitl.AbstractWQS.java
@BeforeSuite(alwaysRun = true) @Parameters({ "contextFileName" }) public static void setupContext(@Optional("wqs-context.xml") String contextFileName) { List<String> contextXMLList = new ArrayList<String>(); contextXMLList.add(contextFileName); ctx = new ClassPathXmlApplicationContext(contextXMLList.toArray(new String[contextXMLList.size()])); testProperties = (ShareTestProperty) ctx.getBean("shareTestProperties"); wqsTestProperties = (WqsTestProperty) ctx.getBean("wqsProperties"); wcmqs = wqsTestProperties.getWcmqs(); shareUrl = testProperties.getShareUrl(); username = testProperties.getUsername(); password = testProperties.getPassword(); alfrescoVersion = testProperties.getAlfrescoVersion(); DOMAIN_FREE = wqsTestProperties.getDomainFree(); DOMAIN_PREMIUM = wqsTestProperties.getDomainPremium(); DOMAIN_HYBRID = wqsTestProperties.getDomainHybrid(); DEFAULT_USER = wqsTestProperties.getDefaultUser(); UNIQUE_TESTDATA_STRING = wqsTestProperties.getUniqueTestDataString(); ADMIN_USERNAME = wqsTestProperties.getAdminUsername(); ADMIN_PASSWORD = wqsTestProperties.getAdminPassword(); DEFAULT_FREENET_USER = DEFAULT_USER + "@" + DOMAIN_FREE; DEFAULT_PREMIUMNET_USER = DEFAULT_USER + "@" + DOMAIN_PREMIUM; logger.info("Target URL: " + shareUrl); logger.info("Alfresco Version: " + alfrescoVersion); }
From source file:de.thischwa.pmcms.model.domain.PoInfo.java
public static String[] getTemplateNames(IRenderable renderable) { List<String> names = new ArrayList<String>(); for (Template template : getTemplates(getSite(renderable), renderable.getTemplateType())) names.add(template.getName());/*w w w . j ava 2s.co m*/ return names.toArray(new String[0]); }
From source file:org.spring.data.gemfire.AbstractGemFireIntegrationTest.java
protected static ServerLauncher startGemFireServer(final long waitTimeout, final String cacheXmlPathname, final Properties gemfireProperties) throws IOException { String gemfireMemberName = gemfireProperties.getProperty(DistributionConfig.NAME_NAME); String serverId = DATE_FORMAT.format(Calendar.getInstance().getTime()); gemfireMemberName = String.format("%1$s-%2$s", (StringUtils.hasText(gemfireMemberName) ? gemfireMemberName : ""), serverId); File serverWorkingDirectory = FileSystemUtils.createFile(gemfireMemberName.toLowerCase()); Assert.isTrue(FileSystemUtils.createDirectory(serverWorkingDirectory), String.format("Failed to create working directory (%1$s) in which the GemFire Server will run!", serverWorkingDirectory)); ServerLauncher serverLauncher = buildServerLauncher(cacheXmlPathname, gemfireProperties, serverId, DEFAULT_SERVER_PORT, serverWorkingDirectory); List<String> serverCommandLine = buildServerCommandLine(serverLauncher); System.out.printf("Starting GemFire Server in (%1$s)...%n", serverWorkingDirectory); Process serverProcess = ProcessUtils.startProcess( serverCommandLine.toArray(new String[serverCommandLine.size()]), serverWorkingDirectory); readProcessStream(serverId, "ERROR", serverProcess.getErrorStream()); readProcessStream(serverId, "OUT", serverProcess.getInputStream()); waitOnServer(waitTimeout, serverProcess, serverWorkingDirectory); return serverLauncher; }
From source file:jease.cms.service.Revisions.java
/** * Keeps only revisions for given content below given count and given days. * Returns number of purged revisions. Setting count or days to 0 means to * ignore it, -1 means unlimited./* ww w.ja va2 s .c o m*/ */ public static int purge(Content content, int count, int days) { if (count == -1 || days == -1 || content.getRevisions() == null) { return 0; } int revisionsBefore = content.getRevisions().length; long daysInPast = System.currentTimeMillis() - (days * 24L * 3600L * 1000L); List<Version> revisions = new ArrayList<Version>(); for (Version version : content.getRevisions()) { if ((count > 0 && revisions.size() < count) || (days > 0 && version.getBlob().getFile().lastModified() > daysInPast)) { revisions.add(version); } } content.setRevisions(revisions.toArray(new Version[] {})); return revisionsBefore - content.getRevisions().length; }