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

  • Home
  • SEARCH
  • 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 6679049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:18:51+00:00 2026-05-26T04:18:51+00:00

This is for a school project. I have a Query<E> class that holds an

  • 0

This is for a school project. I have a Query<E> class that holds an element that is part of the Query condition. So if it’s a GreaterQuery and the element is 10, all values greater than 10 pass the condition.

The constructor of this Query object takes the element, and a Comparator object to be used to test the condition. If null is passed in, I need to create a Comparator to use for the comparison.

I have a match(E element) method that tests the condition. Here’s bare bones version of it:

public boolean matches(E element)
{
    if (comparator == null)
    {

    }
}

What I thought I could do was write an anonymous Comparator class inside the if statement, though I’m not sure if that’s even possible. The other problem I’m having is how to even compare to E objects without knowing anything about them. Also, I’m not sure of this, but there may be a pre condition that E extends Comparable. It’s very late and I apologize if this makes no sense. But any help will be appreciated.

  • 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-26T04:18:52+00:00Added an answer on May 26, 2026 at 4:18 am

    If E is guaranteed to implement Comparable<E>, you can do this:

    if (comparator == null) {
        comparator = new Comparator<E>() {
            @Override
            public int compare(E lhs, E rhs) {
                return lhs.compareTo(rhs);
            }
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this library, ZXing , we have a project at school in which we'll
I have this project for school where i have to populate a drop down
First of all, I'll admit this is a school project, so I need more
I have a school project and i want to dedicate this for New Year,
I hope, this question is not too offtopic. I have a bigger school project
I have this school project I'm making, where I need to make my code
For a school project we have to create an evaluation website that requires a
I am building a simple ajax chat client for a school project and have
I am making a fraction class for a school project, and my brain is
I have a new web app that is packaged as a WAR as part

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.