Questions tagged [utility-method]

For questions regarding utility class methods.

69 questions
1
vote
1 answer

How to handle type checking boilerplate in PHP

I'm writing a utility function to handle arrays. For the sake of avoiding complexity let's say it's a simple handle to allow shorthand array insertion into a function: function array_insert($original_arr,$key,$val){ $original_arr[$key]=$val; …
M1ke
  • 6,166
  • 4
  • 32
  • 50
1
vote
0 answers

how do I make a socket manager for a Swing GUI?

Right now I have a console client which communicates with the server via ObjectInputStream.readObject() and ObjectOutputStream.writeObject(). For a console based application, this seems to work as is. The problem is that the class which has the…
Thufir
  • 8,216
  • 28
  • 125
  • 273
1
vote
1 answer

Mocking private static method in a final (utility) class

Is there a way to test the following class, mocking the private method getMessage() ? I've tried with jUnit + Mockito + PowerMock but I could not find a way (without modifying source code or doing reflection changes). Any idea ? public final class…
Gualtiero Testa
  • 244
  • 1
  • 3
  • 8
0
votes
1 answer

How to fetch single row from excel sheet and pass into testng data provider using java

I have a scenario to fetch entire 3rd row data from excel sheet and pass to data provider. I can fetch all the row available in excel sheet (Please find the code below). But, I want to fetch nth row of data and pass to data provider annotation.…
0
votes
0 answers

What is the utility of a jQuery object or most common methods associated?

Does this relate to specific functions that can be done by using jQuery vs longer javascript code or are their specific utility functions? I'm still trying to understand the importance and versatility of jQuery. thanks! I tried googling but all I…
0
votes
1 answer

Why this code outputs garbage value after swapping the values?

Take two numbers as input and swap them and print the swapped values.You do not need to print anything, it has already been taken care of. Just implement the given function.And the functions looks like this. pair < int, int > swap(pair < int, int >…
0
votes
1 answer

Java how to good practice : Map in Utility Class

Can I use a utility class like this? public final class ProfessorDirectory { private static Map directory = new HashMap<>(); private ProfessorDirectory() { throw new IllegalStateException("Utility Class"); } …
ThrowsError
  • 1,169
  • 1
  • 11
  • 43
0
votes
0 answers

Using Service methods inside Utils class [Spring and Kotlin]

I have faced a well-known scenarios whereby I really need to move a number of utilities private functions (that should not have been there in the first place) from my Service class to a utility class. My question is around using service methods in a…
panza
  • 1,341
  • 7
  • 38
  • 68
0
votes
1 answer

Objects.deepToString(Object o) method

The class java.util.Objects contains the deepEquals(Object a, Object b) method that can be used to compare objects of any type (including arrays and null references), but doesn't contain a similar deepToString(Object o). This is disappointing. (By…
John McClane
  • 3,498
  • 3
  • 12
  • 33
0
votes
1 answer

How to make utility class or functional component to expose few common utility methods

I am new to ReactJs. I have good knowledge of other OOP languages such as Java, C++, etc. That is why I am trying to find similarities between OOP and ReactJs. As we always do in Java, we make a static utility class to expose few common…
masiboo
  • 4,537
  • 9
  • 75
  • 136
0
votes
2 answers

How can I call utility methods statically with a chain of classes?

I have a solution with a "Common" project. This "Common" project is used by other projects in the solution. Within this "Common" project, I have a "Utilities" folder with several different utility classes, for example, "CsvUtilities.cs" and…
0
votes
1 answer

Inject Dependency to Utility Class Map

I have a utility/constants class that contains a Map where Authorizer is an interface with a few different implementations. I use the map across different streams to take in an object that contains some String (the name of an…
0
votes
1 answer

Assigning a returned result for a function in a different file to a variable

I have a function in a utils file that I want to call and assign the exported result to a variable. Currently, the variable is defined then I try to assign the return result but I am getting undefined as the result when I console.log it. Here is my…
joshk132
  • 1,011
  • 12
  • 37
0
votes
3 answers

Blue Prism Replace non English characters

Looking for a function in Blue Prism to replace non english characters with english characters. Example: Input: Andrés Chávez  Output: Andres Chavez
James
  • 11
  • 1
  • 4
0
votes
2 answers

superclass vs utility class for common code

I have the same method in 2 classes that copy fields from one object to builders. I want to refactor it but I do not know if I should create a static method in an utility class or abstract it to a superclass. The classes that shares this code are…
A Torre
  • 219
  • 1
  • 7
  • 18