Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve HashMap support #2

Open
PerfectCarl opened this issue Aug 26, 2012 · 2 comments
Open

Improve HashMap support #2

PerfectCarl opened this issue Aug 26, 2012 · 2 comments

Comments

@PerfectCarl
Copy link

Hello,

I'm evaluating sharpen and I found areas where this usefull could use some enhancements : hashmap.
I found some basic use cases with Hashmaps that weren't working.
Namely, the method get, put and EntrySet are not defined.

I don't know what the solution should be :

  • update the plugin code to deal with it
  • add some redirections in the configuration files
  • add missing methods with Extension methods (?)

Please find below a sample java program and the produced C# file with the compilation errors noted in comments.

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Map<String, String> cities = new HashMap<String, String>();
        cities.put("France", "Paris");
        cities.put("Germany", "Berlin");
        cities.put("Spain", "Madrid");

        String capital = cities.get("France");
        // One way to iterate
        System.out.println("With iterator");
        Iterator it = cities.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pairs = (Map.Entry) it.next();
            System.out.println(pairs.getKey() + " = " + pairs.getValue());
        }

        System.out.println("\nWith entrySet");
        // Another one
        for (Map.Entry<String, String> entry : cities.entrySet()) {
            System.out.println("Key = " + entry.getKey() + ", Value = "
                    + entry.getValue());
        }

        System.out.println("\nWith keys");
        for (String key : cities.keySet()) {
            System.out.println(key + " = " + cities.get(key));
        }

    }

}

Output :

using System.Collections;
using System.Collections.Generic;
using Sharpen;

public class TestProgram
{
    /// <param name="args"></param>
    public static void TestMain(string[] args)
    {
        IDictionary<string, string> cities = new Dictionary<string, string>();
        // *** ERROR Method Put undefined
        cities.Put("France", "Paris");
        cities.Put("Germany", "Berlin");
        cities.Put("Spain", "Madrid");
        string capital = cities.Get("France");
        // One way to iterate
        System.Console.Out.WriteLine("With iterator");
        // *** ERROR EntrySet undefined
        Iterator it = cities.EntrySet().Iterator();
        while (it.HasNext())
        {
            DictionaryEntry pairs = (DictionaryEntry)it.Next();
            System.Console.Out.WriteLine(pairs.Key + " = " + pairs.Value);
        }
        System.Console.Out.WriteLine("\nWith entrySet");
        // Another one
        // *** ERROR EntrySet undefined
        foreach (KeyValuePair<string, string> entry in cities.EntrySet())
        {
            System.Console.Out.WriteLine("Key = " + entry.Key + ", Value = " + entry.Value);
        }
        System.Console.Out.WriteLine("\nWith keys");
        foreach (string key in cities.Keys)
        {
            // *** ERROR Method Get undefined
            System.Console.Out.WriteLine(key + " = " + cities.Get(key));
        }
    }
}
@PerfectCarl
Copy link
Author

Well, the code is already set up in the Extensions classes (Extensions.cs), but the class being internal, the extensions are note registered.

So, all you need is to update the Extensions class visibility to public (and do so with all the related classes), and you're good to go...

Why are most of the classes in the Sharpen project internal by default ?

@cureos
Copy link

cureos commented Aug 27, 2012

I cannot say for sure why the Sharpen C# classes are internal by default, since I have "shamelessly" copied them from the NGit project, but my guess is that the original intention was that these classes should be incorporated in the same library as the C# application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant