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 1002243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:48:13+00:00 2026-05-16T07:48:13+00:00

I want to have a Sorted map as follows: srcAddr, dstAddr, srcPort, dstPort, protocol

  • 0

I want to have a Sorted map as follows:

srcAddr, dstAddr, srcPort, dstPort, protocol as keys

and a List of values as

packetLength, timeArrival for each key.

Is it possible to implement them in separate classes? I am confused if it will work this way.

Update:

I am getting an error indicating im not overriding abstract method compareTo(). Can you help me with it?

package myclassifier;
import java.io.Serializable;
import java.util.*;

public class Flows implements Serializable, Comparable {

    String srcAddr, dstAddr, srcPort, dstPort, protocol;

    public int compareTo(Flows other) {
        int res = this.srcAddr.compareTo(other.srcAddr);
        
        if (res != 0) {
            return res;
        }
        
        res = this.dstAddr.compareTo(other.dstAddr);
        if (res != 0) {
            return res;
        }
        
        res = this.srcPort.compareTo(other.srcPort);
        if (res != 0) {
            return res;
        }
        
        res = this.dstPort.compareTo(other.dstPort);
        if (res != 0) {
            return res;
        }
        
        return this.protocol.compareTo(other.protocol);

      
    }

    @Override
    public int hashCode() {

        final int prime = 31;
        int result = 1;
        result = prime * result + ((dstAddr == null) ? 0 : dstAddr.hashCode());
        result = prime * result + ((dstPort == null) ? 0 : dstPort.hashCode());
        result = prime * result + ((srcAddr == null) ? 0 : srcAddr.hashCode());
        result = prime * result + ((srcPort == null) ? 0 : srcPort.hashCode());
        return result;

    }


    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;

        if (getClass() != obj.getClass())
            return false;

        Flows other = (Flows) obj;
        
        if (dstAddr == null) {
            if (other.dstAddr != null)
                return false;
        } else if (!dstAddr.equals(other.dstAddr))
            return false;

        if (dstPort == null) {
            if (other.dstPort != null)
                return false;
        } else if (!dstPort.equals(other.dstPort))
            return false;

        if (srcAddr == null) {
            if (other.srcAddr != null)
                return false;
        } else if (!srcAddr.equals(other.srcAddr))
            return false;

        if (srcPort == null) {
            if (other.srcPort != null)
                return false;
        } else if (!srcPort.equals(other.srcPort))
            return false;

        return true;
    }

}
  • 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-16T07:48:14+00:00Added an answer on May 16, 2026 at 7:48 am

    You can write a, say a ‘MyKey’ class with srcAddr, dstAddr, srcPort, dstPort and protocol as member variables of it. You have to carefully override the equals and hashCode method of this class. Also this class has to implement the Comparable interface to indicate how your ordering will be determined based on member fields.

    You can implement a class MyValue to have packetLength, timeArrival etc as members. This will be the value you want to store in your map.

    Use TreeMap to store MyValue against MyKey.

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

Sidebar

Related Questions

I have a sorted map and want to reference its ordered objects by their
I have a application and I want to show the contacts are sorted by
I have a number of large sorted sets (5m-25m) in Redis and I want
I have a array with users sorted by score. I only want to output
I have a list of numbers, for example: list=[10,50,90,60] I want to sorte the
I have got a std::list< std::pair<std::string,double> > , which I know is sorted according
I have some objects in an array and want to have them sorted. The
I am trying to implement a sorted list. I have created the class I
I have a Map<byte[], Element> and I want to sort it and write it
I have a sorted sequence and want to go through it and return the

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.