Nested Map or multi-key example Chronicle Map - multimap

I have a use case where I want to create a co-occurrence matrix. Essentially it is going to be something like Map<String, Map<String, Long>>. I wish to use Chronicle-Map for this task.
I checked Multimaps in ChronicleMap and https://github.com/OpenHFT/Chronicle-Map/issues/100. However, I am unable to follow the discussion to make a suitable change.
It would be also okay to have it like a multi-key like Map<String, String, Long> . I looked up the graph example of add and remove edge (in chronicle-map tutorial) which was again too detailed and complicated for me to adapt to my setting.
The way this will be used is to query:
Getting the long value for a very specific combination if key1 and key2.
For a specific key1 return all the key2 along with their respective long value.
Can someone please advise and provide a simple working example.

You need to create a MapMarshaller based on the source of SetMarshaller (yes, it's going to be even more complicated). Or use a Pair<String, String> as a key.

Related

What does "urSoBasic" means in CAAnimation?

I'm trying to implement some animation via CAAnimation, So I'm finding some references via google.
And I found so many examples are achieve the goal using String "urSoBasic" as a key, like below:
shapeLayer.add(basicAnimation, forKey: "urSoBasic")
The developer documents describing about special key "transition", only about key has to be unique.
Briefly, Is there any function of the key "urSoBasic"? or It's just about convention?
It's confusing.
I want to know what exactly "urSoBasic" means.
The key "urSoBasic" is a joke or a play on words. "urSoBasic" -> "you are so basic". Someone was being cute when they named their basic animation key as "urSoBasic". And then it got copied and pasted a bunch which is why you might find it in various search results.
The value of the forKey: parameter is an arbitrary string that only has meaning to you and your code. It's not even required.
From the documentation for the CALayer add(_:forKey:) method:
A string that identifies the animation. Only one animation per unique key is added to the layer. The special key kCATransition is automatically used for transition animations. You may specify nil for this parameter.
tl;dr - "urSoBasic" has no special meaning that would affect the functionality of the code.

Telerik Kendo Chart : How to bind the chart to a string type

I've been stuggling for a moment and I'm unable to find anything related to that. I'm a total newbie with Kendo, and sadly I was not able to find anything that could help my question, documentation, forums and all of that : they haven't helped at all.
Situation :
I have a viewmodel in my ASP .NET app. I'm trying to make a chart out of one of the proripeties called "Type". This propriety represent a type of data - let's say fruits, like "Banana", "Apple" etc.
This type contains only and only one type at the time. It cannot contain something like "Apple and bananas". It's always a string, too.
This proriety is part of a larger model. But I'm only interested in this one.
Now, what I like to do :
I'd like to make a chart, using Kendo, from that propriety.
That means, I have to bind my chart to my model, and then, it will be able to know how many time some of those Types were used.
Like, example, If I have three objects :
Name : "Mjuzl"
Type : "Potato"
Name : "Uijqf"
Type : "Apple"
Name : "Zjli"
Type : Potato"
I'd like my char to count that my model used the type Potato twice, and the type Apple once.
I know how to get my datasource that contain all of the objects that use my model. (I have already used Kendo Grid just before but it's so simplier tbh) My issue right now, is that I have no idea - and I wasnt' able to find any - how to actually display what I want in my chart. I say it again, they are strings. I know how to get my datasource. I don't know how to actually show what I want to show. (Should I use columns ? sections ? I don't know)
Do I need to build a JSON from my controller that will ask the database to count ? Does Kendo is able to do it by it's own ? I'm so lost, I have no idea what Kendo is actually waiting for to make my chart working. The documentation isn't helping at all. I've been researching for a while, I haven't found anything that describes the exact same problem. And I've been searching for days.
Very badly drawn image I've done to put a picture on my problem :
I don't ask to do it for me, I ask for a path. A way to do it.
Thanks.
One way would be to create a view model specifically for your chart, and you can populate that view model based on your data.
Roughly (untested code - just to give you an idea), something like this:
public class MyChartViewModel
{
public int TypeCount { get; set; }
public string TypeName { get; set; }
}
and then in your read method for the chart where you are populating MyChartViewModel:
var myExistingDataModel = howeverYouGetYourDataHere;
var model = new MyChartViewModel();
var distinctTypes = myExistingDataModel.Select(x => x.Type).Distinct().ToList();
foreach (var distinctType in distinctTypes)
{
model.TypeCount = myExistingDataModel.Count(x => x.Type == distinctType);
model.TypeName = distinctType;
}
Finally ! I managed to do it !
For any future reference :
Based on G_P's answer, I used a LINQ request to count all of my types : Linq distinct - Count (don't forget to remove the .District() otherwise I won't work !)
Then, I did some debuging to see if I actually return my data, because nothing was showing in the chart. It did return my data and the right number.
The issue for this case was, I use
return Json(types.ToDataSourceResult(request, ModelState));
To return my data to my chart. But ! there is a little thing to know about Chart, they don't work like grids. You have to use a specific setup for showing your data if you use ToDataSourceResult : https://docs.telerik.com/aspnet-mvc/html-helpers/charts/data-binding (See "3) (Optional) Configure a Custom DataSource."), just change the call to your controller, and voilĂ  ! It worked !

Any reason for URLEncodedUtils.parse return List< NameValuePair >

https://hc.apache.org/httpcomponents-client-4.3.x/httpclient/apidocs/org/apache/http/client/utils/URLEncodedUtils.html#parse(java.net.URI,%20java.lang.String)
why not return Map< String, List< String > >
if it returns Map, user can easily query by key to get whatever they want.
otherwise user should iterator the whole list to find what they want.
Thanks
Because this is a list. If you read carefully the explanation, says:
Returns a list of NameValuePairs as built from the URI's query portion. For example, a URI of http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three NameValuePairs, one for a=1, one for b=2, and one for c=3.
That means that you cannot use a list to acces by value, because these type of data structures aren't designed for that. They doesn't have any "key" to use.
In this website, Jon Skeet wrote a very clear answer about you cannot use a shortcut to acces a List<NameValuePair> value using a name or a key or for similar structures.
Here you can check the post: Get ArrayList<NameValuePair> value by name
Inside of the same post, you'll see different options to solve your problem. (Or could guide to you to find the solution)

GWT JSONObject adding an additional incorrect key when converting overlay type to json string

I'm encountering the following problem - I have simple GWT overlay types, and I'm trying to convert one to a JSON string on the client; I'm simply doing:
new JSONObject(this).toString();
The conversion works, but it adds an additional, incorrect key to the json string, such as:
{"key1":"value1", "key2":value2, "$H":1}
where "$H":1 doesn't correspond to anything in my overlay type.
Any idea why this is?
Any help is appreciated on this, thanks.
This issue is define in this link
The $H property comes from the
implementation of
JavaScriptObject#hashCode() (in
com.google.gwt.cire.client.impl.Impl#getHashCode(Object)).
In your case, this is due to
AbstractEditableCell maintaining a map
of value keys to their "view data",
and your use (I guess) of the default
ProvidesKey implementation
(SimpleProvidesKey) which directly
returns the item.
So, when rendering, the EditTextCell
calls getViewData, which looks up the
key in the map (and thus needs the
hashcode of the key, hence the call to
hashCode), and the key is your JSO
(hence the new $H property).
I believe that giving a ProvidesKey
implementation (in you case, returning
the name property for instance) to the
Celltable would solve your issue.

Code re-use with Linq-to-Sql - Creating 'generic' look-up tables

I'm working on an application at the moment in ASP.NET MVC which has a number of look-up tables, all of the form
LookUp {
Id
Text
}
As you can see, this just maps the Id to a textual value. These are used for things such as Colours. I now have a number of these, currently 6 and probably soon to be more.
I'm trying to put together an API that can be used via AJAX to allow the user to add/list/remove values from these lookup tables, so for example I could have something like:
http://example.com/Attributes/Colours/[List/Add/Delete]
My current problem is that clearly, regardless of which lookup table I'm using, everything else happens exactly the same. So really there should be no repetition of code whatsoever.
I currently have a custom route which points to an 'AttributeController', which figures out the attribute/look-up table in question based upon the URL (ie http://example.com/Attributes/Colours/List would want the 'Colours' table). I pass the attribute (Colours - a string) and the operation (List/Add/Delete), as well as any other parameters required (say "Red" if I want to add red to the list) back to my repository where the actual work is performed.
Things start getting messy here, as at the moment I've resorted to doing a switch/case on the attribute string, which can then grab the Linq-to-Sql entity corresponding to the particular lookup table. I find this pretty dirty though as I find myself having to write the same operations on each of the look-up entities, ugh!
What I'd really like to do is have some sort of mapping, which I could simply pass in the attribute name and get out some form of generic lookup object, which I could perform the desired operations on without having to care about type.
Is there some way to do this to my Linq-To-Sql entities? I've tried making them implement a basic interface (IAttribute), which simply specifies the Id/Text properties, however doing things like this fails:
System.Data.Linq.Table<IAttribute> table = GetAttribute("Colours");
As I cannot convert System.Data.Linq.Table<Colour> to System.Data.Linq.Table<IAttribute>.
Is there a way to make these look-up tables 'generic'?
Apologies that this is a bit of a brain-dump. There's surely imformation missing here, so just let me know if you'd like any further details. Cheers!
You have 2 options.
Use Expression Trees to dynamically create your lambda expression
Use Dynamic LINQ as detailed on Scott Gu's blog
I've looked at both options and have successfully implemented Expression Trees as my preferred approach.
Here's an example function that i created: (NOT TESTED)
private static bool ValueExists<T>(String Value) where T : class
{
ParameterExpression pe = Expression.Parameter(typeof(T), "p");
Expression value = Expression.Equal(Expression.Property(pe, "ColumnName"), Expression.Constant(Value));
Expression<Func<T, bool>> predicate = Expression.Lambda<Func<T, bool>>(value, pe);
return MyDataContext.GetTable<T>().Where(predicate).Count() > 0;
}
Instead of using a switch statement, you can use a lookup dictionary. This is psuedocode-ish, but this is one way to get your table in question. You'll have to manually maintain the dictionary, but it should be much easier than a switch.
It looks like the DataContext.GetTable() method could be the answer to your problem. You can get a table if you know the type of the linq entity that you want to operate upon.
Dictionary<string, Type> lookupDict = new Dictionary<string, Type>
{
"Colour", typeof(MatchingLinqEntity)
...
}
Type entityType = lookupDict[AttributeFromRouteValue];
YourDataContext db = new YourDataContext();
var entityTable = db.GetTable(entityType);
var entity = entityTable.Single(x => x.Id == IdFromRouteValue);
// or whatever operations you need
db.SubmitChanges()
The Suteki Shop project has some very slick work in it. You could look into their implementation of IRepository<T> and IRepositoryResolver for a generic repository pattern. This really works well with an IoC container, but you could create them manually with reflection if the performance is acceptable. I'd use this route if you have or can add an IoC container to the project. You need to make sure your IoC container supports open generics if you go this route, but I'm pretty sure all the major players do.

Resources