Support
Quality
Security
License
Reuse
kandi has reviewed Java and discovered the below as its top functions. This is intended to give you an instant insight into Java implemented functionality, and help decide if they suit your requirements.
27天成为Java大神
Passing and retrieving MutableList or ArrayList from Activity A to B
// Packing and sending the data:
val i = Intent(context, GalleryShow::class.java)
i.putExtra("list", ArrayList(memes)) // where memes is your MutableList<Meme> property
startActivityForResult(i, 777)
// Unpacking the data in the other activity:
memes = intent.extras?.get("list") as MutableList<Meme>
How to write Javascript recipe.components.sort((a, b) => (a.components ? 1 : 0) - (b.components ? 1 : 0)) in Python?
components.sort((a, b) => (a ? 1 : 0) - (b ? 1 : 0))
components.sort(key=bool)
components.sort((a, b) => (a.components ? 1 : 0) - (b.components ? 1 : 0))
components.sort(key=lambda a: bool(a.components))
-----------------------
components.sort((a, b) => (a ? 1 : 0) - (b ? 1 : 0))
components.sort(key=bool)
components.sort((a, b) => (a.components ? 1 : 0) - (b.components ? 1 : 0))
components.sort(key=lambda a: bool(a.components))
-----------------------
components.sort((a, b) => (a ? 1 : 0) - (b ? 1 : 0))
components.sort(key=bool)
components.sort((a, b) => (a.components ? 1 : 0) - (b.components ? 1 : 0))
components.sort(key=lambda a: bool(a.components))
-----------------------
components.sort((a, b) => (a ? 1 : 0) - (b ? 1 : 0))
components.sort(key=bool)
components.sort((a, b) => (a.components ? 1 : 0) - (b.components ? 1 : 0))
components.sort(key=lambda a: bool(a.components))
Create a DateTimeFormater with an Optional Section at Beginning
.appendValue(TimecodeHour.HOUR, 3, 4, SignStyle.NEVER)
-----------------------
var formatter = new DateTimeFormatterBuilder()
.optionalStart()
.appendValue(HOUR_OF_DAY, 2, 4, SignStyle.NEVER).appendLiteral(":")
.appendValue(MINUTE_OF_HOUR, 2).appendLiteral(":")
.appendValue(SECOND_OF_MINUTE, 2)
.optionalEnd()
.optionalStart()
.parseDefaulting(HOUR_OF_DAY, 0)
.appendValue(MINUTE_OF_HOUR, 2).appendLiteral(":")
.appendValue(SECOND_OF_MINUTE, 2)
.optionalEnd()
.toFormatter(Locale.ENGLISH);
-----------------------
public static Duration parse(String timeCodeString) {
String iso8601 = timeCodeString
.replaceFirst("^(\\d{2,}):(\\d{2}):(\\d{2}\\.\\d{3})$", "PT$1H$2M$3S")
.replaceFirst("^(\\d{2}):(\\d{2}\\.\\d{3})$", "PT$1M$2S");
return Duration.parse(iso8601);
}
System.out.println(parse("20:33.123"));
System.out.println(parse("123:20:33.123"));
PT20M33.123S
PT123H20M33.123S
-----------------------
public static Duration parse(String timeCodeString) {
String iso8601 = timeCodeString
.replaceFirst("^(\\d{2,}):(\\d{2}):(\\d{2}\\.\\d{3})$", "PT$1H$2M$3S")
.replaceFirst("^(\\d{2}):(\\d{2}\\.\\d{3})$", "PT$1M$2S");
return Duration.parse(iso8601);
}
System.out.println(parse("20:33.123"));
System.out.println(parse("123:20:33.123"));
PT20M33.123S
PT123H20M33.123S
-----------------------
public static Duration parse(String timeCodeString) {
String iso8601 = timeCodeString
.replaceFirst("^(\\d{2,}):(\\d{2}):(\\d{2}\\.\\d{3})$", "PT$1H$2M$3S")
.replaceFirst("^(\\d{2}):(\\d{2}\\.\\d{3})$", "PT$1M$2S");
return Duration.parse(iso8601);
}
System.out.println(parse("20:33.123"));
System.out.println(parse("123:20:33.123"));
PT20M33.123S
PT123H20M33.123S
How to use a SHA256 MessageDigest in Java on Linux
MessageDigest.getInstance("SHA-256");
Set<String> messageDigest = Security.getAlgorithms("MessageDigest");
messageDigest.forEach(System.out::println);
-----------------------
MessageDigest.getInstance("SHA-256");
Set<String> messageDigest = Security.getAlgorithms("MessageDigest");
messageDigest.forEach(System.out::println);
Regex Pattern In Between Two Exact Strings
\\bFOLDER/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\\.txt\\b
How to required Date and time using Java?
import java.time.LocalDateTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class DateTest {
public static List<ZonedDateTime> getDaysBetweenDates(ZonedDateTime startDate, ZonedDateTime endDate, int interval) {
List<ZonedDateTime> dates = new ArrayList<>();
while (!startDate.isAfter(endDate)) {
dates.add(startDate);
if (Period.between(startDate.toLocalDate(), endDate.toLocalDate()).getDays() < interval) {
startDate = endDate;
}
else {
startDate = startDate.plusDays(interval);
}
dates.add(startDate);
startDate = startDate.plusDays(1);
}
return dates;
}
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss", Locale.ENGLISH);
List<ZonedDateTime> dates = getDaysBetweenDates(ZonedDateTime.of(LocalDateTime.parse("05/08/2021 00:00:00", formatter), ZoneId.systemDefault()),
ZonedDateTime.of(LocalDateTime.parse("15/08/2021 23:59:59", formatter), ZoneId.systemDefault()),
5);
for (int i = 0; i < dates.size(); i+=2) {
System.out.printf("%s to %s , ",
dates.get(i).format(formatter),
dates.get(i + 1).format(formatter));
}
}
}
05/08/2021 00:00:00 to 10/08/2021 00:00:00 , 11/08/2021 00:00:00 to 15/08/2021 23:59:59 ,
-----------------------
import java.time.LocalDateTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class DateTest {
public static List<ZonedDateTime> getDaysBetweenDates(ZonedDateTime startDate, ZonedDateTime endDate, int interval) {
List<ZonedDateTime> dates = new ArrayList<>();
while (!startDate.isAfter(endDate)) {
dates.add(startDate);
if (Period.between(startDate.toLocalDate(), endDate.toLocalDate()).getDays() < interval) {
startDate = endDate;
}
else {
startDate = startDate.plusDays(interval);
}
dates.add(startDate);
startDate = startDate.plusDays(1);
}
return dates;
}
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss", Locale.ENGLISH);
List<ZonedDateTime> dates = getDaysBetweenDates(ZonedDateTime.of(LocalDateTime.parse("05/08/2021 00:00:00", formatter), ZoneId.systemDefault()),
ZonedDateTime.of(LocalDateTime.parse("15/08/2021 23:59:59", formatter), ZoneId.systemDefault()),
5);
for (int i = 0; i < dates.size(); i+=2) {
System.out.printf("%s to %s , ",
dates.get(i).format(formatter),
dates.get(i + 1).format(formatter));
}
}
}
05/08/2021 00:00:00 to 10/08/2021 00:00:00 , 11/08/2021 00:00:00 to 15/08/2021 23:59:59 ,
-----------------------
public static void printDaysInPeriod(LocalDate start, LocalDate end, int interval) {
// provide some data structure that
Map<LocalDate, LocalDate> intervals = new TreeMap<LocalDate, LocalDate>();
// loop through the dates in the defined period
while (start.isBefore(end)) {
// use the interval as step
LocalDate intervalEnd = start.plusDays(interval);
// store the sub-interval in the data structure
intervals.put(start, intervalEnd);
// and rearrange "start" to be the day after the last sub-interval
start = intervalEnd.plusDays(1);
}
// provide a formatter that produces the desired output per datetime
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
"dd/MM/uuuu HH:mm:ss"
);
// provide a data structure for the output parts (Strings here)
List<String> intervalOutput = new ArrayList<>();
// stream the sub-intervals
intervals.entrySet().forEach(e ->
// then produce the desired output per sub-interval and store it
intervalOutput.add(e.getKey().atStartOfDay()
.format(formatter)
+ " to "
+ e.getValue()
.atTime(LocalTime.MAX)
.format(formatter)));
// finally output the sub-interval Strings comma-separated
System.out.println(String.join(" , ", intervalOutput));
}
public static void main(String[] args) {
// example dates defining an interval
String startInterval = "05/08/2021";
String endInterval = "15/08/2021";
// provide a parser that handles the format
DateTimeFormatter dateParser = DateTimeFormatter.ofPattern("dd/MM/uuuu");
// then parse the dates to LocalDates
LocalDate start = LocalDate.parse(startInterval, dateParser);
LocalDate end = LocalDate.parse(endInterval, dateParser);
// and use the method
printDaysInPeriod(start, end, 5);
}
05/08/2021 00:00:00 to 10/08/2021 23:59:59 , 11/08/2021 00:00:00 to 16/08/2021 23:59:59
-----------------------
public static void printDaysInPeriod(LocalDate start, LocalDate end, int interval) {
// provide some data structure that
Map<LocalDate, LocalDate> intervals = new TreeMap<LocalDate, LocalDate>();
// loop through the dates in the defined period
while (start.isBefore(end)) {
// use the interval as step
LocalDate intervalEnd = start.plusDays(interval);
// store the sub-interval in the data structure
intervals.put(start, intervalEnd);
// and rearrange "start" to be the day after the last sub-interval
start = intervalEnd.plusDays(1);
}
// provide a formatter that produces the desired output per datetime
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
"dd/MM/uuuu HH:mm:ss"
);
// provide a data structure for the output parts (Strings here)
List<String> intervalOutput = new ArrayList<>();
// stream the sub-intervals
intervals.entrySet().forEach(e ->
// then produce the desired output per sub-interval and store it
intervalOutput.add(e.getKey().atStartOfDay()
.format(formatter)
+ " to "
+ e.getValue()
.atTime(LocalTime.MAX)
.format(formatter)));
// finally output the sub-interval Strings comma-separated
System.out.println(String.join(" , ", intervalOutput));
}
public static void main(String[] args) {
// example dates defining an interval
String startInterval = "05/08/2021";
String endInterval = "15/08/2021";
// provide a parser that handles the format
DateTimeFormatter dateParser = DateTimeFormatter.ofPattern("dd/MM/uuuu");
// then parse the dates to LocalDates
LocalDate start = LocalDate.parse(startInterval, dateParser);
LocalDate end = LocalDate.parse(endInterval, dateParser);
// and use the method
printDaysInPeriod(start, end, 5);
}
05/08/2021 00:00:00 to 10/08/2021 23:59:59 , 11/08/2021 00:00:00 to 16/08/2021 23:59:59
-----------------------
public static void printDaysInPeriod(LocalDate start, LocalDate end, int interval) {
// provide some data structure that
Map<LocalDate, LocalDate> intervals = new TreeMap<LocalDate, LocalDate>();
// loop through the dates in the defined period
while (start.isBefore(end)) {
// use the interval as step
LocalDate intervalEnd = start.plusDays(interval);
// store the sub-interval in the data structure
intervals.put(start, intervalEnd);
// and rearrange "start" to be the day after the last sub-interval
start = intervalEnd.plusDays(1);
}
// provide a formatter that produces the desired output per datetime
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
"dd/MM/uuuu HH:mm:ss"
);
// provide a data structure for the output parts (Strings here)
List<String> intervalOutput = new ArrayList<>();
// stream the sub-intervals
intervals.entrySet().forEach(e ->
// then produce the desired output per sub-interval and store it
intervalOutput.add(e.getKey().atStartOfDay()
.format(formatter)
+ " to "
+ e.getValue()
.atTime(LocalTime.MAX)
.format(formatter)));
// finally output the sub-interval Strings comma-separated
System.out.println(String.join(" , ", intervalOutput));
}
public static void main(String[] args) {
// example dates defining an interval
String startInterval = "05/08/2021";
String endInterval = "15/08/2021";
// provide a parser that handles the format
DateTimeFormatter dateParser = DateTimeFormatter.ofPattern("dd/MM/uuuu");
// then parse the dates to LocalDates
LocalDate start = LocalDate.parse(startInterval, dateParser);
LocalDate end = LocalDate.parse(endInterval, dateParser);
// and use the method
printDaysInPeriod(start, end, 5);
}
05/08/2021 00:00:00 to 10/08/2021 23:59:59 , 11/08/2021 00:00:00 to 16/08/2021 23:59:59
-----------------------
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
public class Main {
public static void main(String[] args) {
String strStartDateTime = "1/08/2021 00:00:00";
String strEndDateTime = "20/08/2021 23:59:59";
DateTimeFormatter dtfInput = DateTimeFormatter.ofPattern("d/M/u H:m:s", Locale.ENGLISH);
LocalDateTime startDateTime = LocalDateTime.parse(strStartDateTime, dtfInput);
LocalDateTime endDateTime = LocalDateTime.parse(strEndDateTime, dtfInput);
DateTimeFormatter dtfOutput = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ENGLISH);
for (LocalDateTime ldt = startDateTime, nextDateTime = ldt.plusDays(10).minusSeconds(1); !ldt
.isAfter(endDateTime); ldt = ldt.plusDays(10), nextDateTime = ldt.plusDays(10).minusSeconds(1))
System.out.println(dtfOutput.format(ldt) + " - " + nextDateTime);
}
}
2021-08-01 00:00:00 - 2021-08-10T23:59:59
2021-08-11 00:00:00 - 2021-08-20T23:59:59
-----------------------
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
public class Main {
public static void main(String[] args) {
String strStartDateTime = "1/08/2021 00:00:00";
String strEndDateTime = "20/08/2021 23:59:59";
DateTimeFormatter dtfInput = DateTimeFormatter.ofPattern("d/M/u H:m:s", Locale.ENGLISH);
LocalDateTime startDateTime = LocalDateTime.parse(strStartDateTime, dtfInput);
LocalDateTime endDateTime = LocalDateTime.parse(strEndDateTime, dtfInput);
DateTimeFormatter dtfOutput = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ENGLISH);
for (LocalDateTime ldt = startDateTime, nextDateTime = ldt.plusDays(10).minusSeconds(1); !ldt
.isAfter(endDateTime); ldt = ldt.plusDays(10), nextDateTime = ldt.plusDays(10).minusSeconds(1))
System.out.println(dtfOutput.format(ldt) + " - " + nextDateTime);
}
}
2021-08-01 00:00:00 - 2021-08-10T23:59:59
2021-08-11 00:00:00 - 2021-08-20T23:59:59
While loop doesn't exit after file download
// upload side
void upload() {
Path p = Paths.get("/path/to/file/you/want/to/send");
long fileSize = Files.size(p);
out.write(longToBytes(fileSize);
try (InputStream in = Files.newInputStream(p)) {
in.transferTo(out);
}
}
public static byte[] longToBytes(long x) {
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
buffer.putLong(x);
return buffer.array();
}
void download() {
long size = bytesToLong(in.readNBytes(8));
Path p = Paths.get("/file/to/store/data/at");
// Generally network transfer sizes are a bit higher than 1k;
// up to 64k in fact. Best to declare a larger buffer!
byte[] bb = new byte[65536];
try (OutputStream out = Files.newOutputStream(p)) {
while (size > 0) {
int count = in.read(bb);
if (count == -1) throw new IOException("Unexpected end of stream");
out.write(bb, 0, count);
size -= count;
}
}
}
public static long bytesToLong(byte[] bytes) {
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
buffer.put(bytes);
buffer.flip();//need flip
return buffer.getLong();
}
-----------------------
// upload side
void upload() {
Path p = Paths.get("/path/to/file/you/want/to/send");
long fileSize = Files.size(p);
out.write(longToBytes(fileSize);
try (InputStream in = Files.newInputStream(p)) {
in.transferTo(out);
}
}
public static byte[] longToBytes(long x) {
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
buffer.putLong(x);
return buffer.array();
}
void download() {
long size = bytesToLong(in.readNBytes(8));
Path p = Paths.get("/file/to/store/data/at");
// Generally network transfer sizes are a bit higher than 1k;
// up to 64k in fact. Best to declare a larger buffer!
byte[] bb = new byte[65536];
try (OutputStream out = Files.newOutputStream(p)) {
while (size > 0) {
int count = in.read(bb);
if (count == -1) throw new IOException("Unexpected end of stream");
out.write(bb, 0, count);
size -= count;
}
}
}
public static long bytesToLong(byte[] bytes) {
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
buffer.put(bytes);
buffer.flip();//need flip
return buffer.getLong();
}
-----------------------
try (OutputStream out = new FileOutputStream(path)) {
final InputStream is = socket.getInputStream();
byte[] bytes = new byte[1024];
int count;
long receivedBytes = 0;
while (receivedBytes < byteSize && (count = is.read(bytes)) > 0) {
// if ((count = is.read(bytes)) <= 0) break;
out.write(bytes, 0, count);
receivedBytes = receivedBytes + count;
//System.out.println(count + " " + receivedBytes + "/" + byteSize);
}
}
Micronaut java httpclient creation with the existing server
@Singleton
public class MyClient {
private final RxHttpClient client;
public MyClient(@Client("https://some.third-party.com") RxHttpClient client) {
this.client = client;
}
HttpResponse<String> getSomething(Integer id) {
URI uri = UriBuilder.of("/some-objects").path(id).build();
return client.toBlocking().exchange(HttpRequest.GET(uri), String.class);
}
}
@Client("some-service")
public interface SomeServiceClient {
@Get("/api/some-objects/{id}")
String getSomeObject(@QueryValue("id") id: Integer);
}
micronaut:
http:
services:
some-service:
url: "https://some.third-party.com"
read-timeout: 1m
@Singleton
public class SomeServiceConsumer {
private final SomeServiceClient client;
public SomeServiceConsumer(SomeServiceClient client) {
this.client = client;
}
void doWithSomething(Integer id) {
String object = client.getSomeObject(id);
... // processing of object here
}
}
-----------------------
@Singleton
public class MyClient {
private final RxHttpClient client;
public MyClient(@Client("https://some.third-party.com") RxHttpClient client) {
this.client = client;
}
HttpResponse<String> getSomething(Integer id) {
URI uri = UriBuilder.of("/some-objects").path(id).build();
return client.toBlocking().exchange(HttpRequest.GET(uri), String.class);
}
}
@Client("some-service")
public interface SomeServiceClient {
@Get("/api/some-objects/{id}")
String getSomeObject(@QueryValue("id") id: Integer);
}
micronaut:
http:
services:
some-service:
url: "https://some.third-party.com"
read-timeout: 1m
@Singleton
public class SomeServiceConsumer {
private final SomeServiceClient client;
public SomeServiceConsumer(SomeServiceClient client) {
this.client = client;
}
void doWithSomething(Integer id) {
String object = client.getSomeObject(id);
... // processing of object here
}
}
-----------------------
@Singleton
public class MyClient {
private final RxHttpClient client;
public MyClient(@Client("https://some.third-party.com") RxHttpClient client) {
this.client = client;
}
HttpResponse<String> getSomething(Integer id) {
URI uri = UriBuilder.of("/some-objects").path(id).build();
return client.toBlocking().exchange(HttpRequest.GET(uri), String.class);
}
}
@Client("some-service")
public interface SomeServiceClient {
@Get("/api/some-objects/{id}")
String getSomeObject(@QueryValue("id") id: Integer);
}
micronaut:
http:
services:
some-service:
url: "https://some.third-party.com"
read-timeout: 1m
@Singleton
public class SomeServiceConsumer {
private final SomeServiceClient client;
public SomeServiceConsumer(SomeServiceClient client) {
this.client = client;
}
void doWithSomething(Integer id) {
String object = client.getSomeObject(id);
... // processing of object here
}
}
-----------------------
@Singleton
public class MyClient {
private final RxHttpClient client;
public MyClient(@Client("https://some.third-party.com") RxHttpClient client) {
this.client = client;
}
HttpResponse<String> getSomething(Integer id) {
URI uri = UriBuilder.of("/some-objects").path(id).build();
return client.toBlocking().exchange(HttpRequest.GET(uri), String.class);
}
}
@Client("some-service")
public interface SomeServiceClient {
@Get("/api/some-objects/{id}")
String getSomeObject(@QueryValue("id") id: Integer);
}
micronaut:
http:
services:
some-service:
url: "https://some.third-party.com"
read-timeout: 1m
@Singleton
public class SomeServiceConsumer {
private final SomeServiceClient client;
public SomeServiceConsumer(SomeServiceClient client) {
this.client = client;
}
void doWithSomething(Integer id) {
String object = client.getSomeObject(id);
... // processing of object here
}
}
How do I use a Transaction in a Reactive Flow in Spring Integration?
/**
* Populate a {@link FluxMessageChannel} to start a reactive processing for upstream data,
* wrap it to a {@link Flux}, apply provided {@link Function} via {@link Flux#transform(Function)}
* and emit the result to one more {@link FluxMessageChannel}, subscribed in the downstream flow.
* @param fluxFunction the {@link Function} to process data reactive manner.
* @param <I> the input payload type.
* @param <O> the output type.
* @return the current {@link BaseIntegrationFlowDefinition}.
*/
@SuppressWarnings(UNCHECKED)
public <I, O> B fluxTransform(Function<? super Flux<Message<I>>, ? extends Publisher<O>> fluxFunction) {
Swing JMenuBar not rendering properly
import java.util.*;
import javax.swing.*;
public class App implements Runnable {
private static final long serialVersionUID = 6924949643971067836L;
private static final Character[] VALID_CHARS = {'!', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+'};
private static final Character[] LOWER_ALPHA = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
private static final Character[] UPPER_ALPHA = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
private static final Character[] VALID_NUMS = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
private static final String[] KEYBOARD_COMBOS = {"qwe", "wer", "ert", "rty", "tyu", "yui", "uio", "iop", "asd", "sdf", "dfg", "fgh", "gjh", "hjk", "jkl", "zxc", "xcv", "cvb", "vbn", "bnm"};
private Scanner scanner;
private String password;
private Integer score;
private List<Character> pass;
private JFrame parent;
private JLabel frameScore;
private boolean num = false;
private boolean upper = false;
private boolean lower = false;
private boolean character = false;
public App() { }
private void checkPassword() {
System.out.println("Checking password...");
}
private void generatePassword() {
System.out.println("Generating password...");
}
private void why() {
System.out.println("Why...");
}
protected JPanel createContent() {
JPanel mainPanel = new JPanel();
JButton check = new JButton("Check Password");
JButton generate = new JButton("Generate Password");
check.addActionListener(e -> this.checkPassword());
generate.addActionListener(e -> this.generatePassword());
check.setBounds(500,500, 170, 50);
generate.setBounds(500, 200, 170, 50);
mainPanel.add(check);
mainPanel.add(generate);
return mainPanel;
}
protected JMenuBar createMenu() {
JMenuBar menuBar = new JMenuBar();
JMenu checkPass = new JMenu("Check Password");
JMenu resetPass = new JMenu("Generate Password");
JMenu extraCodes = new JMenu("Extra Codes");
JMenuItem enterPass = new JMenuItem("Enter password >>>");
JMenuItem generatePass = new JMenuItem("Generate >>>");
JMenuItem verify = new JMenuItem("Valid >>>");
JMenuItem about = new JMenuItem("Why >>>");
enterPass.addActionListener(e -> this.checkPassword());
generatePass.addActionListener(e -> this.generatePassword());
verify.addActionListener(e -> JOptionPane.showMessageDialog(this.parent, Arrays.asList(VALID_CHARS).toString(), "Valid Characters", JOptionPane.PLAIN_MESSAGE));
about.addActionListener(e -> this.why());
menuBar.add(checkPass);
menuBar.add(resetPass);
menuBar.add(extraCodes);
checkPass.add(enterPass);
resetPass.add(generatePass);
extraCodes.add(verify);
extraCodes.add(about);
return menuBar;
}
@Override
public void run() {
this.parent = new JFrame();
this.parent.setJMenuBar(createMenu());
this.parent.setContentPane(createContent());
this.parent.pack();
this.parent.setLocationRelativeTo(null);
this.parent.setVisible(true);
}
public static void main(String[] args) {
try {
SwingUtilities.invokeAndWait(new App());
} catch (Exception e) {
e.printStackTrace();
}
}
}
QUESTION
maven multi-module project with two versions of protobuf
Asked 2021-Jun-15 at 21:40We have a multi-module maven project. One of the modules has a bunch of .proto
files, which we compile to java files. Pretty much every other module depends on this module. Most of them use Protobuf 2.4, but one needs to use 2.5.
Is there any nice way to do this? (The not nice way is to edit the pom file to say "2.5", build a jar, manually copy that jar to wherever we need it, and then change the pom file back to 2.4.)
ANSWER
Answered 2021-Jun-08 at 13:59Never used protobuf, but, as I understand it's a plugin that generate stuff.
So I'm gonna give you generic pointer hoping it will help. I think you should either try to make 2 jar with different classifier from a single module, see https://maven.apache.org/plugins/maven-jar-plugin/examples/attached-jar.html For example classifier proto2.4 and proto2.5 then you can add the classifier when you define the dependency to that module.
Other option I see is having 2 modules, the real one, you have now, and another one for 2.5 Generate a zip from the main one and the second module would be empty but have a dependency on the generated zip, unzip it and then compile with the plugin config for 2.5 Slower at execution, a bit dirtier imho, but can be needed if for example you need more customization than just the version.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit