Added explicit null check

As per FindBugs Recommendation.
Fixed Default Encoding Check
Used entry set and replaced call to clone()
Added many default:break; statements

Appeases the Findbugs self-test
Redundant Null Check
Safer Averaging
Fixed Encoding