Cross-parameter constraint for functions with parameters having different ordering in each function

So I have a problem statement in which I want to have a validation to take place on the inputs of a function and the validation has to take place using two of the inputs provided in the function but the functions on which I have to do these they have their inputs in varied orders. So I have to run validation using two variables suppose a and b. But the functions on which I have to run the validation have their function definition as

  1. f1(a, b, c)
  2. f2(a, d, b)
  3. f3(a, c, d, b)

Also I am not able to use instanceof as the instance of b collides with d. So there any other way in which this can be done?

JTable losing values when focus is lost

My JTable/ JXTreeTable “forgets” the values just entered and reverts to the default value of “Value x” when cell focus is lost (by clicking another cell, hitting enter, etc).

I have found a few suggestions on SO and nothing has helped. One was to set putClientProperty(…) which didn’t change a thing. From:
Can a Jtable save data whenever a cell loses focus?

I am at a loss why this is so difficult.
Please explain why the entered data wont “stick” and how to fix it.

Here is my code:

public class MyJTreeTable extends JXTreeTable{
public MyJTreeTable()
    setTreeTableModel(new MyTreeStructure(5));
    setTreeCellRenderer(new DefaultTreeRenderer());
    setSelectionBackground(new Color(176, 197, 227));
    setSelectionForeground(new Color(0, 0, 128));
    BorderHighlighter border = new BorderHighlighter(new ColumnHighlightPredicate(1, 2), BorderFactory.createEmptyBorder(0, 6, 0, 6), false, false);
putClientProperty("terminateEditOnFocusLost", true);

   addMouseListener(new java.awt.event.MouseAdapter() 
        public void mouseClicked(java.awt.event.MouseEvent evt) 
            int row = rowAtPoint(evt.getPoint());
            int col = columnAtPoint(evt.getPoint());
            if (row >= 0 && col >= 0) 
                editCellAt(row, 1);


    public boolean isCellEditable(int row, int column) 
        if (column == 1)
            return true;
        else return false;

class MyTreeStructure extends DefaultTreeTableModel 

    DefaultMutableTreeTableNode Root = null;
    MyTreeStructure(int i) 
        Root = new DefaultMutableTreeTableNode();

        for (int x = 0; x < 5; x++) 
            DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode("HI");
            for (int j = 0; j < i; j++) 
                node.add(new DefaultMutableTreeTableNode(j));

    public String getColumnName(int column)
        return "Value";

    public int getColumnCount() 
        return 2;

    public Object getValueAt(Object arg0, int arg1) 
        if (arg1 == 1) 

            return new String("Value " + arg0.toString());
    return arg0;


Subclass constructor without one parameter – is it possible? How to do that? [duplicate]

This question already has an answer here:

Let’s start with code first

This is my superclass

public class Burger {

protected String name;
protected MeatType meat;
protected BreadType bread;
private double basePrice;
private EnumMap<Addition, Integer> additions;

public Burger(String name, MeatType meat, BreadType bread){ = name;
    this.meat = meat;
    this.bread = bread;
    this.basePrice = 3.00;
    this.additions = new EnumMap<Addition, Integer>(Addition.class);

and this is the subclass inheriting from it

public class FitBurger extends Burger {

public FitBurger(String name, MeatType meat, BreadType bread){


However, I don’t want my subclass to have a constructor with the BreadType bread but still I want it to keep inherit the variable and set it to a particular value. I want the superclass to remain the way it is too.

Is it possible to achieve that in any possible way?

Drawing to a BufferedImage sometimes, but consistently, yields weird results

So on two occasions I’ve written two programs that do almost the exact same thing: search an image for pixels of a user-determined color and draw over them with another user-determined color.

So I get the image, then call createGraphics on it, then with two for() loops go over every pixel, and if

new Color(image.getRGB(x, y)).equals(userSubmittedColor1)

I draw over it like so

graphics.fillRect(x, y, 1, 1);

Then I use ImageIO.write() to save the image as a PNG, appending “_recolored.png” to the original image’s file name.

Now in most cases it just works, but sometimes, the color is a completely different one from userSubmittedColor2, or the image isn’t altered at all. In these cases, no matter how often I re-try it, the color being drawn is reliably not the one being input by the user.

I have absolutely no idea what causes this. I’ve looked in the debugger and the color is alright.

Generate Java code from WSDL file

I am new to Java. I am trying to create SOAP Web service client to consume a vendors webservice which requires username password and ssl certificate.

A vendor provided me SoapUI project file. I imported the project file in SoapUI and ran the tests. Those tests worked successfully.

I then exported the wsdl file using SoapUI and tried to generate java code using wsimport. I am unable to generate code. I am getting all sorts of errors which I tried to resolve by searching online but none of the solutions work.

I am using jdk1.8.0_152. and SoapUI version 5.3.0 by SmartBear.

I tried to use this wsimport command on command line of Windows 7:

wsimport -keep -verbose -s src vendor.wsdl

and I received this message:

[WARNING] Simple type "RiskType" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 365, current limit: 256. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.

line 4317 of file:/C:/Projects/soapclient/vendor.xsd

With the SoapUI Project file they also sent me the below files:

  • jaxbbinding.xml
  • wsdlbinding.xml
  • ACORD_v2.2.0.xsd
  • ACORD-WSP_v2.0.0.xsd
  • Soap12-Envelope.xsd
  • xml.xsd

So tried wsimport with -b option like below:

wsimport -keep -verbose -s src vendor.wsdl -b ../jaxb/jaxbbinding.xml -b ../jaxb/wsdlbinding.xml

I received this error :

[ERROR] "file:/C:/Projects/soapclient/.../ACORD_v2.2.0.xsd" is not a part of this compilation. Is this a mistake for "file:/C:/Projects/soapclient/..../ProcessSuretyBond_1_2.xsd"?
  line 13 of file:/C:/Projects/TestProjects/soapclient/..../jaxb/jaxb-binding.xml

Exception in thread "main"
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(

Not sure but should I request new binding files from the vendor ?

It works in SoapUI so shouldn’t it work with wsimport ?

I tried all solution out there to resolve this issue including creating file in jdk folder, adding jvm argument in maven’s system settings etc. None worked.

I will appreciate if someone can point me in right direction and help resolve this issue. Many thanks in advance.

What is the best way to optimise a program that makes a lot of array and file accesses?

I’m currently developing a program for my AI module at university in Java. The goal of the program is to enable spam detection via neural networks. At the moment I have written this program to extract input data from a large folder full of spam and ham emails represented as txt files.

Currently what happens is this:

  1. The files are accessed and the text contents of each file are extracted and placed into an ArrayList, each string element within the ArrayList corresponds to one email.
  2. One by one each ArrayList element is fed to a second class, which accesses each element in turn, removes a number of junk characters and strings such as special characters etc. When each string has been ‘purged’ of junk characters, the new string is used to overwrite the old string present in the arraylist.
  3. From here the occurence of each unique word stored in this particular element is counted, the total number of occurences of each unique word and the unique word is used to create a custom object designed to hold these two parameters.
  4. Each email string in the ArrayList is iterated over, junk characters are removed, the words are counted, and the custom WordOccurence objects are updated with their new tallys.

At the moment the program is very slow to run, it currently takes around 15 minutes to analyse a folder consisting of 2000 emails. However this time does not seem to be linear, the program seems to slow down as more emails are analysed and stored. At first I thought the slow execution time was due to accesssing each file in turn, so I changed the code around to extract each email’s data first and place it into an ArrayList, the ArrayList was then used instead of accessing each email. However this had little impact on the performance of the program.

I’m just wondering if there are any other out-of-the-box optimisations that I will be able to make in order to run this program faster? My goal is to analyse a folder of 17000 emails, however as it stands at the moment this will take a significant amount of time.

I don’t want to just paste the code to my whole program into github somewhere and give you guys a link to search through, as this is not fair. I’m just asking for any ideas or suggestions you guys might have that will hopefully improve the performance.

ComboBox Model Java

When i Populate combo box with array list .. Strange elements appears this

i added in jCombo Box >> properties >> model >> custom code (this next line)

new DefaultComboBoxModel(arr.toArray())

and here is the code in gui which i declared my arraylist

public class adminsystem extends javax.swing.JFrame {
Apparels app = new Apparels();
public static ArrayList<Apparels> arr= new ArrayList<Apparels>();

DefaultComboBoxModel cateogry;

public adminsystem() {

    this.cateogry= new DefaultComboBoxModel();

so i want to fill the combo box with the array list elements( which i load from bin file )
and passes it to my arraylist

Spring 5 consume multiple MediaType

I’m using Spring boot 1.5.8.RELEASE
I have an endpoint and would like to consume multiple MediaType.
In particular application/x-www-form-urlencoded and application/json type.
At the moment I have the below code. It works for application/x-www-form-urlencoded, but doesn’t work for application/json.

@RequestMapping(path = "/abc", method = RequestMethod.POST,
                    consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_FORM_URLENCODED_VALUE},
                    produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseStatus(value = HttpStatus.OK)
    public ResponseEntity<MyResponse> validate(@Valid @ModelAttribute MyDetails details) {
        return something();

I tried to put a content negotiator in my configuration, but still doesn’t work.

public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
                      .mediaType("x-www-form-urlencoded", MediaType.APPLICATION_FORM_URLENCODED);

How can I allow the endpoint to accept these 2 media types?

Java jsoup type error with element vs elements

im pretty sure that my problem would be solved in <1 minute, but I don’t get it… 🙁
[Image: type error][1]

My code is 90% copy-paste from an easy example and same like many questions here, but doesn’t work…
My problem is that I don’t understand the error.

Please help

ListIterator for a one way linked list

So I’ve implemented a single linked, linked list which extends generic type AbstractSequentialList. I’m overriding the listIterator method, so have made a new class that implements generic type ListIterator which gets instantiated in the listIterator method of my linked list class. I have a few questions:

  • The listIterator method that I override needs an int parameter, what is the purpose of this? Do I go to that index of the list and pass that node through to the instantiated ListIterator?
  • Does the index always start at 0 for the ListIterator, even if I’m starting to iterate from a node in the middle of the list?
  • In the ListIterator class how do I write the hasPrevious and Previous method if the list is singly linked?