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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:14:32+00:00 2026-05-24T01:14:32+00:00

given: class Widget { Object value; } interface WidgetMap { void put( Widget key,

  • 0

given:

class Widget {
    Object value;
}

interface WidgetMap {
    void put( Widget key, Widget value );
    Widget get( Widget key );
}

… how would I go about implementing WidgetMap using only Widget objects or primitives?
Without the use of other classes (toolkits, collections, JDK classes ). Primitive arrays would be allowed, but it would be better to do without them.

  • 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-24T01:14:33+00:00Added an answer on May 24, 2026 at 1:14 am

    This is a map implemented as a linked list of WidgetMap. It doesn’t strike me as terribly efficient, or useful, but it should function. I assume you also want a remove function, but I’ll leave that as an exercise. This also assumes you appropriately override the Widget.equals function, though it should be trivial to fix it not to have that requirement.

    class BadMap implements WidgetMap{
    
        private WidgetMap next = null;
        private Widget key = null;
        private Widget val = null;
    
        public void put(Widget _key, Widget _value){
            if(key == null){
                key = _key;
                val = _value;
            }else if(key.equals(_key)){
                val = _value;
            }else if(next != null){
                next.put(_key, _value);
            }else{
                next = new BadMap();
                next.put(_key, _value);
            }
        }
    
        public Widget get(Widget _key){
            if(key != null && key.equals(_key)){
                return val;
            }else if(next != null){
                return next.get(_key);
            }else{
                return null;
            }
        }
    
    }
    

    Working example code.

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

Sidebar

Related Questions

For a given class I would like to have tracing functionality i.e. I would
For a file containing the given class, SomeCoolClass, what would be the proper or
Using __PACKAGE__->meta->get_attribute('foo') , you can access the foo attribute definitions in a given class,
Following class structure is given: class Job { String description; Collection<JobHistory> history; } class
Is there any possibility that GetPropInfo returns nil even if the given class is
Does anyone know a way to auto-generate database tables for a given class? I'm
My problem is thus: I need a way to ensure only one given class
Given this class class Foo { // Want to find _bar with reflection [SomeAttribute]
Given a class instance, is it possible to determine if it implements a particular
Given a class, org.eclipse.ui.views.navigator.ResourceNavigator for example, how do I find out which jar file

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.