Example usage for org.apache.commons.collections.iterators ArrayIterator hasNext

List of usage examples for org.apache.commons.collections.iterators ArrayIterator hasNext

Introduction

In this page you can find the example usage for org.apache.commons.collections.iterators ArrayIterator hasNext.

Prototype

public boolean hasNext() 

Source Link

Document

Returns true if there are more elements to return from the array.

Usage

From source file:com.likya.myra.jef.utils.JobQueueOperations.java

public static HashMap<String, JobImpl> transformJobQueue(JobListDocument jobListDocument) {

    HashMap<String, JobImpl> jobQueue = new HashMap<String, JobImpl>();

    Object[] objectArray = jobListDocument.getJobList().getGenericJobArray();

    ArrayIterator jobArrayIterator = new ArrayIterator(objectArray);

    while (jobArrayIterator.hasNext()) {

        AbstractJobType abstractJobType = (AbstractJobType) jobArrayIterator.next();

        JobImpl jobImpl = transformJobTypeToImpl(abstractJobType);

        CoreFactory.getLogger().info(/*from w w  w . j a  va  2 s  .c  om*/
                "Transformed " + abstractJobType.getHandlerURI() + " Job Id : " + abstractJobType.getId());

        jobQueue.put(abstractJobType.getId(), jobImpl);
    }

    return jobQueue;
}

From source file:au.com.dw.testdatacapturej.reflection.MetadataGenerationHandler.java

/**
 * The handler for array classes. Determines the type of objects
 * inside the array and passes them to the appropriate handler.
 * //  www  . j a va  2 s  . c  o m
 * @param array
 * @throws IllegalAccessException
 */
protected void handleArray(ObjectInfo info) throws IllegalAccessException {
    ArrayIterator iter = new ArrayIterator(info.getValue());
    int index = 0;
    ContainmentType elementType = ContainmentType.ARRAY_ELEMENT;

    // handle each array element
    while (iter.hasNext()) {
        Object elementObject = iter.next();

        ObjectInfo elementInfo = new ObjectInfo();

        // increment the array index so each array element can later be assigned to successive array slots
        elementInfo.setIndex(index++);

        if (elementObject != null) {
            elementInfo.setValue(elementObject);
            elementInfo.setContainingClassFieldName(info.getClassFieldName());
            elementInfo.getConstructorInfo().setHasDefaultConstructor(hasDefaultConstructor(elementObject));
            // no need to check for setter since is an element of an array, so would be assigned instead
            elementInfo.getSetterAdderInfo().setHasSetter(false);

            if (TypeUtil.isJavaClass(elementObject)) {
                elementInfo.setType(ObjectType.SIMPLE);
                elementInfo.setContainmentType(elementType);

                elementInfo.setClassName(elementObject.getClass().getName());
                elementInfo.setClassFieldName(BuilderUtil.createClassFieldName(elementObject, null, null));
            } else if (TypeUtil.isArray(elementObject)) {
                elementInfo.setType(ObjectType.ARRAY);
                elementInfo.setContainmentType(elementType);

                // special handling for array class names
                elementInfo.setClassName(ReflectionUtil.getArrayClassName(elementObject));
                String arrayType = elementObject.getClass().getComponentType().getName();
                elementInfo.setClassFieldName(BuilderUtil.createArrayClassFieldName(arrayType, null, null));

                handleArray(elementInfo);
            } else if (TypeUtil.isMap(elementObject)) {
                elementInfo.setType(ObjectType.MAP);
                elementInfo.setContainmentType(elementType);

                elementInfo.setClassName(elementObject.getClass().getName());
                elementInfo.setClassFieldName(BuilderUtil.createClassFieldName(elementObject, null, null));

                handleMap(elementInfo);
            } else if (TypeUtil.isCollection(elementObject)) {
                elementInfo.setType(ObjectType.COLLECTION);
                elementInfo.setContainmentType(elementType);

                elementInfo.setClassName(elementObject.getClass().getName());
                elementInfo.setClassFieldName(BuilderUtil.createClassFieldName(elementObject, null, null));

                handleCollection(elementInfo);
            } else {
                elementInfo.setType(ObjectType.OBJECT);
                elementInfo.setContainmentType(elementType);

                elementInfo.setClassName(elementObject.getClass().getName());
                elementInfo.setClassFieldName(BuilderUtil.createClassFieldName(elementObject, null, null));

                handleFields(elementInfo);
            }
        } else {
            elementInfo.setType(ObjectType.SIMPLE);
            elementInfo.setContainmentType(elementType);
        }

        // add the link between the array and each element
        elementInfo.setParentInfo(info);
        info.addFieldToList(elementInfo);
    }
}

From source file:org.jenkinsci.plugins.aptly.AptlyPublisher.java

/**
 * {@inheritDoc}//from  w w w  . ja  v a2 s  . c  om
 *
 * @param build
 * @param launcher
 * @param listener
 * @return
 * @throws InterruptedException
 * @throws IOException
 *           {@inheritDoc}
 * @see hudson.tasks.BuildStep#perform(hudson.model.Build, hudson.Launcher, hudson.model.BuildListener)
 */
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
        throws InterruptedException, IOException {

    listener.getLogger().println("Perform AptlyPublisher ");
    if (skip != null && skip) {
        listener.getLogger().println("Publish built packages via Aptly - Skipping... ");
        return true;
    }

    if (build.getResult() == Result.FAILURE || build.getResult() == Result.ABORTED) {
        // build failed
        return true;
    }

    Map<String, String> envVars = build.getEnvironment(listener);

    AptlySite aptlysite = null;
    aptlysite = getSite();
    listener.getLogger().println("Using aptly site: " + aptlysite.getHostname());
    listener.getLogger().println("Port " + aptlysite.getPort());
    listener.getLogger().println("Username " + aptlysite.getUsername());
    listener.getLogger().println("Timeout " + aptlysite.getTimeOut());

    AptlyRestClient client = new AptlyRestClient(listener.getLogger(), aptlysite.getHostname(),
            Integer.parseInt(aptlysite.getPort()), aptlysite.getTimeOut(), aptlysite.getUsername(),
            aptlysite.getPassword());

    try {
        String result = client.getAptlyServerVersion();
        listener.getLogger().println("Aptly API version response: " + result);
    } catch (Throwable th) {
        th.printStackTrace(listener.error("Failed to connect to the server"));
        build.setResult(Result.UNSTABLE);
        return false;
    }
    List<PackageItem> itemlist = getPackageItems();
    for (PackageItem i : itemlist) {
        String uploaddirid = envVars.get("JOB_NAME") + "-" + envVars.get("BUILD_NUMBER") + "-"
                + UUID.randomUUID().toString().substring(0, 6);
        // Creating a temp dir for copying the remote files
        File tempDir = File.createTempFile("aptlyplugin", null);
        tempDir.delete();
        tempDir.mkdirs();

        FilePath workspace = new FilePath(launcher.getChannel(), build.getWorkspace().getRemote());
        //expand the macros like ${BUILD_NUM}
        String expanded = Util.replaceMacro(i.getSourceFiles(), envVars);
        //expand the file globs
        FilePath[] remoteFiles = workspace.list(expanded);
        if (remoteFiles.length == 0) {
            listener.getLogger().println("No matching file found to upload in: " + expanded);
            build.setResult(Result.UNSTABLE);
            return false;
        }
        //copy the remote file into the local dir, collect all of the
        // filepaths into 'filelist', and pass the list for uploading
        ArrayIterator filesiterator = new ArrayIterator(remoteFiles);
        List<File> filelist = new ArrayList<File>();
        while (filesiterator.hasNext()) {
            FilePath filepath = (FilePath) filesiterator.next();
            if (filepath.isRemote()) {
                FilePath localfilepath = new FilePath(new FilePath(tempDir), filepath.getName());
                filepath.copyTo(localfilepath);
                filepath = localfilepath;
            }
            File file = new File(filepath.toURI());
            listener.getLogger().println("Found file to upload: " + file.toString());
            //this is already ensured to be a local and absoulute path
            filelist.add(file);
        }
        try {
            client.uploadFiles(filelist, uploaddirid);
        } catch (Throwable th) {
            th.printStackTrace(listener.error("Failed to upload files"));
            build.setResult(Result.UNSTABLE);
        } finally {
            try {
                FileUtils.deleteDirectory(tempDir);
            } catch (IOException e) {
                try {
                    FileUtils.forceDeleteOnExit(tempDir);
                } catch (IOException e1) {
                    e1.printStackTrace(listener.getLogger());
                }
            }
        }

        // ################### ADD THE PACKAGES TO THE REPO  ###############
        try {
            client.addUploadedFilesToRepo(i.getRepositoryName(), uploaddirid);
        } catch (Throwable th) {
            th.printStackTrace(listener.error("Failed to upload files"));
            build.setResult(Result.UNSTABLE);
            return false;
        }

        // ################### UPDATE THE PUBLISHED REPO ###################
        try {
            client.updatePublishRepo(i.getPrefixName(), i.getDistributionName());
        } catch (Throwable th) {
            th.printStackTrace(listener.error("Failed to upload files"));
            build.setResult(Result.UNSTABLE);
            return false;
        }
    }
    return true;
}