2015年06月

splint large project (hundreds of files)

I'm using Splint for a moderately large project. All is fine, but we are now trying to up the level from "weak" to "checks". Because we are checking files one by one, Splint complains about undefined functions. I seem to remember Splint had the option to analyse multiple files individually and then do a final analysis of all together (compile + link style).



I can't find any info on how to do this in the manual nor general Googling.



Is this possible?





Always true if entity framework

I have simple query. I want to get rows that don't have corresponding row in other table or if it have then SubField has to be false.



var list = ctx.Product.Where(p => p.Field == null || p.Field.SubField == false)


But with this query I always get all rows doesn't matter if p.Field is null. Even if I set second condition to p.Field.SubField== true I also get all rows.



I created simple MessageBoxes to see result:



MessageBox.Show((c.Field== null).ToString());
result = true;

MessageBox.Show((c.Field.SubField == false).ToString());
result = object is not set exception

MessageBox.Show((c.Field == null || c.Field.SubField == false).ToString());
result = true;


What I am doing wrong?



Answers

This is an example of C# short-cutting the query for you. When p.Field == null evaluates to true, there is no point attempting to look at the second part as it is part of an or expression. Consider this variation of your code, note that when Field is null, Console.WriteLine does not execute:



Setup:



public class Product
{
public Field Field { get; set; }
}

public class Field
{
public bool SubField { get; set; }
}

private bool GetSubField(Product product)
{
Console.WriteLine("GetSubField");
return product.Field.SubField;
}


Example execution:



var products = new List<Product>
{
new Product { Field = null }
};

var list = products.Where(p => p.Field == null || GetSubField(p) == false);




Cannot find file path - image

I am currently trying to send an image over FTP on Android.
I tried a lot of possible ways to accomplish that, and the same problem persists: I get an error telling that the path/directory/file doesn't exist.



My code right now is using the CameraSample from Xamarin and getting the picture taken from the camera and trying to send it over FTP. When I try to do that, I receive the error:




ENOENT (No such file or directory)




Here is the code:



protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);

// make it available in the gallery
Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
Uri contentUri = Uri.FromFile(_file);
System.Console.WriteLine (contentUri.ToString ());
mediaScanIntent.SetData(contentUri);
SendBroadcast(mediaScanIntent);

// display in ImageView. We will resize the bitmap to fit the display
// Loading the full sized image will consume to much memory
// and cause the application to crash.
int height = _imageView.Height;
int width = Resources.DisplayMetrics.WidthPixels;
using (Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height))
{
_imageView.RecycleBitmap ();
_imageView.SetImageBitmap(bitmap);
}

Thread t = new Thread ( () => UploadToFTP(contentUri.ToString()));
t.Start ();
}

private void UploadToFTP(String uri){
SimpleFTP ftp = new SimpleFTP ();
ftp.Connect("xxx.xxxxx.xxx", 21, "xxxxxxx", "xxxxxxxx");
ftp.Stor (new File(uri));
ftp.Disconnect();
}


Does anyone have an ideia what is happening? I've tried with assets/drawable/files etc. and nothing works. The image can be seen on the ImageView.



The path printed on the console is this one:




file:///storage/sdcard0/Pictures/CameraAppDemo/myPhoto_64ee3fec-08af-4bde-9214-62892b6d9f72.jpg




Thanks



EDIT:
I figured it out... The problem is the use of contentUri.ToString() instead of contentUri.Path, this latter the result is the correct and without the "file://" part, so it should be something like that:




/storage/sdcard0/Pictures/CameraAppDemo/myPhoto_64ee3fec-08af-4bde-9214-62892b6d9f72.jpg





What is the best language for HTML parsing and web scraping? [on hold]

What is the best language for HTML parsing and web scraping?



Would it be Jsoup on Java or Beautifulsoup on Python?





Scala set element uniqueness: What to implement for comparison of user defined classes?

I am trying to find this information in the Scala documentation but it looks like it is not there.



In the case of Java this was dependent of the Set implementation that was used, AFAIK. In some cases the method to implement was equals, in the case of a HashSet the comparison was done with the hash method.



The actual implementation details of scala.collections.mutable.Set seem to be unspecified, as the implementation may vary (and that's nice, I like my code to be generic), but I wonder how can I ensure specific comparisons are done with such a generic collection.



For example, in the case of SortedSet there is an implicit Ordering[A] to ensure the order. Is there anything similar in the case of Set?



Answers

Both scala and java require you to implement both equals and hashCode in a consistent way. If it worked with just one in some cases it's coincidental. You must have both so that with your class being X, for every X, x1.equals(x2) == (x1.hashCode() == x2.hashCode()).



Scala case classes have equals and hashCode methods implemented by the compiler for you.





↑このページのトップヘ