Map<Object, List<Element>> groupeUniqueMap =values.stream().collect(Collectors.groupingBy(this::getCompositeGroupKey, Collectors.toList()));
      if(groupeUniqueMap.containsKey(Arrays.asList(null,null,null,null,null,null,null)))
        return values;
      return doReturn();
By ThisIsFine, 2020-07-02 18:41:35
try
{
    len = readBufferSize(reader);
}
catch (IOException xcp)
{
    throw xcp;
}

I swear I didn't omit a single symbol (except for tabs at the beginning)

By RusAD, 2019-07-18 09:24:10
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.


   O | O | O 
  -----------
   O | O | O 
  -----------
   O | O | O 
     

 */
package tictactoe;

import java.util.Scanner;

public class TicTacToe {

    /**
     * @param args the command line arguments
     * @throws java.lang.InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        Scanner input = new Scanner(System.in);
        String a1 = "1";
        String a2 = "2";
        String a3 = "3";
        String a4 = "4";
        String a5 = "5";
        String a6 = "6";
        String a7 = "7";
        String a8 = "8";
        String a9 = "9";
        int inO;
        int inX = 0;
        boolean winner = false;
        PrintBoard(a1,a2,a3,a4,a5,a6,a7,a8,a9);
        System.out.printf("How to play - wait for your turn and when it comes write the number of the field that you want to draw in (from 1 to 9)\n");
        System.out.printf("Player O's turn: ");
        inO = input.nextInt();
        while (true) {
            switch (inO) {
                case 1:
                    if (a1 == "1") {
                        a1 = "O";
                    }
                    break;
                case 2:
                    if (a2 == "2") {
                    a2 = "O";
                    }
                    break;
                case 3:
                    if (a3 == "3") {
                    a3 = "O";
                    }
                    break;
                case 4:
                    if (a4 == "4") {
                    a4 = "O";
                    }
                    break;
                case 5:
                    if (a5 == "5") {
                    a5 = "O";
                    }
                    break;
                case 6:
                    if (a6 == "6") {
                    a6 = "O";
                    }
                    break;
                case 7:
                    if (a7 == "7") {
                    a7 = "O";
                    }
                    break;
                case 8:
                    if (a8 == "8") {
                    a8 = "O";                        
                    }
                    break;
                case 9:
                    if (a9 == "9") {
                    a9 = "O";
                    }
                    break;
                default:
                    System.out.printf("An error occured. Please accept it politely and restart the game.");
                    break;
            }
            System.out.printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
            if (null != Winners(a1,a2,a3,a4,a5,a6,a7,a8,a9))switch (Winners(a1,a2,a3,a4,a5,a6,a7,a8,a9)) {
                case "NONE":
                    if (a1 != "1" && a2 != "2" && a3 != "3" && a4 != "4" && a5 != "5" && a6 != "6" && a7 != "7" && a8 != "8" && a9 != "9") {
                        winner = true;
                        System.out.println("DRAW!");
                        Thread.sleep(3000);
                        break;
                    } else {
                    PrintBoard(a1,a2,a3,a4,a5,a6,a7,a8,a9);
                    System.out.printf("Player X's turn: ");
                    inX = input.nextInt();
                    break;
                    }
                case "X":
                    winner = true;
                    System.out.println("X HAS WON!!!");
                    Thread.sleep(3000);
                    break;
                case "O":
                    winner = true;
                    System.out.printf("O HAS WON!!!");
                    Thread.sleep(3000);
                    break;
                default:
                    break;
            }
            if (winner) {
                break;
            }
            switch (inX) {
                case 1:
                    if (a1 == "1") {
                    a1 = "X";
                    }
                    break;
                case 2:
                    if (a2 == "2") {
                    a2 = "X";
                    }
                    break;
                case 3:
                    if (a3 == "3") {
                    a3 = "X";
                    }
                    break;
                case 4:
                    if (a4 == "4") {
                    a4 = "X";
                    }
                    break;
                case 5:
                    if (a5 == "5") {
                    a5 = "X";
                    }
                    break;
                case 6:
                    if (a6 == "6") {
                    a6 = "X";
                    }
                    break;
                case 7:
                    if (a7 == "7") {
                    a7 = "X";
                    }
                    break;
                case 8:
                    if (a8 == "8") {
                    a8 = "X";
                    }
                    break;
                case 9:
                    if (a9 == "9") {
                    a9 = "X";
                    }
                    break;
                default:
                    System.out.printf("An error occured. Please accept it politely and restart the game.");
                    break;
            }
            System.out.printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
            if (null != Winners(a1,a2,a3,a4,a5,a6,a7,a8,a9))switch (Winners(a1,a2,a3,a4,a5,a6,a7,a8,a9)) {
                case "NONE":
                    if (a1 != "1" && a2 != "2" && a3 != "3" && a4 != "4" && a5 != "5" && a6 != "6" && a7 != "7" && a8 != "8" && a9 != "9") {
                        winner = true;
                        System.out.println("DRAW!");
                        Thread.sleep(3000);
                        break;
                    } else {
                    PrintBoard(a1,a2,a3,a4,a5,a6,a7,a8,a9);
                    System.out.printf("Player O's turn: ");
                    inO = input.nextInt();
                    break;
                    }
                case "X":
                    winner = true;
                    System.out.println("X HAS WON!!!");
                    Thread.sleep(3000);
                    break;
                case "O":
                    winner = true;
                    System.out.println("O HAS WON!!!");
                    Thread.sleep(3000);
                    break;
                default:
                    break;
            }
            if (winner) {
                break;
            }
        }    
    }
    
    public static void PrintBoard(String f1, String f2, String f3, String f4, String f5, String f6, String f7, String f8, String f9) {  
        System.out.printf("   %s | %s | %s \n",f1,f2,f3);
        System.out.printf("  ----------- \n");
        System.out.printf("   %s | %s | %s \n",f4,f5,f6);
        System.out.printf("  ----------- \n");
        System.out.printf("   %s | %s | %s \n",f7,f8,f9);
        System.out.printf(" \n");
    }
    
    public static String Winners(String f1, String f2, String f3, String f4, String f5, String f6, String f7, String f8, String f9) {
        if (f1 == f2 && f2 == f3 && f3 == "O") {
            return "O";
        } else if (f4 == f5 && f5 == f6 && f6 == "O") {
            return "O";
        } else if (f7 == f8 && f8 == f9 && f9 == "O") {
            return "O";
        } else if (f1 == f4 && f4 == f7 && f7 == "O") {
            return "O";
        } else if (f2 == f5 && f5 == f8 && f8 == "O") {
            return "O";
        } else if (f3 == f6 && f6 == f9 && f9 == "O") {
            return "O";
        } else if (f1 == f5 && f5 == f9 && f9 == "O") {
            return "O";
        } else if (f3 == f5 && f5 == f7 && f7 == "O") {
            return "O";
        } else if (f1 == f2 && f2 == f3 && f3 == "X") {
            return "X";
        } else if (f4 == f5 && f5 == f6 && f6 == "X") {
            return "X";
        } else if (f7 == f8 && f8 == f9 && f9 == "X") {
            return "X";
        } else if (f1 == f4 && f4 == f7 && f7 == "X") {
            return "X";
        } else if (f2 == f5 && f5 == f8 && f8 == "X") {
            return "X";
        } else if (f3 == f6 && f6 == f9 && f9 == "X") {
            return "X";
        } else if (f1 == f5 && f5 == f9 && f9 == "X") {
            return "X";
        } else if (f3 == f5 && f5 == f7 && f7 == "X") {
            return "X";
        } else {
            return "NONE";
        }
    }
}

There are sooo many problems with this...

By umnikos, 2017-12-12 17:27:24
    if (!recruiters
                    .stream().map(UserData::getUserName).collect(Collectors.toList())
                    .contains(recruiter.getUserData().getUserName())) {
    }
By somebody11, 2022-03-11 09:56:35
public class CustomBoolean {

    private Container<java.lang.Boolean> booleanContainer;

    public CustomBoolean(Container<Boolean> booleanContainer) {
        CustomBoolean custom_boolean = getThis();
        custom_boolean.booleanContainer = booleanContainer;
    }

    private <T extends Object> T getThis() {
        return (T) (Object) (T) this;
    }

    public Container<Boolean> getBooleanContainer() {
        return booleanContainer;
    }

    public static CustomBoolean create(Boolean value) {
        return new CustomBoolean(Container.builder().setValue(true).build());
    }

    public static void main(String[] args) {
        System.out.println(CustomBoolean.create(Boolean.TRUE).getBooleanContainer().getObject());
    }

    public static class Container<T extends Object> {

        private T object = null;

        private Container(T object) {
            Container<T> _this = getThis();
            _this.object = (T) (Object) object;
        }

        private <T extends Object> T getThis() {
            return (T) (Object) (T) this;
        }

        public static Builder builder() {
            return new Builder();
        }

        public T getObject() {
            return object;
        }

        public static class Builder<T extends Object> {
            private T value;

            public Builder<T> setValue(T value) {
                Container<T> _this = getThis();
                _this.object = (T) (Object) value;
                return this;
            }

            private <T extends Object> T getThis() {
                return (T) (Object) (T) this;
            }

            public Container build() {
                return new Container(value);
            }
        }
    }
} // Dort#0001

trolled

By Dort, 2022-03-24 21:41:54
	public static <A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> String get(A h, B u, C e, F l, G o, D v, E p, H a, I b, L c, K d, N f, J g, P i, M j, N m) {
        StringBuilder yes = new StringBuilder();
        yes.append((String) String.valueOf(h.toString()));
        yes.append((String) String.valueOf(u.toString()));
        yes.append((String) String.valueOf(e.toString()));
        yes.append((String) String.valueOf(l.toString()));
        yes.append((String) String.valueOf(o.toString()));
        yes.append((String) String.valueOf(v.toString()));
        yes.append((String) String.valueOf(p.toString()));
        yes.append((String) String.valueOf(a.toString()));
        yes.append((String) String.valueOf(b.toString()));
        yes.append((String) String.valueOf(c.toString()));
        yes.append((String) String.valueOf(d.toString()));
        yes.append((String) String.valueOf(f.toString()));
        yes.append((String) String.valueOf(h.toString()));
        yes.append((String) String.valueOf(g.toString()));
        yes.append((String) String.valueOf(i.toString()));
        yes.append((String) String.valueOf(j.toString()));
        return (String) String.valueOf(yes.toString());
	}

why

By fxcil, 2022-03-24 21:53:11
	public static int findSplitVariable(LinkedList<ByteDataRow> matrix) {
		LinkedList<ByteDataRow> list = new LinkedList<ByteDataRow>();
		int maxNoOfZeros = 0;
		int maxNoOfOnes = 0;
		int varId = -1;
		int[] NoOfOnesInColumn = new int[matrix.get(0).getInVars().length];


		for (ByteDataRow bdr : matrix) {
			int tmpNoOfZeros = bdr.getNumberOfZeros();
			if (maxNoOfZeros < tmpNoOfZeros) {
				list.clear();
				list.add(bdr.clone());
				maxNoOfZeros = tmpNoOfZeros;
			} else if (maxNoOfZeros == tmpNoOfZeros) {
				list.add(bdr.clone());
			}
		}

		for (ByteDataRow bdr : list) {
			byte[] vars = bdr.getInVars();
			for (int i = 0; i < vars.length; i++) {
				NoOfOnesInColumn[i] = NoOfOnesInColumn[i]
						+ Byte.compare(vars[i], Byte.parseByte("0"));
				if (NoOfOnesInColumn[i] > maxNoOfOnes) {
					maxNoOfOnes = NoOfOnesInColumn[i];
					varId = i;
				}
			}
		}

		return varId;
	}

	public static int findSplitVariable(LinkedList<ByteDataRow> matrix, int varIdx) {
		LinkedList<ByteDataRow> list = new LinkedList<ByteDataRow>();
		int maxNoOfZeros = 0;
		int maxNoOfOnes = 0;
		int varId = -1;
		int[] NoOfOnesInColumn = new int[matrix.get(0).getInVars().length];

		// Wybierz kostkÍ z najwiÍkszπ liczbπ zer.
		for (ByteDataRow bdr : matrix) {
			int tmpNoOfZeros = bdr.getNumberOfZeros();
			if (maxNoOfZeros < tmpNoOfZeros) {
				list.clear();
				list.add(bdr.clone());
				maxNoOfZeros = tmpNoOfZeros;
			} else if (maxNoOfZeros == tmpNoOfZeros) {
				list.add(bdr.clone());
			}
		}

		for (ByteDataRow bdr : list) {
			byte[] vars = bdr.getInVars();
			for (int i = 0; i < vars.length; i++) {
				NoOfOnesInColumn[i] = NoOfOnesInColumn[i]
						+ Byte.compare(vars[i], Byte.parseByte("0"));
				if (NoOfOnesInColumn[i] > maxNoOfOnes) {
					maxNoOfOnes = NoOfOnesInColumn[i];
					varId = i;
				}
			}
		}

		return varId;
	}

There are two methods findSplitVariable. Second one takes extra parameter (varIdx) that is not used anywhere.

By Paul, 2018-02-17 14:47:37
#997 Java +15
final int two_fifty_five_hex = 0xFF
final int two_fifty_five_dec = 255

One is in hex but the other is in decimal! Watch out, make sure you use the correct 255, not the other 255.

By Anonymous, 2020-04-28 14:52:27
String s = "string";

String.valueOf(s).toString();

// just to make sure it's a damn string
while(!s instanceof String) {
    String.valueOf(s).toString();
}
By Anonymous, 2021-01-23 17:11:10
spring.datasource.password=#{@secretsManager.getJsonField('${DSP_DB_SECRET:}', 'password', @secretsManager.getString('${DSP_DB_PASSWORD_SECRET:}', '${DSP_DB_PASSWORD:}'))}

String boot, 3 env variables written as string containing code executable code which cannot be verified by compiler. Welcome to Java

By 7bits, 2022-02-01 19:17:55
// check if user is valid or not
ValidUserValidationResult userValidationResult = validUserValidator.validateUser(validationRequest);
By Anonymous, 2020-12-09 17:45:18
private static final double RESULT_OF_DIVISION_BY_0 = 9.99;

public static double getPercentageDifference(long currentResult, long previousResult) {
    if (previousResult == 0 && currentResult == 0) {
        return 0;
    } else if (previousResult == 0) {
        return RESULT_OF_DIVISION_BY_0;
    } else {
        return (currentResult - previousResult) * 1.0 / previousResult;
    }
}
By Anonymous, 2017-12-20 10:56:50
class PythonClass {
    protected boolean True = true;
    protected boolean False = false;
    protected Object None = null;
}

class MyClass extends PythonClass {
    String do_something(Object foo) {
        if (foo == False)
            return ""                                  ;
        
        
        else if (foo == None)
            return "!"                                 ;
            
        else if (foo == True)
            return "Yay!"                              ;
    }
}

Yikes

By imaginedev, 2021-04-03 02:44:52
public List<Location> searchLocations(final String phrase) {
        final String like = phrase.replaceAll("(\\s)", "%$1") + "%";
        final List<Location> result = getLocations(
                "replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(\n" +
                        "replace(lower(name),'.',' '),\n" +
                        "'á','a'),\n" +
                        "'é','e'),\n" +
                        "'í','i'),\n" +
                        "'ĺ','l'),\n" +
                        "'ó','o'),\n" +
                        "'ŕ','r'),\n" +
                        "'ú','u'),\n" +
                        "'ý','y'),\n" +
                        "'č','c'),\n" +
                        "'ď','s'),\n" +
                        "'ľ','l'),\n" +
                        "'ň','n'),\n" +
                        "'š','s'),\n" +
                        "'ť','t'),\n" +
                        "'ž','z'),\n" +
                        "'ä','a'),\n" +
                        "'ô','o') LIKE lower(?)\n" +
                        "ORDER BY CASE country_code WHEN 'SK' THEN 0 ELSE 1 END, length(name), name", like);
        return result;
    }

Author: I am satisfied with the project and I don't think I have anything to be ashamed of

By Anonymous, 2020-07-16 10:49:27

/**
 * fk--folder key,dk--doc key -->value is key string
 * dt--doc type,ft--folder type -->both have 19 key options: 
 * bom tr amend history help info loeid cust cust0-cust9 custhist
 * folder type only seen as "history" in toc,why ??do we use other ones? -- it only has one child
 * doc type only seen two "tr" and "history" in toc??-- it only has one child 
 * node with "folder type="history"" is the only child of it parent either "<doc type="tr" key="xxx" trnum="xxx"....." or "<doc type="tr"  trnum="xxx""
 * <folder type="history"  could has more then one doc children .e.g. title="History of AMM31-32-00-720-807" in 700/amm
 * 
 * 
 * 
 * folder element has the follwing to identify itself:
 * 	1, key 
 * 	2, type="history",  in this case, folder is the only child of doc element with type ="tr"?????
 * 
 * doc element has the following to identify itself
 * 	1, key
 * 	2, type="tr" trnum="xxxxx"
 * 	3, type="history", in this case, doc isthe only child of a folder element???
 * 
 * 
 * 
 * the return json format likes following: 
 * [
 * { "data" : "A node", "children" , "state" : "open" },
 * { "data" : "Only child", "state" : "closed" },
 *	"Ajax node"
 *	]
 */

public class XMLToJson
{
	private static final Map<String, String> pathMap;
	static
	{
		Map<String, String> aMap = new HashMap<String, String>();
		aMap.put("fk", "folder[@key");
		aMap.put("ft", "folder[@type");
		aMap.put("fth", "folder[@type='history'");
		aMap.put("dk", "doc[@key");
		aMap.put("dt", "doc[@type");
		aMap.put("dth", "doc[@type='history'");
		aMap.put("dtrn", "doc[@trnum");
		pathMap = Collections.unmodifiableMap(aMap);
	}

	Util util = new Util();

	/*
	 * @param url the path to TOC.xml
	 * @param xPathString the short format searched node path
	 * @throws DocumentException
	 * 
	 * sample xPathString : "fk:AMM24_fk:AMM24-FM_dk" 
	 */
	@SuppressWarnings({ "unchecked" })
	public String getJson(URL url, String xPathString) throws Exception
	{
		Document TOCDoc = util.getDocument(url);
		String jsonString = "[";

		Element node = null;
		if (xPathString.equals("/"))
		{

			node = TOCDoc.getRootElement();
		}
		else
		{
			String realXPathString = pathMapping(xPathString);
			System.out.println(realXPathString);
			node = (Element) TOCDoc.selectSingleNode(realXPathString);
		}
		//List<Element>  li = node.elements();
		for (Iterator<Element> i = node.elementIterator(); i.hasNext();)
		{
			Element elem = (Element) i.next();
			String eleName = elem.getName();
			Boolean hasChildren = false;
			if ((elem.elements().size() > 0))
			{
				hasChildren = true;
				//current element has children itself, state shoud be "closed"

			}
			List<Attribute> list = elem.attributes();
			String titleAttrContent = elem.attributeValue("title");
			//Boolean isFileAttr = false;
			String fileAttrContent = elem.attributeValue("file");
			//if  (fileAttrContent.isEmpty() )
			if (eleName == "doc")
			{
				//doc element always has "file" attribute

				for (Attribute attribute : list)
				{
					jsonString = jsonString.concat("{");
					String attrName = attribute.getName();
					//System.out.println("doc arribute Name : " + attrName);
					//each one has to have "data" line, "attr" line "state" line and "children" line
					jsonString = jsonString.concat("'data':'").concat(titleAttrContent).concat("',");
					if (attrName.equals("key"))
					{
						String keyContent = elem.attributeValue("key");
						jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_dk:").concat(keyContent).concat("','file':'").concat(fileAttrContent).concat("'}");

						break;
					}
					else if (attrName.equals("trnum"))
					{

						String trnumContent = elem.attributeValue("trnum");
						jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_dtrn:").concat(trnumContent).concat("','file':'").concat(fileAttrContent).concat("'}");

						break;
					}
					/*		else if (attrName.equals("type"))//type attribute for doc element won't determite what exactly the element is 
							{
								String typeContent = elem.attributeValue("type");
								//doc element has type "history"
								if (typeContent == "history"){
									jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_dth,");
								}else if (typeContent == "?????"){
									//any values for type attribute need to concern???? 
								}

							}
							else if (attrName.equals("file"))
							{

							}*/
				}
				if (hasChildren)
				{
					//state set up as "closed" and no need to set up "children" field
					jsonString = jsonString.concat(",'state':'closed'");

				}
				else
				{
					//no need to put anything
					//jsonString = jsonString.concat("'state':'???'");
				}
				jsonString = jsonString.concat("},");
			}

			else if (eleName == "folder")
			{
				jsonString = jsonString.concat("{");
				for (Attribute attribute : list)
				{
					String attrName = attribute.getName();
					jsonString = jsonString.concat("'data':'").concat(titleAttrContent).concat("',");
					if (attrName.equals("key"))
					{
						String keyContent = elem.attributeValue("key");
						jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_fk:").concat(keyContent).concat("'}");
						if (fileAttrContent != null)
						{
							jsonString = jsonString.concat("','file':'").concat(fileAttrContent).concat("'}");
						}

						break;
					}
					else if (attrName.equals("type"))
					{
						String typeContent = elem.attributeValue("type");
						//doc element has type "history"
						if (typeContent == "history")
						{
							jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_fth,");

						}
						else if (typeContent == "?????")
						{
							//any values need to concern???? 
						}
						break;

					}

				}
				jsonString = jsonString.concat("},");
			}
			continue;
		}
		//return list;
		jsonString = jsonString.substring(0, jsonString.length() - 1);
		jsonString = jsonString.concat("]");
		return jsonString;

	}

	/*
	 * read xpathstring from post request and generate the real xpath for toc
	 */
	public String getXPathString()
	{
		//readPostRequest()
		return null;
	}

	/*
	 * post string looks like : "fk:LOETR_dtrn:TR12-118_fth_dth"
	 * it represents the inner doc elemnet:
	 * <folder key="LOETR" type="loetr" title="List of Effective TRs" file="loetr.html">
	 *		<doc type="tr" trnum="TR12-118" trdate="May 07/2012" title="[TR12-118] TASK AMM12-31-00-660-806 - Inspection and Removal of De-Hydrated Anti-Icing Fluid inside the Flight Control Surfaces" file="TR12-118.pdf" refloc="AMM12-31-00-660-806">
	 * 			<folder type="history" title="History of AMM12-31-00-660-806">
	 *   			<doc title="TASK 12-31-00-660-806 - Inspection and Removal of De-Hydrated Anti-Icing Fluid inside the Flight Control Surfaces" file="AMM12-31-00-660-806.pdf" type="history" refloc="AMM12-31-00-660-806"/>
	 * </folder>
	 * the xpath string should be:
	 * folder[@key="LOETR"]/doc[@trnum="TR12-118"]/folder[@type="history"]/doc[@type="history"]
	 * 
	 * 
	 * the String : "fk:AMM24_fk:AMM24-FM_dk:CTOC-24" 
	 * it represents the inner doc with attribute file="CTOC-24.pdf"
	 * the string : "fk:AMM24_fk:AMM24-00-00_fk:AMM24-00-00-02_dk:AMM24-00-00-700-801" represents
	 * <folder key="AMM24" title="CH 24 - Electrical Power">
	 *		<folder key="AMM24-FM" title="Front Matter">
	 * 			<doc key="CTOC-24" title="Table of Contents" file="CTOC-24.pdf"/>
	 *		</folder>
	 *		<folder key="AMM24-00-00" title="24-00-00 - General">
	 * 			<folder key="AMM24-00-00-02" title="General - Maintenance Practices">
	 *   			<doc key="AMM24-00-00-700-801" title="TASK 24-00-00-700-801 - AC Power, DC Power and Battery Maintenance Practice Recommendations" file="AMM24-00-00-700-801.pdf"/>
	 * 
	 * it can be even optimized as :
	 * "fk:AMM24_fk:00-00_fk:02_dk:AMM24-00-00-700-801"
	 * if the inner key fully include the previous key, omit it, otherwise use full string   
	 * the xpath string should be:
	 * folder[@key="AMM24"]/folder[@key="AMM24-00-00"]/folder[@key="AMM24-00-00-02"]/doc[@key="AMM24-00-00-700-801"]
	 *  
	 * if shortXPath is ?? which means the query based on the root of the document
	 * 
	 * 	 
	 */
	public String pathMapping(String shortXPath) throws Exception
	{
		String tagetString = null;
		if (shortXPath.equals(""))
		{
			tagetString = "//toc";
		}
		else
		{
			tagetString = "//";
		}

		int newStart = 0;
		String segString = "";
		String valueString = "";
		//dth???
		//need mapping all senarios
		//already??
		while (shortXPath.indexOf("_", newStart) > -1)
		{
			int keyValueSepPos = 0;
			String keyString = "";//not necessary key, might be type attribute
			segString = shortXPath.substring(newStart, shortXPath.indexOf("_", newStart));
			newStart = shortXPath.indexOf("_", newStart) + 1;//new start search point
			//System.out.println(newStart);
			if (segString.indexOf(":") > 0)
			{
				keyValueSepPos = segString.indexOf(":");
				keyString = segString.substring(0, keyValueSepPos);
				valueString = segString.substring(keyValueSepPos + 1);
				if (pathMap.get(keyString).length() > 0)
				{
					tagetString = tagetString.concat(pathMap.get(keyString));
				}
				else
				{
					throw new Exception("no mapping found");
				}
				tagetString = tagetString.concat("='").concat(valueString).concat("']/");
			}
		}
		//this is for scenerio either no "_" or sub string after "_"
		segString = shortXPath.substring(newStart);
		System.out.println(segString);
		if (segString.indexOf(":") > 0)
		{
			int lastKeyValueSepPos = segString.indexOf(":");
			String lastKeyString = segString.substring(0, lastKeyValueSepPos);
			String lastValueString = segString.substring(lastKeyValueSepPos + 1);
			if (pathMap.get(lastKeyString).length() > 0)
			{
				tagetString = tagetString.concat(pathMap.get(lastKeyString));
			}
			else
			{
				throw new Exception("no mapping found");
			}
			tagetString = tagetString.concat("='").concat(lastValueString).concat("']");
		}
		return tagetString;

	}

	public static void main(String[] args) throws Exception
	{
		XMLToJson x2j = new XMLToJson();
		String test = "fk:AMM24_fk:AMM24-FM";

		test = "";
		System.out.println(x2j.getJson(new URL("http://localhost:8080/WebNavSpring/q400/amm/toc.xml"), test));
		//System.out.println(x2j.pathMapping(test));

	}
}

easy clean code to convert XML to JSON .

By used in Major Airspace company , 2019-03-15 17:59:54