CACI (UK)
2.9 of 5 24 reviews
www.caci.co.uk London, United Kingdom 500 to 999 Employees

CACI (UK) Software Technical Lead (Java) Interview Question

I interviewed in Saint Louis, MO and was asked:
"Write an AscendingSortedLongList and DescendingSortedLongList class ... and write some JUnit classes associated with them ..."
Tags: java
Add Tags [?]
Answer Flag Question

Part of a Software Technical Lead (Java) Interview Review - one of 9 CACI (UK) Interview Reviews

Answers & Comments

0
of 0
votes
package sortedlist;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Highly inefficient implementation of a sorted long list.
 */
public class AscendingSortedLongList implements SortedLongList {
    protected ArrayList<Long> list;

    public AscendingSortedLongList() {
        this(new ArrayList<Long>());
    }

    public AscendingSortedLongList(List<Long> initialList) {
        this.list = new ArrayList<Long>(initialList);
        sort();
    }

    protected void sort() {
        Collections.sort(this.list);
    }

    public void add(Long item) {
        this.list.add(item);
        sort();
    }

    public int getPositionOf(Long item) {
        return this.list.indexOf(item);
    }

    public Long get(int position) {
        try {
            return this.list.get(position);
        } catch (IndexOutOfBoundsException e) {
            return null;
        }
    }

    public int length() {
        return this.list.size();
    }

    public void printSortedContents() {
        System.out.print(">");
        boolean comma = false;
        for (Long longValue : this.list) {
            if (comma) {
                System.out.print("," + longValue);
            } else {
                System.out.print(longValue);
                comma = true;
            }
        }
        System.out.println();
    }

    public SortedLongList reverseSort() {
        return new DescendingSortedLongList(this.list);
    }
}
- Interview Candidate on Feb 20, 2012 Flag Response

To comment on this question, Sign In with Facebook or Sign Up


Tags are like keywords that help categorize interview questions that have something in common.

Glassdoor is your free inside look at CACI (UK) interview questions and advice. All interview reviews posted anonymously by CACI (UK) employees and interview candidates.