Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6224889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:44:43+00:00 2026-05-24T08:44:43+00:00

I am devicing an abstract class that will override toString() with an automated message,

  • 0

I am devicing an abstract class that will override toString() with an automated message, as such:

public abstract class AbstractTask {

    abstract void run();
    abstract int calculate();

    private String makeMessage() {
        String raw = this.getClass().toString();
        // do regex stuff here!
    }  

    @Override
    public String toString() {
        return makeMessage();
}

My implemented (extends AbstractTask) classes might be called something like

TaskXRQMinimize
TaskListParallell
TaskVerifyRepositoryEmpty
TaskCreateXRQs
TaskCreateZRQs
TaskSendAllSRQToTLS

The output I want to have when calling the classes toString() methods are:

Task XRQ Minimize
Task List Parallell
Task Verify Repository Empty
Task Create XRQs
Task Create ZRQs
Task Send All SRQ To TLS

I made a simple regex pattern to find these words:

([A-Z]{1}[a-z]+|[A-Z]{3}[a-z]?)

How do I implement this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:44:45+00:00Added an answer on May 24, 2026 at 8:44 am

    Make your toString() abstract as well, force subclasses to implement it by returning fixed string. Throw away parsing class name and using regular expressions – too fragile and with poor performance. If you really want to make it this way, at least do the computations once per class, not every time toString() is called.

    As for the regular expression, I have something better: StringUtils#splitByCharacterTypeCamelCase() from Apache Commons Lang (there is really no need to reinvent some things):

    StringUtils.splitByCharacterTypeCamelCase("fooBar")     = ["foo", "Bar"]
    StringUtils.splitByCharacterTypeCamelCase("foo200Bar")  = ["foo", "200", "Bar"]
    StringUtils.splitByCharacterTypeCamelCase("ASFRules")   = ["ASF", "Rules"]
    

    In your case:

    //yields [Task, Send, All, SRQ, To, TLS]
    StringUtils.splitByCharacterTypeCamelCase("TaskSendAllSRQToTLS")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given the task of devising a custom forms manager that has
When working with a console application, a history of everything that has been entered
Background Information: I'm part of a team of developers that runs a web application
I have an .fsproj (and .sln) from an F# project that was developed on
I understand that this is a very broad question, but a short it depends
I have run into a problem and would appreciate help devising a creative, and
I am working on a program in C# that needs to load some JavaScript
aka, Seeking generic Error Handler (ΟΚ to use commercially) I doubt that I am
I'm not particularly accustomed to generating complex SQL queries and am having difficulty in
Can a UI application be unit tested? Lets consider a UI application which has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.