Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 561629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:28:11+00:00 2026-05-13T12:28:11+00:00

I’m implementing a high-order split function, which takes a collection of items to be

  • 0

I’m implementing a high-order split function, which takes a collection of items to be splitted, a filter delegate which defines the boundary criteria of the split, and two ReturnDelegate, which are delegates that provides the concrete collection type of the return collections (so I don’t need to fix ArrayList or HashSet in the split function, but rather, leaving the creation of the return collections to the calling code, yielding flexibility). The return is a Tuple2 class, which is basically a wrapper around two heterogeneous objects.

Here’s the split method:

public static <T, T1 extends Collection<T>, T2 extends Collection<T>>
    Tuple2<T1, T2> split(final Collection<T> coll,
                         final FilterDelegate<T> filterDelegate,
                         final FilterReturnDelegate<T1> truthyDelegate1,
                         final FilterReturnDelegate<T2> falsyDelegate2) {
    final Collection<T> t1 = truthyDelegate1.createReturnCollection();
    final Collection<T> t2 = falsyDelegate2.createReturnCollection();

    for (final T item : coll) {
        if (filterDelegate.filter(item)) {
            t1.add(item);
        } else {
            t2.add(item);
        }
    }

    final Tuple2<T1, T2> retval = new Tuple2<T1, T2>();
    retval.setItem1(t1);
    retval.setItem2(t2);

    return retval;
}

Here’s the Tuple2 class. It’s a simple generic-aware wrapper of heterogeneous objects.

public final class Tuple2<T1, T2> {

    private T1 _item1;

    private T2 _item2;

    public Tuple2() {
    }

    public Tuple2(final T1 item1, final T2 item2) {
        _item1 = item1;
        _item2 = item2;
    }

    public T1 getItem1() {
        return _item1;
    }

    public T2 getItem2() {
        return _item2;
    }

    public void setItem1(final T1 item1) {
        _item1 = item1;
    }

    public void setItem2(final T2 item2) {
        _item2 = item2;
    }

}

FilterDelegate:

public interface FilterDelegate<T> {

    /**
     *
     * @param item The item to be filtered.
     * @return true if the item should be retained. false if the item should be
     */
    boolean filter(T item);

}

FilterReturnDelegate:

public interface FilterReturnDelegate<R extends Collection<?>> {

    R createReturnCollection();

}

However, the above split method doesn’t even compile. Javac is complaining on the lines

retval.setItems(t1); retval.setItems(t2);

that "The method setItem1(T1) in the type Tuple2<T1,T2> is not applicable for the arguments (Collection<T>)".

Wondering what am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:28:11+00:00Added an answer on May 13, 2026 at 12:28 pm

    Your t1 and t2 should be of type T1 and T2:

    final T1 t1 = truthyDelegate1.createReturnCollection();
    final T2 t2 = falsyDelegate2.createReturnCollection();
    

    Collection<T> isn’t a subtype of T1, so setItem(t1) would fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 402k
  • Answers 402k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have to map him as domain\username, another way would… May 15, 2026 at 4:45 am
  • Editorial Team
    Editorial Team added an answer I found the answer myself. git config --add remote.origin.push +refs/heads/*:refs/MACHINENAME/* May 15, 2026 at 4:45 am
  • Editorial Team
    Editorial Team added an answer The first error sounds like your copy of feedparser.py is… May 15, 2026 at 4:45 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.