| 1 |
/** |
| 2 |
* JNA-RInChI - Library for calling RInChI from Java |
| 3 |
* Copyright © 2022 Nikolay Kochev |
| 4 |
* <p> |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* <p> |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU Lesser General Public License for more details. |
| 14 |
* <p> |
| 15 |
* You should have received a copy of the GNU Lesser General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
package io.github.dan2097.jnarinchi; |
| 19 |
|
| 20 |
/** |
| 21 |
* Immutable data class for the result of a decomposition of RInChI/RAuxInfo into separate InChIs. |
| 22 |
* |
| 23 |
* @author Nikolay Kochev |
| 24 |
*/ |
| 25 |
public class RinchiDecompositionOutput extends Output { |
| 26 |
private final static int ARRAY_IS_NULL = -1; |
| 27 |
private final ReactionDirection direction; |
| 28 |
private final String[] inchis; |
| 29 |
private final String[] auxInfos; |
| 30 |
private final ReactionComponentRole[] roles; |
| 31 |
|
| 32 |
public RinchiDecompositionOutput(ReactionDirection direction, String[] inchis, String[] auxInfos, ReactionComponentRole[] roles, |
| 33 |
Status status, int errorCode, String errorMessage) { |
| 34 |
super(status, errorCode, errorMessage); |
| 35 |
this.direction = direction; |
| 36 |
|
| 37 |
// make sure that the number of elements in the arrays storing the individual InChIs, auxiliary information |
| 38 |
// and reaction component roles is equal; otherwise, we throw an exception |
| 39 |
final int noElementsInchis = inchis == null ? ARRAY_IS_NULL : inchis.length; |
| 40 |
final int noElementsAuxInfo = auxInfos == null ? ARRAY_IS_NULL : auxInfos.length; |
| 41 |
final int noElementsRoles = roles == null ? ARRAY_IS_NULL : roles.length; |
| 42 |
if (noElementsInchis != noElementsAuxInfo || noElementsAuxInfo != noElementsRoles) { |
| 43 |
throw new IllegalArgumentException("The number of InChIs (" + noElementsInchis + "), auxiliary information (" + |
| 44 |
noElementsAuxInfo + ") and reaction component roles (" + noElementsRoles + ") must be equal."); |
| 45 |
} |
| 46 |
|
| 47 |
this.inchis = inchis; |
| 48 |
this.auxInfos = auxInfos; |
| 49 |
this.roles = roles; |
| 50 |
} |
| 51 |
|
| 52 |
public ReactionDirection getDirection() { |
| 53 |
return direction; |
| 54 |
} |
| 55 |
|
| 56 |
public String[] getInchis() { |
| 57 |
return inchis; |
| 58 |
} |
| 59 |
|
| 60 |
public String[] getAuxInfos() { |
| 61 |
return auxInfos; |
| 62 |
} |
| 63 |
|
| 64 |
public ReactionComponentRole[] getRoles() { |
| 65 |
return roles; |
| 66 |
} |
| 67 |
|
| 68 |
public int getNumberOfComponents() { |
| 69 |
if (inchis == null) |
| 70 |
return 0; |
| 71 |
else |
| 72 |
return inchis.length; |
| 73 |
} |
| 74 |
|
| 75 |
@Override |
| 76 |
public String toString() { |
| 77 |
StringBuilder stringBuilder = new StringBuilder(); |
| 78 |
stringBuilder.append(this.getClass().getSimpleName()); |
| 79 |
stringBuilder.append("={reactionDirection="); |
| 80 |
stringBuilder.append(direction); |
| 81 |
stringBuilder.append(", inchis="); |
| 82 |
stringBuilder.append(arrayElementsToString(inchis)); |
| 83 |
stringBuilder.append(", auxInfo="); |
| 84 |
stringBuilder.append(arrayElementsToString(auxInfos)); |
| 85 |
stringBuilder.append(", reactionComponentRole="); |
| 86 |
stringBuilder.append(arrayElementsToString(roles)); |
| 87 |
stringBuilder.append("}"); |
| 88 |
|
| 89 |
return stringBuilder.toString(); |
| 90 |
} |
| 91 |
|
| 92 |
private String arrayElementsToString(Object[] array) { |
| 93 |
StringBuilder stringBuilder = new StringBuilder(); |
| 94 |
|
| 95 |
if (array == null) { |
| 96 |
stringBuilder.append("null"); |
| 97 |
} else { |
| 98 |
stringBuilder.append("["); |
| 99 |
for (Object object : array) { |
| 100 |
stringBuilder.append(object.toString()); |
| 101 |
stringBuilder.append(", "); |
| 102 |
} |
| 103 |
stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length()); |
| 104 |
stringBuilder.append("]"); |
| 105 |
} |
| 106 |
|
| 107 |
return stringBuilder.toString(); |
| 108 |
} |
| 109 |
} |