Skip to content

Commit

Permalink
Merge branch 'isEmpty()' of github.com:Juiceman/fred into next
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBab committed Jan 30, 2024
2 parents 3cf2617 + 16f7ab0 commit ea0a195
Show file tree
Hide file tree
Showing 33 changed files with 80 additions and 80 deletions.
4 changes: 2 additions & 2 deletions src/freenet/client/ClientMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public String getMIMEType() {
* existing information.
*/
public void mergeNoOverwrite(ClientMetadata clientMetadata) {
if((mimeType == null) || mimeType.equals(""))
if((mimeType == null) || mimeType.isEmpty())
mimeType = clientMetadata.mimeType;
}

/** Is there no MIME type? */
public boolean isTrivial() {
return ((mimeType == null) || mimeType.equals(""));
return ((mimeType == null) || mimeType.isEmpty());
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/freenet/client/FetchContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ public FetchContext(DataInputStream dis) throws StorageFormatException, IOExcept
}
}
String s = dis.readUTF();
if(s.equals(""))
if(s.isEmpty())
charset = null;
else
charset = s;
canWriteClientCache = dis.readBoolean();
s = dis.readUTF();
if(s.equals(""))
if(s.isEmpty())
overrideMIME = null;
else
overrideMIME = s;
Expand All @@ -425,7 +425,7 @@ public FetchContext(DataInputStream dis) throws StorageFormatException, IOExcept
// input stream reached EOF, so it must have been and old version without scehmeHostAndPort.
s = "";
}
if (s.equals("")) {
if (s.isEmpty()) {
schemeHostAndPort = null;
} else {
schemeHostAndPort = s;
Expand Down
2 changes: 1 addition & 1 deletion src/freenet/client/FetchException.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public static String getShortMessage(FetchExceptionMode mode) {
// FIXME change the l10n to use the names rather than codes
int code = mode.code;
String ret = NodeL10n.getBase().getString("FetchException.shortError."+code);
if(ret == null || ret.equals(""))
if(ret == null || ret.isEmpty())
return "Unknown code "+mode;
else return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/freenet/client/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ private void addRedirectionManifestWithMetadata(HashMap<String, Object> dir) {
Logger.debug(this, "Putting metadata for "+key);
manifestEntries.put(key, data);
} else if(o instanceof HashMap) {
if(key.equals("")) {
if(key.isEmpty()) {
Logger.error(this, "Creating a subdirectory called \"\" - it will not be possible to access this through fproxy!", new Exception("error"));
}
HashMap<String, Object> hm = Metadata.forceMap(o);
Expand Down
4 changes: 2 additions & 2 deletions src/freenet/client/async/ClientGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public void onFailure(FetchException e, ClientGetState state, ClientContext cont
String mime = e.getExpectedMimeType();
if(ctx.overrideMIME != null)
mime = ctx.overrideMIME;
if(mime != null && !"".equals(mime)) {
if(mime != null && !mime.isEmpty()) {
// Even if it's the default, it is set because we have the final size.
UnsafeContentTypeException unsafe = ContentFilter.checkMIMEType(mime);
if(unsafe != null) {
Expand Down Expand Up @@ -784,7 +784,7 @@ public void onExpectedMIME(ClientMetadata clientMetadata, ClientContext context)
mime = clientMetadata.getMIMEType();
if(ctx.overrideMIME != null)
mime = ctx.overrideMIME;
if(mime == null || mime.equals("")) return;
if(mime == null || mime.isEmpty()) return;
synchronized(this) {
expectedMIME = mime;
}
Expand Down
2 changes: 1 addition & 1 deletion src/freenet/client/async/SingleFileFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ private synchronized void handleMetadata(final ClientContext context) throws Fet
} else if(metaStrings.isEmpty()) {
FreenetURI u = uri;
String last = u.lastMetaString();
if(last == null || !last.equals(""))
if(last == null || !last.isEmpty())
u = u.addMetaStrings(new String[] { "" });
else
u = null;
Expand Down
40 changes: 20 additions & 20 deletions src/freenet/client/filter/CSSTokenizerFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1773,26 +1773,26 @@ else if(HTMLelement.indexOf('#')!=-1)
}

}
if(isIDSelector && "".equals(id)) return null; // No ID
if(isIDSelector && id.isEmpty()) return null; // No ID

boolean elementValid =
"*".equals(HTMLelement) ||
(ElementInfo.isValidHTMLTag(HTMLelement.toLowerCase())) ||
("".equals(HTMLelement.trim()) &&
((!className.equals("")) || (!id.equals("")) || attSelections!=null ||
!pseudoClass.equals("")));
(HTMLelement.trim().isEmpty() &&
((!className.isEmpty()) || (!id.isEmpty()) || attSelections!=null ||
!pseudoClass.isEmpty()));
if(!elementValid) return null;

if(!className.equals("")) {
if(!className.isEmpty()) {
// Note that the definition of isValidName() allows chained classes because it allows . in class names.
if(!ElementInfo.isValidName(className))
return null;
} else if(!id.equals("")) {
} else if(!id.isEmpty()) {
if(!ElementInfo.isValidName(id))
return null;
}

if(!pseudoClass.equals("")) {
if(!pseudoClass.isEmpty()) {
if(!ElementInfo.isValidPseudoClass(pseudoClass)) {
return null;
} else if(ElementInfo.isBannedPseudoClass(pseudoClass)) {
Expand Down Expand Up @@ -1853,14 +1853,14 @@ else if(HTMLelement.indexOf('#')!=-1)
}

fBuffer.append(HTMLelement);
if(!className.equals("")) {
if(!className.isEmpty()) {
fBuffer.append('.');
fBuffer.append(className);
} else if(!id.equals("")) {
} else if(!id.isEmpty()) {
fBuffer.append('#');
fBuffer.append(id);
}
if(!pseudoClass.equals("")) {
if(!pseudoClass.isEmpty()) {
fBuffer.append(':');
fBuffer.append(pseudoClass);
}
Expand Down Expand Up @@ -2361,7 +2361,7 @@ else if(parts[0] instanceof SimpleParsedWord && "@media".equals(((SimpleParsedWo
if(!isState1Present)
{
String s = buffer.toString().trim();
if(!(s.equals("") || s.equals("/") || s.equals("<") || s.equals("<!") || s.equals("<!-") || s.equals("<!--")))
if(!(s.isEmpty() || s.equals("/") || s.equals("<") || s.equals("<!") || s.equals("<!-") || s.equals("<!--")))
currentState=STATE2;
}
if(logDEBUG) Logger.debug(this, "STATE1 default CASE: "+c);
Expand Down Expand Up @@ -2450,7 +2450,7 @@ else if(parts[0] instanceof SimpleParsedWord && "@media".equals(((SimpleParsedWo
}

openBraces++;
if(!buffer.toString().trim().equals(""))
if(!buffer.toString().trim().isEmpty())
{
String filtered=recursiveSelectorVerifier(buffer.toString());
if(filtered!=null && !"".equals(filtered))
Expand Down Expand Up @@ -3847,7 +3847,7 @@ public static boolean isValidURI(ParsedURL word, FilterCallback cb)
{
//if(debug) Logger.debug(this, "CSSPropertyVerifier isVaildURI "+cb.processURI(URI, null));
String s = cb.processURI(w, null);
if(s == null || s.equals("")) return false;
if(s == null || s.isEmpty()) return false;
if(s.equals(w)) return true;
if(logDEBUG) Logger.debug(CSSTokenizerFilter.class, "New url: \""+s+"\" from \""+w+"\"");
word.setNewURL(s);
Expand Down Expand Up @@ -4012,7 +4012,7 @@ public boolean checkValidity(String[] media,String[] elements,ParsedWord[] words
// 2) We should sanitize the selectors, not just pass them on. Which in turn may
// cause them to take up more than one word!
String result = HTMLelementVerifier(words[0].original, true);
if (!(result == null || result.equals(""))) {
if (!(result == null || result.isEmpty())) {
return true;
}
}
Expand Down Expand Up @@ -4085,7 +4085,7 @@ public boolean checkValidity(String[] media,String[] elements,ParsedWord[] words
public boolean recursiveParserExpressionVerifier(String expression,ParsedWord[] words, FilterCallback cb)
{
if(logDEBUG) Logger.debug(this, "1recursiveParserExpressionVerifier called: with "+expression+" "+toString(words));
if((expression==null || ("".equals(expression.trim()))))
if((expression==null || (expression.trim().isEmpty())))
{
if(words==null || words.length == 0)
return true;
Expand Down Expand Up @@ -4116,7 +4116,7 @@ public boolean recursiveParserExpressionVerifier(String expression,ParsedWord[]
if(endIndex!=expression.length())
secondPart=expression.substring(endIndex+1,expression.length());
int j = 1;
if((secondPart.equals(""))) {
if((secondPart.isEmpty())) {
// This is an optimisation: If no second part, there cannot be any words assigned to the second part, so the first part must match everything.
// It is equivalent to running the loop, because each time the second part will fail, because it is trying to match "" to a nonzero number of words.
// This happens every time we have "1a2a3" with nothing after it, so it is tested by the unit tests already.
Expand Down Expand Up @@ -4276,7 +4276,7 @@ public boolean doubleAmpersandVerifier(String expression, ParsedWord[] words, Fi
List<CSSPropertyVerifier> propertyVerifierList = new ArrayList<CSSPropertyVerifier>();
for (int i = 0; i <= expression.length(); i++) {
if(i == expression.length() || expression.charAt(i)=='b') {
if(!firstPart.equals("")) {
if(!firstPart.isEmpty()) {
if(ignoredParts.length() == 0) {
ignoredParts = firstPart;
} else {
Expand Down Expand Up @@ -4468,7 +4468,7 @@ public boolean recursiveDoubleBarVerifier(String expression,ParsedWord[] words,F
{
if(i == expression.length() || expression.charAt(i)=='a')
{
if(!firstPart.equals("")) {
if(!firstPart.isEmpty()) {
if(ignoredParts.length() == 0)
ignoredParts = firstPart;
else
Expand Down Expand Up @@ -4502,9 +4502,9 @@ public boolean recursiveDoubleBarVerifier(String expression,ParsedWord[] words,F
}
// Against the rest of the pattern: the part that we've tried and failed plus the part that we haven't tried yet.
// NOT against the verifier we were just considering, because the double-bar operator expects no more than one match from each component of the pattern.
String pattern = ignoredParts+((("".equals(ignoredParts))||("".equals(secondPart)))?"":"a")+secondPart;
String pattern = ignoredParts+(((ignoredParts.isEmpty())||(secondPart.isEmpty()))?"":"a")+secondPart;
if(logDEBUG) Logger.debug(this, "14a "+toString(getSubArray(words, 0, j+1))+" can be consumed by "+index+ " passing on expression="+pattern+ " value="+toString(valueToPass));
if(pattern.equals("")) return false;
if(pattern.isEmpty()) return false;
result=recursiveDoubleBarVerifier(pattern,valueToPass, cb);
if(result)
{
Expand Down
2 changes: 1 addition & 1 deletion src/freenet/client/filter/ElementInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public static String getPseudoClassArg(String cname, String cname_sans_arg) {
int cnameIndex=cname.indexOf(cname_sans_arg);
int firstIndex=cname.indexOf('(');
int secondIndex=cname.lastIndexOf(')');
if(cname.substring(cnameIndex+cname_sans_arg.length(),firstIndex).trim().equals("") && cname.substring(0,cnameIndex).trim().equals("") && cname.substring(secondIndex+1,cname.length()).trim().equals(""))
if(cname.substring(cnameIndex + cname_sans_arg.length(), firstIndex).trim().isEmpty() && cname.substring(0, cnameIndex).trim().isEmpty() && cname.substring(secondIndex + 1, cname.length()).trim().isEmpty())
{
arg=CSSTokenizerFilter.removeOuterQuotes(cname.substring(firstIndex+1,secondIndex).trim());
}
Expand Down
2 changes: 1 addition & 1 deletion src/freenet/client/filter/FilterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ public static String[] removeWhiteSpace(String[] values, boolean stripQuotes)
value = value.trim();
if(stripQuotes)
value = CSSTokenizerFilter.removeOuterQuotes(value).trim();
if(value!=null && !("".equals(value.trim())))
if(value!=null && !(value.trim().isEmpty()))
arrayToReturn.add(value);
}
return arrayToReturn.toArray(new String[0]);
Expand Down
10 changes: 5 additions & 5 deletions src/freenet/client/filter/HTMLFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void run() throws IOException, DataFilterException {
if(textAllowed) {
saveText(b, currentTag, w, this);
} else {
if(!b.toString().trim().equals(""))
if(!b.toString().trim().isEmpty())
throwFilterException(l10n("textBeforeHTML"));
}
break;
Expand Down Expand Up @@ -294,7 +294,7 @@ void run() throws IOException, DataFilterException {
if(textAllowed) {
saveText(b, currentTag, w, this);
} else {
if(!b.toString().trim().equals(""))
if(!b.toString().trim().isEmpty())
throwFilterException(l10n("textBeforeHTML"));
}
b.setLength(0);
Expand All @@ -316,7 +316,7 @@ void run() throws IOException, DataFilterException {
if(textAllowed) {
saveText(b, currentTag, w, this);
} else {
if(!b.toString().trim().equals(""))
if(!b.toString().trim().isEmpty())
throwFilterException(l10n("textBeforeHTML"));
}

Expand Down Expand Up @@ -454,7 +454,7 @@ void run() throws IOException, DataFilterException {
if(textAllowed) {
saveText(b, currentTag, w, this);
} else {
if(!b.toString().trim().equals(""))
if(!b.toString().trim().isEmpty())
throwFilterException(l10n("textBeforeHTML"));
}
balt.setLength(0);
Expand Down Expand Up @@ -3066,7 +3066,7 @@ Map<String, Object> sanitizeHash(Map<String, Object> h,
throwFilterException(l10n("invalidMetaType"));
} else if (
http_equiv.equalsIgnoreCase("Content-Language")) {
if(content.matches("((?>[a-zA-Z0-9]*)(?>-[A-Za-z0-9]*)*(?>,\\s*)?)*") && (!content.trim().equals(""))) {
if(content.matches("((?>[a-zA-Z0-9]*)(?>-[A-Za-z0-9]*)*(?>,\\s*)?)*") && (!content.trim().isEmpty())) {
hn.put("http-equiv", "Content-Language");
hn.put("content", content);
}
Expand Down
4 changes: 2 additions & 2 deletions src/freenet/clients/fcp/AddPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void run(FCPConnectionHandler handler, Node node) throws MessageInvalidEx
throw new MessageInvalidException(ProtocolErrorMessage.URL_PARSE_ERROR, "IO error while retrieving ref URL <"+urlString+">: "+e.getMessage(), identifier, false);
}
ref = new StringBuilder(ref.toString().trim());
if("".equals(ref.toString())) {
if(ref.toString().isEmpty()) {
throw new MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing ref from URL <"+urlString+ '>', identifier, false);
}
try {
Expand Down Expand Up @@ -166,7 +166,7 @@ public void run(FCPConnectionHandler handler, Node node) throws MessageInvalidEx
throw new MessageInvalidException(ProtocolErrorMessage.FILE_PARSE_ERROR, "IO error while retrieving ref file <"+fileString+">: "+e.getMessage(), identifier, false);
}
ref = new StringBuilder(ref.toString().trim());
if("".equals(ref.toString())) {
if(ref.toString().isEmpty()) {
throw new MessageInvalidException(ProtocolErrorMessage.REF_PARSE_ERROR, "Error parsing ref from file <"+fileString+ '>', identifier, false);
}
try {
Expand Down
2 changes: 1 addition & 1 deletion src/freenet/clients/fcp/ClientPut.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public ClientPut(FCPConnectionHandler handler, ClientPutMessage message, FCPServ
if ((mimeType == null) && (targetFilename != null)) {
mimeType = DefaultMIMETypes.guessMIMEType(targetFilename, true);
}
if(mimeType != null && mimeType.equals("")) mimeType = null;
if(mimeType != null && mimeType.isEmpty()) mimeType = null;
if(mimeType != null && !DefaultMIMETypes.isPlausibleMIMEType(mimeType)) {
throw new MessageInvalidException(ProtocolErrorMessage.BAD_MIME_TYPE, "Bad MIME type in Metadata.ContentType", identifier, global);
}
Expand Down
2 changes: 1 addition & 1 deletion src/freenet/clients/fcp/ClientPutBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected ClientPutBase() {

static FreenetURI checkEmptySSK(FreenetURI uri, String filename, ClientContext context) {
if("SSK".equals(uri.getKeyType()) && uri.getDocName() == null && uri.getRoutingKey() == null) {
if(filename == null || filename.equals("")) filename = "key";
if(filename == null || filename.isEmpty()) filename = "key";
// SSK@ = use a random SSK.
InsertableClientSSK key = InsertableClientSSK.createRandom(context.random, "");
return key.getInsertURI().setDocName(filename);
Expand Down
2 changes: 1 addition & 1 deletion src/freenet/clients/fcp/DirPutFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static DirPutFile create(SimpleFieldSet subset, String identifier, boolea
if(name == null)
throw new MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Missing field Name", identifier, global);
String contentTypeOverride = subset.get("Metadata.ContentType");
if(contentTypeOverride != null && (!contentTypeOverride.equals("")) && !DefaultMIMETypes.isPlausibleMIMEType(contentTypeOverride)) {
if(contentTypeOverride != null && !contentTypeOverride.isEmpty() && !DefaultMIMETypes.isPlausibleMIMEType(contentTypeOverride)) {
throw new MessageInvalidException(ProtocolErrorMessage.BAD_MIME_TYPE, "Bad MIME type in Metadata.ContentType", identifier, global);
}
String type = subset.get("UploadFrom");
Expand Down
2 changes: 1 addition & 1 deletion src/freenet/clients/fcp/FCPConnectionInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void realRun() throws IOException {
Closer.close(is);
return;
}
if(messageType.equals(""))
if(messageType.isEmpty())
continue;
fs = new SimpleFieldSet(lis, 4096, 128, true, true, true);

Expand Down
10 changes: 5 additions & 5 deletions src/freenet/clients/fcp/ModifyPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void run(FCPConnectionHandler handler, Node node) throws MessageInvalidEx
DarknetPeerNode dpn = (DarknetPeerNode) pn;
String isDisabledString = fs.get("IsDisabled");
if(isDisabledString != null) {
if(!isDisabledString.equals("")) {
if(!isDisabledString.isEmpty()) {
if(Fields.stringToBool(isDisabledString, false)) {
dpn.disablePeer();
} else {
Expand All @@ -63,25 +63,25 @@ public void run(FCPConnectionHandler handler, Node node) throws MessageInvalidEx
}
String isListenOnlyString = fs.get("IsListenOnly");
if(isListenOnlyString != null) {
if(!isListenOnlyString.equals("")) {
if(!isListenOnlyString.isEmpty()) {
dpn.setListenOnly(Fields.stringToBool(isListenOnlyString, false));
}
}
String isBurstOnlyString = fs.get("IsBurstOnly");
if(isBurstOnlyString != null) {
if(!isBurstOnlyString.equals("")) {
if(!isBurstOnlyString.isEmpty()) {
dpn.setBurstOnly(Fields.stringToBool(isBurstOnlyString, false));
}
}
String ignoreSourcePortString = fs.get("IgnoreSourcePort");
if(ignoreSourcePortString != null) {
if(!ignoreSourcePortString.equals("")) {
if(!ignoreSourcePortString.isEmpty()) {
dpn.setIgnoreSourcePort(Fields.stringToBool(ignoreSourcePortString, false));
}
}
String allowLocalAddressesString = fs.get("AllowLocalAddresses");
if(allowLocalAddressesString != null) {
if(!allowLocalAddressesString.equals("")) {
if(!allowLocalAddressesString.isEmpty()) {
dpn.setAllowLocalAddresses(Fields.stringToBool(allowLocalAddressesString, false));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/freenet/clients/http/ConnectionsToadlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,12 @@ public void handleMethodPOST(URI uri, final HTTPRequest request, ToadletContext

String trustS = request.getPartAsStringFailsafe("trust", 10);
FRIEND_TRUST trust = null;
if(trustS != null && !trustS.equals(""))
if(trustS != null && !trustS.isEmpty())
trust = FRIEND_TRUST.valueOf(trustS);

String visibilityS = request.getPartAsStringFailsafe("visibility", 10);
FRIEND_VISIBILITY visibility = null;
if(visibilityS != null && !visibilityS.equals(""))
if(visibilityS != null && !visibilityS.isEmpty())
visibility = FRIEND_VISIBILITY.valueOf(visibilityS);

if(trust == null && !isOpennet()) {
Expand Down
Loading

0 comments on commit ea0a195

Please sign in to comment.