Könnte mir bitte jemand helfen, diesen Java -Code zu verstehen? [geschlossen]Java

Java-Forum
Anonymous
 Könnte mir bitte jemand helfen, diesen Java -Code zu verstehen? [geschlossen]

Post by Anonymous »

Ich stehe gerade in Java auf den neuesten Stand und bin auf diesen Code gestoßen, den ich versuche, meinen Kopf herumzuwickeln, kann aber nicht ... :). Könnte mir jemand bitte helfen zu verstehen, was mit der folgenden Methode los ist? < /P>

Code: Select all

 private @NotNull HttpRoutePlanner proxyRoutePlanner(String proxyHostname, int proxyPort) {

String nonProxyHostsProperty = System.getProperty("http.nonProxyHosts");
String[] nonProxyHosts = nonProxyHostsProperty != null ? nonProxyHostsProperty.split("\\|") : new String[0];

HttpHost proxyHost = new HttpHost(proxyHostname, proxyPort);

return (httpHost, httpRequest, httpContext) -> {
if (Arrays.stream(nonProxyHosts).anyMatch(nonProxyHost -> FilenameUtils.wildcardMatch(httpHost.getHostName(), nonProxyHost, IOCase.INSENSITIVE))) {
return new HttpRoute(httpHost);
}
return new HttpRoute(httpHost, proxyHost);
};
}
Hier ist, was ich verstehe:
  • Die Methode speichert zunächst eine Liste von 'Non -Proxy' Hostnamen in ein Array von String s, nachdem sie von der http.nonproxyhostes -systems -codes -systems -symboles -system -achte it it tods tods tods the code systems -Eigenschaft. Httphost Objekt Verwenden Sie den ProxyHostName und proxyport übergeben in die ProxyroutePlanner () -Methode. Diese httphost -Methode wird später in der Methode beim Erstellen einer "Proxy" -Route (

    Code: Select all

    HttpRoute(httpHost, proxyHost)
    ).
Hier bin ich total verwirrt:

Was genau läuft die Rückgabe Anweisung des enthaltenden ProxyroutePlanner () Methode? Gibt es eine andere anonyme Funktion zurück, die noch etwas anderes zurückgibt (ein httproute Objekt)? Httphost befindet sich in der Liste der "Nicht -Proxy" -Hosts. Wenn dies der Fall ist, gibt es ein "Nicht -Proxy" -Httproute (httoHost) zurück, ansonsten für "Proxy" -Hosts, es gibt ein 'Proxy' httProute (httphost, proxyHost) Objekt zurück. Aber woher kommt diese Argumente? Httproute < /code>, das aussieht, wie

erneut aus der enthaltenden ProxyroutePlanner () < /code> -Methode zurückgegeben wird, dies ist jedoch nicht sinnvoll. Der Rückgabetyp der ProxyroutePlanner () ist nicht httproute , aber httproutePlanner ! und diese Objekte sind nicht einmal verwandt. Ich verstehe nichts. Könnte mir jemand bitte helfen zu verstehen, was mit dieser Funktion los ist? Jede Hilfe/Einsicht wäre sehr geschätzt. Vielen Dank für Ihre Zeit und Geduld im Voraus!

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post