How to create a Hashmap in jasmin? - jasmin

I want to create a HashMap inside a class in a Jasmin, it's equivalent Java would be :
class grammar {
Hashmap <String, Integer> memory= new Hashmap <String, Integer>;
}
Something to do with
Ljava/util/HashMap
Any help would be appreciated

Related

Declare a Map<String, Object> as a scoped variable cause problem

When I declare a Map<String, Object> scoped variable in my SpringMVC project as below:
#Bean
#SessionScope
public Map<String, Object> allProjects() {
return new TreeMap<>();
}
It is weird that it contains many unexpected things even I didn't put anything into it. Just like it is the whole session scope. It will not happen if I declare it as Map<String, String>. Is there any formal statement in document talked about this?

Is it possible to define an abstract named constructor in Dart?

I'm trying to create an abstract class Firestorable which will ensure that subclasses override a named constructor fromMap(Map<String, dynamic> map)
The code looks like this ...
abstract class Firestorable {
/// Concrete implementations will convert their state into a
/// Firestore safe [Map<String, dynamic>] representation.
Map<String, dynamic> toMap();
/// Concrete implementations will initialize its state
/// from a [Map] provided by Firestore.
Firestorable.fromMap(Map<String, dynamic> map);
}
class WeaponRange implements Firestorable {
int effectiveRange;
int maximumRange;
WeaponRange({this.effectiveRange, this.maximumRange});
#override
WeaponRange.fromMap(Map<String, dynamic> map) {
effectiveRange = map['effectiveRange'] ?? 5;
maximumRange = map['maximumRange'] ?? effectiveRange;
}
#override
Map<String, int> toMap() {
return {
'effectiveRange': effectiveRange,
'maximumRange': maximumRange ?? effectiveRange,
};
}
}
I don't get any errors when I do this, however I also don't get a compile error when I leave out the concrete implementation of the fromMap(..) constructor.
For example the following code will compile without any errors:
abstract class Firestorable {
/// Concrete implementations will conver thier state into a
/// Firestore safe [Map<String, dynamic>] representation.
Map<String, dynamic> convertToMap();
/// Concrete implementations will initialize its state
/// from a [Map] provided by Firestore.
Firestorable.fromMap(Map<String, dynamic> map);
}
class WeaponRange implements Firestorable {
int effectiveRange;
int maximumRange;
WeaponRange({this.effectiveRange, this.maximumRange});
// #override
// WeaponRange.fromMap(Map<String, dynamic> map) {
// effectiveRange = map['effectiveRange'] ?? 5;
// maximumRange = map['maximumRange'] ?? effectiveRange;
// }
#override
Map<String, int> convertToMap() {
return {
'effectiveRange': effectiveRange,
'maximumRange': maximumRange ?? effectiveRange,
};
}
}
Am I not able to define an abstract named constructor and have it be a require implementation in a concrete class? If not, what would be the correct way to do this?
As stated in the official guide for the Dart Language constructors aren’t inherited so you can't enforce a factory constructor to subclasses. To ensure an implementation it should be part of the class' interface which constructors are not. You can check these related stackoverflow questions for more information:
How to declare factory constructor in abstract classes
How do i guarentee a certain named constructor in dart

How to parse settings object in ShellViewModel (Caliburn.Micro)

I have a Dictionary Object defined as below
Dictionary<string, object> dictArguments = new Dictionary<string, object>();
dictArguments.Add("CommandLine", strCommandLineArguments);
And then I am passing it ShellViewModel as below.
DisplayRootViewFor<ShellViewModel>(dictArguments);
Whereas I am at a loss to figure out how and where ShellViewModel parses this argument because as far as Caliburn is concerned ShellViewModel has a single CTOR with ieventAggregator. Any pointers please?
Thanks,
Deepak
The parameter for DisplayRootViewFor accepts Windows Settings as dictionary. So for example,
Dictionary<string, object> dictArguments = new Dictionary<string, object>();
dictArguments.Add("Height", 1000);
dictArguments.Add("Width", 1500);
dictArguments.Add("ShowInTaskbar", false);
dictArguments.Add("WindowStartupLocation", WindowStartupLocation.CenterScreen);
DisplayRootViewFor<ShellViewModel>(dictArguments);
These settings would influence the Height,Width,ShowInTaskbar and WindowStartupLocation properties of your View (Caliburn Micro does that for, you do not need to do it manually).
I do not think this is useful for the storing CommandLine argument.

JacksonMapping Polymorphic

I am trying to parse json structure https://developers.nest.com/documentation/api-reference
Where device could be various types i want jackson to instantiate relevant objects Thermostat/SmokeAlarm,Camera etc
#Data
#ToString
public class Nest {
#JsonProperty("metadata")
private Metadata metadata;
#JsonProperty("structures")
private HashMap<String, Structure> structures;
#JsonProperty("devices")
private HashMap<String, HashMap<String, Device>> devices;
}
How would i use#JsonTypeinfo to decided which type to instatntite based on values in keys.
Another question would be how woul i get rid of all these multilevel nestings and cal have something like
#JsonProperty("devices")
private List<Device> devices;
parsed according to keys/subtypes

Seam 3 - retrieve all seam components in application context

is there a way to get all the Seam 3 component classes which are #ApplicationScoped?
Didn't try myself, just a guess after reading 16.5. The Bean interface chapter of Weld documentation
class ApplicationScopedBeans {
#Inject BeanManager beanManager;
public Set<Bean<?>> getApplicationScopedBeans() {
Set<Bean<?>> allBeans = beanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {});
Set<Bean<?>> result = new HashSet<Bean<?>>();
for(Bean<?> bean : allBeans) {
if(bean.getScope().equals(ApplicationScoped.class)) {
result.add(bean);
}
}
return result;
}
}
UPDATE
To obtain an instance of a Bean:
public Object getApplicationScopedInstance(Bean<?> bean) {
CreationalContext ctx = beanManager.createCreationalContext(bean);
Context appCtx = beanManager.getContext(ApplicationScoped.class);
return appCtx.get(bean, ctx);
}
UPDATE 2
Looks like all above misses the whole point of CDI :)
class ApplicationScopedBeans {
#Inject #ApplicationScoped Instance<Object> appScopedBeans;
}
if you want to call a method from a component in applicationContext or use a field in this, it's better that u define it as producer method or field and inject it where u want.
You would use getApplicationContext() to get the context, and then the getNames() to get all names of things that are application scope, and then you would use get()to retrieve them by name.
What are you trying to do? From there you would have to use reflection to get them to the right type..
Context appContext = Contexts.getApplicationContext();
String [] names = appContext.getNames();
//Do whatever with them..
for(String s : names){
Object x = appContext.get(name);
// do something.
}

Resources