Skip to content

Commit

Permalink
Code cleanup?
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanduhr32 committed Jan 15, 2018
1 parent f3943e9 commit 16957f9
Show file tree
Hide file tree
Showing 47 changed files with 183 additions and 159 deletions.
43 changes: 29 additions & 14 deletions bots/dunctebot/system/aiml.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="aiml" type="xs:string">
<xs:complexType>
<xs:sequence>
Expand All @@ -27,8 +27,8 @@
<xs:element name="category">
<xs:complexType>
<xs:sequence>
<xs:element name="pattern" type="xs:string"></xs:element>
<xs:element name="that" type="xs:string"></xs:element>
<xs:element name="pattern" type="xs:string"/>
<xs:element name="that" type="xs:string"/>
<xs:element name="template">
<xs:complexType>
<xs:sequence>
Expand All @@ -38,26 +38,33 @@
<xs:element name="set" type="xs:string">
<xs:complexType>
<xs:sequence>
<xs:element name="star"></xs:element>
<xs:element
name="star"/>
<xs:element name="get">
<xs:complexType>
<xs:attribute name="name" type="xs:string"></xs:attribute>
<xs:attribute
name="name"
type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"></xs:attribute>
<xs:attribute
name="name"
type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="star"></xs:element>
<xs:element name="star"/>
<xs:element name="srai" type="xs:string">
<xs:complexType>
<xs:sequence>
<xs:element name="get">
<xs:complexType>
<xs:attribute name="name" type="xs:string"></xs:attribute>
<xs:attribute
name="name"
type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand All @@ -71,16 +78,24 @@
<xs:sequence>
<xs:element name="get">
<xs:complexType>
<xs:attribute name="name" type="xs:string"></xs:attribute>
<xs:attribute
name="name"
type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="srai" maxOccurs="unbounded" type="xs:string"></xs:element>
<xs:element
name="srai"
maxOccurs="unbounded"
type="xs:string"/>
</xs:sequence>
<xs:attribute name="value" type="xs:string"></xs:attribute>
<xs:attribute
name="value"
type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"></xs:attribute>
<xs:attribute name="name"
type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand All @@ -90,12 +105,12 @@
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"></xs:attribute>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="category" maxOccurs="unbounded" type="category"/>
</xs:sequence>
<xs:attribute name="version" type="xs:string"></xs:attribute>
<xs:attribute name="version" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/com/wolfram/alpha/impl/WAImageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class WAImageImpl implements WAImage, Visitable, Serializable {
int width = Integer.parseInt(thisElement.getAttribute("width"));
int height = Integer.parseInt(thisElement.getAttribute("height"));
dimensions = new int[]{width, height};
} catch (NumberFormatException e) {
} catch (NumberFormatException ignored) {
}
}

Expand Down Expand Up @@ -141,12 +141,17 @@ public void acquireImage() {
if (!imageAcquired && http != null) {
try {
String suffix;
if (format == WAImage.FORMAT_GIF)
suffix = ".gif";
else if (format == WAImage.FORMAT_PNG)
suffix = ".png";
else
suffix = ".tmp";
switch (format) {
case WAImage.FORMAT_GIF:
suffix = ".gif";
break;
case WAImage.FORMAT_PNG:
suffix = ".png";
break;
default:
suffix = ".tmp";
break;
}
String outFile = File.createTempFile("WAImage", suffix, tempDir).getAbsolutePath();
URLFetcher fetcher = new URLFetcher(new URL(url), outFile, http, null);
fetcher.fetch();
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/wolfram/alpha/impl/WAInfoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class WAInfoImpl implements WAInfo, Serializable {
static final WAInfoImpl[] EMPTY_ARRAY = new WAInfoImpl[0];
private static final long serialVersionUID = 687066271144463657L;
private String text;
private Visitable[] contentElements = EMPTY_VISITABLE_ARRAY;
private Visitable[] contentElements;


WAInfoImpl(Element thisElement, HttpProvider http, File tempDir) throws WAException {
Expand All @@ -51,16 +51,20 @@ public class WAInfoImpl implements WAInfo, Serializable {

NodeList subElements = thisElement.getChildNodes();
int numSubElements = subElements.getLength();
List<Visitable> contentList = new ArrayList<Visitable>(numSubElements);
List<Visitable> contentList = new ArrayList<>(numSubElements);
for (int i = 0; i < numSubElements; i++) {
Node child = subElements.item(i);
String name = child.getNodeName();
if ("link".equals(name)) {
contentList.add(new WALinkImpl((Element) child));
} else if ("img".equals(name)) {
contentList.add(new WAImageImpl((Element) child, http, tempDir));
} else if ("units".equals(name)) {
contentList.add(new WAUnitsImpl((Element) child, http, tempDir));
switch (name) {
case "link":
contentList.add(new WALinkImpl((Element) child));
break;
case "img":
contentList.add(new WAImageImpl((Element) child, http, tempDir));
break;
case "units":
contentList.add(new WAUnitsImpl((Element) child, http, tempDir));
break;
}
}
contentElements = contentList.toArray(new Visitable[contentList.size()]);
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/com/wolfram/alpha/impl/WAPodImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private synchronized void createFromDOM(Element thisElement) throws WAException
scanner = thisElement.getAttribute("scanner");
try {
position = Integer.parseInt(thisElement.getAttribute("position"));
} catch (NumberFormatException e) {
} catch (NumberFormatException ignored) {
}
id = thisElement.getAttribute("id");
asyncURL = thisElement.getAttribute("async");
Expand All @@ -112,7 +112,7 @@ private synchronized void createFromDOM(Element thisElement) throws WAException
// Program defensively and don't assume that every element in a <states> is a <state>
// or <statelist>, although we have no intention of making such a change in the API output.
int numSubElements = subElements.getLength();
List<Node> stateAndStatelistNodes = new ArrayList<Node>(numSubElements);
List<Node> stateAndStatelistNodes = new ArrayList<>(numSubElements);
for (int i = 0; i < numSubElements; i++) {
Node child = subElements.item(i);
String name = child.getNodeName();
Expand All @@ -136,7 +136,7 @@ private synchronized void createFromDOM(Element thisElement) throws WAException
// Program defensively and don't assume that every element in an <infos> is an <info>,
// although we have no intention of making such a change in the API output.
int numSubElements = subElements.getLength();
List<Node> infoNodes = new ArrayList<Node>(numSubElements);
List<Node> infoNodes = new ArrayList<>(numSubElements);
for (int i = 0; i < numSubElements; i++) {
Node child = subElements.item(i);
String name = child.getNodeName();
Expand All @@ -157,7 +157,7 @@ private synchronized void createFromDOM(Element thisElement) throws WAException
// Program defensively and don't assume that every element in a <sounds> is an <sound>,
// although we have no intention of making such a change in the API output.
int numSubElements = subElements.getLength();
List<Node> soundNodes = new ArrayList<Node>(numSubElements);
List<Node> soundNodes = new ArrayList<>(numSubElements);
for (int i = 0; i < numSubElements; i++) {
Node child = subElements.item(i);
String name = child.getNodeName();
Expand Down Expand Up @@ -271,16 +271,9 @@ public void finishAsync() throws WAException {
asyncURL = null;
}
acquireImages();
} catch (ParserConfigurationException e) {
} catch (ParserConfigurationException | FactoryConfigurationError | SAXException | IOException e) {
// Probably impossible in any realistic circumstance.
newAsyncException = new WAException(e);
} catch (FactoryConfigurationError e) {
// Probably impossible in any realistic circumstance.
newAsyncException = new WAException(e);
} catch (IOException e) {
newAsyncException = new WAException(e);
} catch (SAXException e) {
newAsyncException = new WAException(e);
}
if (newAsyncException != null) {
synchronized (this) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/wolfram/alpha/impl/WAPodStateImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private synchronized void createFromDOM(Element thisElement) throws WAException
// although we have no intention of making such a change in the API output.
NodeList states = thisElement.getChildNodes();
int numStates = states.getLength();
List<Node> stateElements = new ArrayList<Node>(numStates);
List<Node> stateElements = new ArrayList<>(numStates);
for (int i = 0; i < numStates; i++) {
Node stateNode = states.item(i);
if ("state".equals(stateNode.getNodeName()))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/wolfram/alpha/impl/WAQueryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public WAQuery copy() {
// Creates the URL representation of this query, not including server, path, and appid param. Result starts with &.
public String toString() {

StringBuffer s = new StringBuffer(600);
StringBuilder s = new StringBuilder(600);

List<String[]> params = getParameters();
for (String[] param : params) {
Expand Down
Loading

0 comments on commit 16957f9

Please sign in to comment.