For questions regarding utility class methods.
Questions tagged [utility-method]
69 questions
2
votes
1 answer
Do you prefer repeating code instead of utility classes?
We have a service in Java that deals with a lot of user-uploaded files, and tasks that prepare these files for different models to execute with.
One such phase of preparation included overriding values in json files. 4 out of 10 tasks were supposed…

user2684198
- 812
- 1
- 10
- 18
2
votes
3 answers
Don't fully understand custom-written 'memcpy' function in C
So I was browsing the Quake engine source code earlier today and stumbled upon some written utility functions. One of them was 'Q_memcpy':
void Q_memcpy (void *dest, void *src, int count)
{
int i;
if (( ( (long)dest | (long)src…

Simeon Laplev
- 69
- 1
- 8
2
votes
2 answers
C# Utility Class - Setting up for General Use and Compiling w/o Main
Okay, so working on learning some C#. Great language, love working with it in general, but I'm not understanding how to get over this lack of utility classes. In essence, I want to set up a general utilities class that can be contained in a folder…

Jonathan McDevitt
- 113
- 1
- 11
2
votes
0 answers
Is it good idea to use a Utility class with static methods to show and hide Android Dialogs?
Which way is better to hide and show Android Dialogs? There won't be stored any reference in the class to make a leak, so just give your advice with an explanation concerning to this.
Write an Utility class with static methods?
Write an Utility…

X-HuMan
- 1,488
- 1
- 17
- 37
2
votes
1 answer
Designing Helper/Utility classes - java
Maybe this question is general but I did not find an answer I was looking for, so I was hoping to get some ideas from this post. I am trying to move out some commonly used methods to a helper to simplify my design. I looked at multiple posts and…

Shyna
- 145
- 2
- 10
2
votes
3 answers
Find if present in enum without iterating?
trying to find an element by its constant parameter/field value(i.e. value0/value1/value2) without iterarting; is there a way?
found guava utility method which works for enum constant name(i.e. CONSTANT0/CONSTANT1/CONSTANT2) and not parameter/field…

urmalp
- 382
- 2
- 4
- 20
2
votes
2 answers
Is there a built in Kotlin method to apply void function to value?
I wrote this method to apply a void function to a value and return the value.
public inline fun T.apply(f: (T) -> Unit): T {
f(this)
return this
}
This is useful in reducing something like this:
return values.map {
var other =…

Michael Pardo
- 2,590
- 3
- 24
- 33
2
votes
2 answers
Why does my removeDuplicates method only remove the duplicate integer the first time it encounters it?
My method for removing the duplicate numbers works but not if a number appears more than twice.
e.g. a list with numbers 1,2,2,3,4,5,6,7,7,7,8,9 when using the method gives the list 1,2,3,4,5,6,7,7,8,9
import java.util.*;
public class final…

csanders8
- 23
- 6
2
votes
7 answers
Why setter and getter methods
Possible Duplicate:
Why use getters and setters?
I know this is very trivial. But why do we define private and then we use getter and setters. Is this more like for preventing the programmers from making mistakes on using private variables or…

Sara
- 2,417
- 7
- 35
- 52
1
vote
1 answer
Passing object to constructor versus getting from static utility class
I am not sure how to design of my Java classes, the question is also related to better testing.
I am using static utility class/method Utils.getMapper() to get configured ObjectMapper at many places in my Spring application.
When object mapper is…

jnemecz
- 3,171
- 8
- 41
- 77
1
vote
1 answer
Reflecting methods in a utility class and invoking them with varargs in Java
I built a _VERY_ rudimentary utility class in Java to handle database operations (connection retrieval, inserts, etc.) like this:
// define the package name
package com.foo.bar.helpers;
// import all needed resources
import…

Julio María Meca Hansen
- 1,303
- 1
- 17
- 37
1
vote
3 answers
Utility class or Common class in asp.net
Do anyone knows about the class which has the common function which we generally use while developing web application. I have no idea what you may call it, it may be the utility class or common function class. Just for reference, this class can have…

Chris
- 2,293
- 11
- 48
- 86
1
vote
4 answers
If utility class is an anti pattern, what is the alternatives in PHP?
I am trying to build my own MVC framework (of course to learn it better) by following latest OOP design pattern. I was wondering, what is the best practice for placing repeatable codes (which are used to stay in the utility classes as static…

Md Monjur Ul Hasan
- 1,705
- 1
- 13
- 36
1
vote
1 answer
Util class for accesing a Service in Spring 3
In Spring 3 it is not possible to set @Autowired in either static fields or methods, so since I want to declare an utility class such as:
public class SchoolYearServiceUtil {
private static SchoolYearService schoolYearService;
public static…
anon
1
vote
1 answer
One Stateless Session EJB for Utility functions?
I have some utility functions which may be called from multiple Stateless Session EJBs. These utility functions needs to be in a new transaction (RequiresNew).
Does it make sense to create one Stateless Session EJB for all these functions may be…

ChumboChappati
- 1,442
- 4
- 18
- 38