我正在尝试计算我的Hashtable的加载因子并打印出结果。但是,当我运行它时,加载因子等于2.这是我的地图的大小 - 所以我的方法loadFactor不是很有效。有什么明显的东西我不见了吗? (我对Java很新)
- (BOOL) warningAlert:(NSString* )messageText informText:(NSString*)informText {
// Displays a fading, then self-dismissing view within the top level window
__block NSInteger alertReturn = 0; // __block, so it can be accessed by the completion blocks
// Define the alert
NSAlert* __block generalAlert = [[NSAlert alloc] init];
[generalAlert addButtonWithTitle:@"Continue?"];
[generalAlert addButtonWithTitle:@"Cancel"];
[generalAlert setMessageText:messageText];
[generalAlert setInformativeText:informText];
[generalAlert setAlertStyle:NSAlertStyleWarning];
// Animate the fading box, with the passed completion criteria alertReturn = NSModalResponseStop
[NSAnimationContext beginGrouping];
// Animate alpha fade
[[NSAnimationContext currentContext] setDuration:5.0];
[[NSAnimationContext currentContext] setCompletionHandler:^{
// Dismiss the alert
NSWindow *window = [NSApp mainWindow];
[[window attachedSheet] close];
NSLog(@"Closed the Sheet");
alertReturn = NSModalResponseStop;
}];
[[generalAlert.window animator] setAlphaValue:0.0];
[NSAnimationContext endGrouping];
// Begin the alert.
// For the completion criteria, speed up the animation to it's conclusion, but not before we return to the calling method
[generalAlert beginSheetModalForWindow:self.mySwiftCentral.sxWindowController.window completionHandler:^(NSInteger result) {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.01];
[[generalAlert.window animator] setAlphaValue:0.0];
[NSAnimationContext endGrouping];
alertReturn = result;
NSLog(@"Success, alertReturn = %ld",(long)alertReturn);
}];
// Create a NSModalSession using the global Application Instance variable NSApp
NSModalSession session = [NSApp beginModalSessionForWindow:
self.mywindow];
alertReturn = NSModalResponseContinue;
// Loop here until the user responds or the animation completes, either of which will modify alertReturn and break out of the loop
// Without the NSModalSession, this loop would block user button actions or animation timeout.
for (;;) {
[NSApp runModalSession:session];
if (alertReturn != NSModalResponseContinue)
break;
// Break on timeout here
}
[NSApp endModalSession:session];
NSLog(@"Alert Return = %ld",(long)alertReturn);
if (alertReturn == NSAlertFirstButtonReturn ||
alertReturn == NSModalResponseStop) {
return YES;
}
else return NO;
}