Never really liked to make the code in static methods, doing it usually, if he does without it. And here thinking and I can't find the correct answer to, it seems to me, quite an easy question.
Does it make sense (for resources, or performance ?) in the transformation:
public class A { private final int a; private final Map map; public A(int a) { this.a = a; this.map = new HashMap(); } public int calcSomthing() { int b = 0; for (int i : map.values()) if (i == a) b++; return b; } }
in
public class A { // ... public int getA() { return a; } public Collection getValues() { return map.values(); } public static int calcSomthing(A obj) { int b = 0; for (int i : obj.getValues()) if (i == obj.getA()) b++; return b; } }
If we consider that objects a lot, say 50 thousand.
Or washed away will only if you have to make those methods static, which did not turn directly to class variables, and use only the other class methods?