Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testproject8;
- import java.io.IOException;
- import java.io.InvalidObjectException;
- import java.io.ObjectInputStream;
- import java.io.Serializable;
- import java.io.UncheckedIOException;
- import java.lang.annotation.ElementType;
- import java.lang.annotation.Retention;
- import java.lang.annotation.RetentionPolicy;
- import java.lang.annotation.Target;
- import java.math.BigDecimal;
- import java.math.MathContext;
- import java.math.RoundingMode;
- import java.nio.ByteBuffer;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.time.LocalTime;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.EnumMap;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- import java.util.Optional;
- import java.util.OptionalDouble;
- import java.util.PriorityQueue;
- import java.util.Random;
- import java.util.RandomAccess;
- import java.util.Set;
- import java.util.Spliterator;
- import java.util.Spliterators;
- import java.util.concurrent.Callable;
- import java.util.concurrent.atomic.AtomicInteger;
- import java.util.function.BiConsumer;
- import java.util.function.BiFunction;
- import java.util.function.Consumer;
- import java.util.function.DoubleBinaryOperator;
- import java.util.function.Function;
- import java.util.function.IntBinaryOperator;
- import java.util.function.IntConsumer;
- import java.util.function.IntFunction;
- import java.util.function.IntUnaryOperator;
- import java.util.function.Predicate;
- import java.util.function.Supplier;
- import java.util.regex.Pattern;
- import java.util.stream.Collector;
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- import java.util.stream.Stream;
- import java.util.stream.StreamSupport;
- import javafx.scene.control.TableCell;
- import javafx.scene.control.TableColumn;
- import javafx.util.Callback;
- import testproject8.package1.MyEnum;
- /**
- *
- * @author Beheerder
- */
- public class TestProject8 {
- private Map<Class<?>, Object> values;
- private void init() {
- String strinzzz = "afdgdfdds";
- strinzzz.substring(5);
- PriorityQueue<String> pqs = new PriorityQueue<>();
- LinkedList<Integer> ll = new LinkedList<>();
- Set<String> ssere = new HashSet<>();
- Stream<String> streamString = Stream.of("a", "b", "c");
- String[] stringArray = streamString.toArray(String[]::new);
- Arrays.stream(stringArray).forEach(System.out::println);
- Map<String, String> map = Stream.of("A,1,!","B,2,@","C,3,#","D,4,$","E,5,%")
- .map(line -> line.split(","))
- .collect(Collectors.toMap(
- array -> array[0],
- array -> array[1]
- ));
- map.forEach((k, v) -> System.out.println("Key = " + k + " / Value = " + v));
- Set<Notifiable> set = new HashSet<>();
- set.add(new NotifiableImpl1());
- set.add(new NotifiableImpl2());
- set.add(new NotifiableImpl3());
- Set<? extends Notifiable> set3 = set;
- Set<? extends Notifiable> set2 = new HashSet<>();
- // set2.add(new NotifiableImpl1());
- // set2.add(new NotifiableImpl2());
- // set2.add(new NotifiableImpl3());
- String input = "abcdd";
- long count = input.chars()
- .distinct()
- .count();
- System.out.println(count);
- AtomicInteger integer = new AtomicInteger(0);
- IntStream.range(0, 1000000)
- .parallel()
- .forEach(i -> integer.getAndIncrement());
- System.out.println(integer.get());
- Callback<TableColumn<Factura, BigDecimal>, TableCell<Factura, BigDecimal>> moneyCellFactoryOld =
- new Callback<TableColumn<Factura, BigDecimal>, TableCell<Factura, BigDecimal>>() {
- public TableCell call(TableColumn p) {
- return new MoneyFormatCell();
- }
- };
- Callback<TableColumn<Factura, BigDecimal>, TableCell<Factura, BigDecimal>> moneyCellFactory = column -> new MoneyFormatCell();
- List<Employee> employeeList = new ArrayList<>();
- // employeeList.sort(Comparator.comparingInt(Employee::getEmpSalary).reversed());
- employeeList.sort(
- Comparator.comparing(Employee::getEmpName)
- .thenComparingInt(Employee::getEmpSalary)
- );
- List<String> list = Collections.nCopies(6, "abc");
- list.forEach(System.out::println);
- long a = 0L;
- if (a > Integer.MAX_VALUE) {
- }
- Stream<Class<?>> stream = Stream.of(NotifiableImpl1.class, NotifiableImpl2.class, NotifiableImpl3.class);
- HashMap<Class<?>, List<Class<?>>> hashMap = stream
- .collect(Collectors.groupingBy(
- Class::getSuperclass,
- HashMap::new,
- Collectors.toList()
- ));
- hashMap.forEach((k, v) -> System.out.println("Key = " + k + " / Value = " + v));
- SubClass sub = new SubClass(5);
- UnrelatedInterfaceDefault unrelated = new UnrelatedClass();
- unrelated.unrelate();
- List<BigDecimal> bdList = new ArrayList<>();
- BigDecimal result2 = bdList.stream()
- .reduce(BigDecimal.ZERO, BigDecimal::add);
- //
- // List<Invoice> invoiceList = new ArrayList<>();
- // //populate
- // Function<Invoice, BigDecimal> totalMapper = invoice -> invoice.getUnit_price().multiply(invoice.getQuantity());
- // BigDecimal result = invoiceList.stream()
- // .map(totalMapper)
- // .reduce(BigDecimal.ZERO, BigDecimal::add);
- List<Invoice> invoiceList = new ArrayList<>();
- //populate
- BigDecimal result = invoiceList.stream()
- .map(Invoice::total)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
- List<Person> personList = new ArrayList<>();
- personList.add(new Person("Shannon", "Goldstein"));
- personList.add(new Person("Donnie", "Denney"));
- personList.add(new Person("Mark", "Thomas"));
- personList.add(new Person("Julia", "Thomas"));
- Map<String, List<Person>> personMapping = personList.stream()
- .collect(Collectors.groupingBy(Person::getLastName));
- System.out.println("personMapping = " + personMapping);
- // List<String> listString = new ArrayList<>();
- // for (String str : listString) {
- // if (str.charAt(0) == ' ') {
- // // do something with str
- // }
- // }
- List<String> listString = new ArrayList<>();
- List<String> filteredString = listString.stream()
- .filter(s -> s.charAt(0) == ' ')
- .collect(Collectors.toList());
- List<String> stringList = new ArrayList<>();
- stringList.add("a");
- stringList.add("hg");
- stringList.add("dsl");
- stringList.add("sldi");
- stringList.add("ilsdo");
- stringList.add("jlieio");
- Predicate<String> predicate = str -> (str.length() >= 3);
- Map<Boolean, List<String>> mapping = stringList.stream()
- .collect(Collectors.partitioningBy(predicate));
- List<Integer> testList = new ArrayList<>();
- IntStream.rangeClosed(0, 10)
- .forEach(testList::add);
- testList.forEach(System.out::println);
- LinkedList<User> users = new LinkedList<>();
- users.add(new User(1, "User1"));
- users.add(new User(2, "User2"));
- users.add(new User(3, "User3"));
- List<User> resultUserList = users.stream()
- .filter(user -> user.getId() == 1)
- .collect(Collectors.toList());
- if (resultUserList.size() != 1) {
- throw new IllegalStateException();
- }
- User resultUser = resultUserList.get(0);
- System.out.println("resultUser = " + resultUser);
- User resultTwoUser = users.stream()
- .filter(user -> user.getId() > 2)
- .collect(singletonCollector());
- System.out.println("resultTwoUser = " + resultTwoUser);
- // Integer[] integerArray = new Integer[1024];
- // int[] intArray = new int[1024];
- // Arrays.setAll(intArray, i -> integerArray[i]);
- // int t = 1024;
- // Player[] p = new Player[t];
- // Arrays.sort(p, Comparator.comparingInt(Player::getNumber));
- boolean checkOne = containsAllChars("helloworld", "asdfuvjerhelloworld");
- System.out.println("checkOne = " + checkOne);
- boolean checkTwo = containsAllChars("helloworld", "lshewodxzr");
- System.out.println("checkTwo = " + checkTwo);
- boolean checkThree = containsAllChars("helloworld", "abc");
- System.out.println("checkThree = " + checkThree);
- List<String> listOfStrings = new ArrayList<>();
- listOfStrings.add("christopher hitchens");
- listOfStrings.add("william craig");
- listOfStrings.forEach(this::mapper);
- CustomList<String> cstmLst = new CustomList<>();
- cstmLst.add("a");
- cstmLst.add("b");
- Collections.sort(cstmLst);
- init2();
- }
- private void init2() {
- List<Callable<Double>> list = IntStream.range(1, 99)
- .<Callable<Double>>mapToObj(value -> (() -> calculateResult(value)))
- .collect(Collectors.toList());
- //
- // List<Callable> list2 = IntStream.range(1, 99)
- // .mapToObj(value -> (() -> calculateResult(value)))
- //
- // IntStream.range(1, 99)
- // .mapToObj(value -> (() -> calculateResult(value)));
- init3();
- }
- private void init3() {
- // String result = Stream.of("a", "b", "c", "de", "fg", "hij")
- // .map(this::resolve)
- // .flatMap(CustomOptionalOld::flatStream)
- // .findFirst()
- // .get();
- // String result = Stream.of("a", "b", "c", "de", "fg", "hij")
- // .map(this::resolve)
- // .map(CustomOptionalOld::getTOrNull)
- // .findFirst()
- // .get();
- init4();
- }
- private void init4() {
- Collection<String> input = Arrays.asList("1", "2", "3");
- Function<String, String> mapper = x -> x + " " + x;
- Predicate<String> filter = y -> !y.startsWith("1");
- Collector<String, ?, List<String>> toList = Collectors.toList();
- List<String> list = ((Supplier<List<String>>)toList.supplier()).get();
- for (String in : input) {
- in = mapper.apply(in);
- if (filter.test(in)) {
- ((BiConsumer<List<String>, String>)toList.accumulator()).accept(list, in);
- }
- }
- System.out.println("list = " + list);
- init5();
- }
- private void init5() {
- Stream<Integer> stream1 = null;
- Stream<Integer> stream2 = null;
- Integer element = null;
- // Stream<Integer> resultStream = Stream.concat(stream1, Stream.concat(stream2, Stream.of(element)))
- // .filter(x -> x != 0)
- // .filter(x -> x != 1)
- // .filter(x -> x != 2);
- // Stream<Integer> resultStream = Stream.concat(
- // stream1,
- // stream2,
- // Stream.of(element)
- // )
- // .filter(x -> x != 0)
- // .filter(x -> x != 1)
- // .filter(x -> x != 2);
- init6();
- }
- private void init6() {
- int[] array = new int[1024];
- //fill
- int[] arrayWithoutDuplicates = Arrays.stream(array)
- .distinct()
- .toArray();
- fakingRandomAccess();
- init7();
- }
- // private void init7() {
- // IntStream tstream = IntStream.rangeClosed(1, 100000000);
- // Collector<Object, ?, Map<Object, List<Object>>> collector = Collectors.groupingBy(i -> Thread.currentThread());
- // Map<Object, List<Object>> coll = tstream.boxed().parallel().collect(collector);
- // coll.replaceAll((thread, list) -> Arrays.asList(list.size()));
- // System.out.println(coll.size() + " threads was used: " + coll);
- // }
- // private void init7() {
- // for (int i = 0; i < 2; i++) {
- // try (Scanner scanner = new Scanner(System.in)) {
- // while (scanner.hasNextInt()) {
- // int next = scanner.nextInt();
- // if (next == 0) {
- // break;
- // }
- // System.out.println("Input was: " + next);
- // }
- // }
- // }
- // }
- // private void init7() {
- // try {
- // long size = Files.walk(Paths.get("C://"))
- // .parallel()
- // .peek(System.out::println)
- // .mapToLong(this::fileSize)
- // .sum();
- // System.out.println("size = " + size);
- // } catch (IOException ex) {
- // Logger.getLogger(TestProject8.class.getName()).log(Level.SEVERE, null, ex);
- // }
- // }
- private long fileSize(final Path path) {
- try {
- return Files.size(path);
- } catch (IOException | UncheckedIOException ex) {
- return 0;
- }
- }
- // private <E> void takeList(List<E> list) {
- //
- // }
- // private <E> void takeList(ArrayList<E> list) {
- //
- // }
- private <E, T extends List<E> & RandomAccess> void takeList(T list) {
- }
- private void fakingRandomAccess() {
- // List<Integer> linkedList = new LinkedList<>();
- // takeList((List<Integer> & RandomAccess)linkedList);
- // List<Integer> linkedList = (List<Integer> & RandomAccess)new LinkedList<Integer>();
- // takeList(linkedList);
- }
- private void init7() {
- IntStream.range(0, 100)
- .boxed()
- .collect(topPercentFromRangeCollector(Comparator.comparingInt(i -> i), 0.1d, 0.3d))
- .forEach(System.out::println);
- init8();
- }
- private <T> Collector<T, ?, Stream<T>> topPercentFromRangeCollector(Comparator<T> comparator, double from, double to) {
- return Collectors.collectingAndThen(
- Collectors.toList(),
- list -> list.stream()
- .sorted(comparator)
- .skip((long)(list.size() * from))
- .limit((long)(list.size() * (to - from)))
- );
- }
- private <T> CustomOptionalOld<T> resolve(final T input) {
- if (new Random().nextBoolean()) {
- return CustomOptionalOld.ofNullable(input);
- }
- return CustomOptionalOld.empty();
- }
- private String mapper(final String input) {
- String[] parts = input.split(" ");
- return parts[1] + ", " + parts[0];
- }
- public double calculateResult(int value) {
- return 0.0d;
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- new TestProject8().init();
- }
- public static long countUniqueCharacters(String input) {
- return input.chars()
- .distinct()
- .count();
- }
- public static <T> Collector<T, ?, T> singletonCollector() {
- return Collectors.collectingAndThen(
- Collectors.toList(),
- list -> {
- if (list.size() != 1) {
- throw new IllegalStateException();
- }
- return list.get(0);
- }
- );
- }
- public boolean check(final String firstString, final String secondString) {
- //Create a map mapping all characters from the firstString to true/false
- Map<Character, Boolean> map = IntStream.rangeClosed('a', 'z')
- .boxed()
- .collect(Collectors.toMap(
- i -> (char)(int)i,
- i -> firstString.chars().anyMatch(j -> j == i)
- ));
- return map.entrySet().stream()
- .filter(entry -> entry.getValue() == true)
- .map(Map.Entry::getKey)
- .allMatch(ch -> secondString.chars().anyMatch(i -> i == ch));
- }
- public boolean containsAllChars(String a, String b) {
- List<Character> aChars = stringToCharacterList(a);
- List<Character> bChars = stringToCharacterList(b);
- return bChars.containsAll(aChars);
- }
- public List<Character> stringToCharacterList(String input) {
- return input.chars().distinct()
- .mapToObj(i -> (char)i)
- .collect(Collectors.toList());
- }
- public <T, U, R> Collection<R> singleCollectionOf(final Collection<T> collectionA, final Collection<U> collectionB, final Supplier<Collection<R>> supplier, final BiFunction<T, U, R> mapper) {
- if (Objects.requireNonNull(collectionA).size() != Objects.requireNonNull(collectionB).size()) {
- throw new IllegalArgumentException();
- }
- Objects.requireNonNull(supplier);
- Objects.requireNonNull(mapper);
- Iterator<T> iteratorA = collectionA.iterator();
- Iterator<U> iteratorB = collectionB.iterator();
- Collection<R> returnCollection = supplier.get();
- while (iteratorA.hasNext() && iteratorB.hasNext()) {
- returnCollection.add(mapper.apply(iteratorA.next(), iteratorB.next()));
- }
- return returnCollection;
- }
- private void init8() {
- List<Integer> list1 = IntStream.range(0, 10).boxed().collect(Collectors.toList());
- List<Integer> list2 = IntStream.range(0, 10).map(n -> n * n + 1).boxed().collect(Collectors.toList());
- singleCollectionOf(list1, list2, ArrayList::new, Pair::new).stream().forEach(System.out::println);
- init9();
- }
- private void init9() {
- values = new HashMap<>();
- values.put(Pet.class, new Pet());
- values.put(Car.class, new Car());
- System.out.println("get(Pet.class).getClass() = " + get(Pet.class).getClass());
- System.out.println("get(Car.class).getClass() = " + get(Car.class).getClass());
- init10();
- }
- @SuppressWarnings("unchecked")
- private <T> T get(Class<T> clazz) {
- return (T)values.get(clazz);
- }
- private void init10() {
- System.out.println("ContentType.values(SubType.MAIL) = " + ContentType.values(SubType.MAIL));
- System.out.println("ContentType.values(SubType.DEFAULT) = " + ContentType.values(SubType.DEFAULT));
- init11();
- }
- private void init11() {
- IntFunction<String[]> intFunction = String[]::new;
- Function<Integer, String[]> intFunctionBoxed = String[]::new;
- Function<String[], String[]> cloner = String[]::clone;
- String[] s = {};
- init12();
- }
- private void init12() {
- Map<String, Integer> map = new HashMap<>();
- map.put("test", 5);
- Map<String, String> mapped = map.entrySet().stream()
- .collect(Collectors.toMap(Map.Entry::getKey, entry -> String.valueOf(entry.getValue())));
- mapped.forEach((k, v) -> System.out.println("key: " + k + " / value: " + v));
- init13();
- }
- private void init13() {
- List<String[]> phrases = Arrays.asList(new String[]{"a", "b", "c"}, new String[]{"a", "a", "b", "d"});
- List<Map.Entry<String, Long>> topEntries = getTopWords(2, phrases.stream().flatMap(Arrays::stream))
- .collect(Collectors.toList());
- int counter = 1;
- for (Map.Entry<String, Long> entry : topEntries) {
- System.out.println(counter + ": " + entry.getKey() + " - " + entry.getValue());
- counter++;
- }
- init14();
- }
- public static Stream<Map.Entry<String, Long>> getTopWords(final int topX, final Stream<String> words) {
- if (topX < 1) {
- throw new IllegalArgumentException("invalid value for topX: " + topX);
- }
- Objects.requireNonNull(words);
- Comparator<Map.Entry<String, Long>> comparator = Comparator.comparingLong(Map.Entry::getValue);
- return words.collect(Collectors.groupingBy(i -> i, Collectors.counting()))
- .entrySet().stream()
- .sorted(comparator.reversed())
- .limit(topX);
- }
- private void init14() {
- LinkedList<Integer> linkedList = new LinkedList<>();
- linkedList.add(5);
- linkedList.add(10);
- linkedList.add(15);
- LinkedList<String> resultList = transform(linkedList, i -> (i + 1) + "-" + i);
- // LinkedList<String> resultList = transform(linkedList, i -> (i + 1) + "-" + i, LinkedList::new);
- resultList.forEach(System.out::println);
- init15();
- }
- public static <E, R, C extends Collection<? extends R>> C transform(final Collection<E> collection, final Function<? super E, ? extends R> mapper) {
- try {
- Objects.requireNonNull(collection);
- Objects.requireNonNull(mapper);
- Class<? extends Collection> clazz = collection.getClass();
- @SuppressWarnings("unchecked") Collection<Object> returnCollection = clazz.newInstance();
- collection.stream().map(mapper).forEach(returnCollection::add);
- @SuppressWarnings("unchecked") C genericReturnCollection = (C)returnCollection;
- return genericReturnCollection;
- } catch (InstantiationException | IllegalAccessException ex) {
- throw new RuntimeException(ex);
- }
- }
- public static <E, R, C extends Collection<R>> C transform(final Collection<E> collection, final Function<? super E, ? extends R> mapper, final Supplier<C> collectionSupplier) {
- Objects.requireNonNull(collection);
- Objects.requireNonNull(mapper);
- Objects.requireNonNull(collectionSupplier);
- return collection.stream().map(mapper).collect(Collectors.toCollection(collectionSupplier));
- }
- private void init15() {
- Stream<Integer> stream = IntStream.iterate(0, i -> i + LocalTime.now().getSecond()).skip(1).limit(10).boxed();
- for (int i : iterable(stream)) {
- System.out.println("i = " + i);
- }
- init16();
- }
- private static <T> Iterable<T> iterable(final Stream<T> stream) {
- return stream::iterator;
- }
- private void init16() {
- String dashes = Stream.generate(() -> "-").limit(80).reduce("", (s1, s2) -> s1 + s2);
- System.out.println(dashes);
- init17();
- }
- private void init17() {
- String[] stringArray = new String[]{
- "a",
- "bc",
- "def",
- "ghij"
- };
- Arrays.sort(stringArray, new Comparator<String>() {
- @Override
- public int compare(String s1, String s2) {
- return s1.length() - s2.length();
- }
- });
- Arrays.stream(stringArray).forEach(System.out::println);
- Arrays.sort(stringArray, (s1, s2) -> s1.length() - s2.length());
- Arrays.stream(stringArray).forEach(System.out::println);
- Arrays.sort(stringArray, Comparator.comparingInt(String::length));
- Arrays.stream(stringArray).forEach(System.out::println);
- init18();
- }
- private void init18() {
- Arrays.stream(Operation.values())
- .forEach(op -> System.out.println("Performing operation " + op.getSymbol() + " on 2 and 4: " + op.applyAsDouble(2, 4)));
- init19();
- }
- private void init19() {
- OptionalDouble d1 = OptionalDouble.of(1.);
- OptionalDouble d2 = OptionalDouble.of(2.);
- OptionalDouble d3 = OptionalDouble.of(3.);
- OptionalDouble result = OptionalDoubleImproved.of(d1)
- .applyFunction((a, b) -> a + b, d2)
- .applyFunction((a, b) -> a * b, d3)
- .get();
- System.out.println("result = " + result);
- init20();
- }
- private void init20() {
- List<String> languages = Arrays.asList("c#", "java", "python", "scala");
- Pattern pattern = Pattern.compile("[a-z]{4}");
- languages.stream()
- // .filter(str -> pattern.matcher(str).matches())
- .filter(pattern.asPredicate())
- .forEach(System.out::println);
- init21();
- }
- private void init21() {
- Stream<Integer> stream1 = IntStream.rangeClosed(0, 100).boxed()
- .filter(i -> i % 2 != 0);
- Stream<Integer> stream2 = IntStream.rangeClosed(101, 200).boxed()
- .filter(i -> i % 3 != 0);
- Stream.concat(stream1, stream2)
- .forEach(System.out::println);
- init22();
- }
- private void init22() {
- BigDecimal t1 = new BigDecimal(134.23576185216913);
- BigDecimal one = new BigDecimal(1);
- BigDecimal speed = new BigDecimal(200000000).pow(2);
- BigDecimal lightsSpeed = new BigDecimal(299800000).pow(2);
- MathContext mc = new MathContext(2, RoundingMode.HALF_UP);
- System.out.println(t1.subtract((t1.multiply(SquareRoot.bigSqrt(one.subtract(speed.divide(lightsSpeed,mc)))))));
- init23();
- }
- private void init23() {
- GenericParticle electron = BasicGenericParticle.ELECTRON;
- GenericParticle hydrogen = BasicGenericParticle.HYDROGEN;
- GenericParticle water = new GenericParticleBuilder()
- .name("water").name("h2o2")
- // .component(/*components*/)
- .build();
- init24();
- }
- private void init24() {
- for (int y = 0; y < 5; y++) {
- for (int x = y; x < 10; x += 2) {
- System.out.println(x + y);
- }
- }
- init25();
- }
- private void init25() {
- doMyDoubleLoop(5, y -> y + 1, 10, x -> x + 2, (x, y) -> x + y, System.out::println);
- init26();
- }
- private void init26() {
- doMyInternalDoubleLoop((x, y) -> x + y, System.out::println);
- init27();
- }
- private void doMyDoubleLoop(
- final int yEnd, final IntUnaryOperator yIncrementOperator,
- final int xEnd, final IntUnaryOperator xIncrementOperator,
- final IntBinaryOperator combiner, final IntConsumer consumer
- ) {
- for (int y = 0; y < yEnd; y = yIncrementOperator.applyAsInt(y)) {
- for (int x = y; x < xEnd; x = xIncrementOperator.applyAsInt(x)) {
- consumer.accept(combiner.applyAsInt(x, y));
- }
- }
- }
- private void doMyInternalDoubleLoop(final IntBinaryOperator combiner, final IntConsumer consumer) {
- for (int y = 0; y < 5; y++) {
- for (int x = y; x < 10; x += 2) {
- consumer.accept(combiner.applyAsInt(x, y));
- }
- }
- }
- private IntStream doMyInternalDoubleLoopRenewed(final IntBinaryOperator combiner, final IntConsumer consumer) {
- //TODO is there a way to return it as an IntStream without consuming memory, thus making it lazy?
- for (int y = 0; y < 5; y++) {
- for (int x = y; x < 10; x += 2) {
- consumer.accept(combiner.applyAsInt(x, y));
- }
- }
- return null;
- }
- private void init27() {
- Map<Integer, Long> coinCount = new Random().ints(10000, 0, 2)
- .boxed()
- .collect(Collectors.groupingBy(i -> i, Collectors.counting()));
- coinCount.forEach((k, v) -> System.out.println("Key: " + k + " / Value: " + v));
- init28();
- }
- private void init28() {
- int[] ints = new int[10];
- int ints2[] = new int[10];
- init29();
- }
- private void init29() {
- // int x = 0;
- // int y = 0;
- // int w = 10;
- // int h = 10;
- // Picture picture = null;
- // IntStream.range(x, x + w)
- // .parallel()
- // .boxed()
- // .flatMap(xVal -> IntStream.range(y, y + h).parallel().mapToObj(yVal -> new IntTuple(xVal, yVal)))
- // .forEach(tuple -> averagePixel(picture, tuple));
- init30();
- }
- private void init30() {
- Consumer<MyEnum> myMethod = MyEnum::myMethod;
- init31();
- }
- private void init31() {
- // //little benchmark
- //
- // //setup byte arrays
- // List<byte[]> arrays = createByteArrays(1000);
- //
- // //warmup
- // arrays.forEach(this::byteArrayCheck12);
- // arrays.forEach(this::byteArrayCheck3);
- // arrays.forEach(this::byteArrayCheck4);
- // arrays.forEach(this::byteArrayCheck5);
- //
- // //benchmark
- // benchmark(arrays, this::byteArrayCheck12, "byteArrayCheck12");
- // benchmark(arrays, this::byteArrayCheck3, "byteArrayCheck3");
- // benchmark(arrays, this::byteArrayCheck4, "byteArrayCheck4");
- // benchmark(arrays, this::byteArrayCheck5, "byteArrayCheck5");
- init32();
- }
- private void init32() {
- byte a = 0;
- byte b = 0;
- byte c = -17;
- byte d = 55;
- byte e = -55;
- byte f = 17;
- long z = a | b | c | d | e | f;
- System.out.println("z = " + z);
- init33();
- }
- private void init33() {
- Float alpha = +0.0f;
- Float beta = -0.0f;
- boolean equal = alpha.equals(beta);
- System.out.println("Equal: " + equal);
- boolean equality = alpha.floatValue() == beta.floatValue();
- System.out.println("Equality: " + equality);
- init34();
- }
- private void init34() {
- byte a = 1;
- byte b = 3;
- byte c = 7;
- byte d = 11;
- int z = a + b + c + d;
- System.out.println("z = " + z);
- byte[] byteArray = new byte[] { a, b, c, d };
- ByteBuffer byteBuffer = ByteBuffer.wrap(byteArray);
- int[] intArray = new int[1];
- byteBuffer.asIntBuffer().get(intArray);
- System.out.println("intArray[0] = " + intArray[0]);
- init35();
- }
- private void init35() {
- int ៛ = 0;
- int ៛៛ = 0;
- int ௹ = 1;
- int ௹௹ = 1;
- int ៛៛៛ = ៛*௹+៛៛/௹௹;
- System.out.println("៛៛៛ = " + ៛៛៛);
- init36();
- }
- private void init36() {
- String str1 = "a";
- String str2 = "a@";
- String str3 = "a@@a";
- String str4 = "a#@a";
- List<Character> characters = Arrays.asList('@', '#', '$', '%');
- System.out.println("stringMatchesChars(str1, characters) = " + stringMatchesChars(str1, characters));
- System.out.println("stringMatchesChars(str2, characters) = " + stringMatchesChars(str2, characters));
- System.out.println("stringMatchesChars(str3, characters) = " + stringMatchesChars(str3, characters));
- System.out.println("stringMatchesChars(str4, characters) = " + stringMatchesChars(str4, characters));
- init37();
- }
- private void init37() {
- String[] array = {"a", "b", "c", "d", "e", "f"};
- for (int i = array.length; i--!=0; ) {
- System.out.println("array[i] = " + array[i]);
- }
- init38();
- }
- private void init38() {
- register(event -> System.out.println("Test"));
- init39();
- }
- private void init39() {
- String[] array = {"a", "b", "c"};
- Collections.shuffle(Arrays.asList(array));
- System.out.println("array = " + Arrays.toString(array));
- init40();
- }
- private void init40() {
- Random random = new Random();
- String randomString = IntStream.concat(
- random.ints(8, 'a', 'z'),
- random.ints(8, 'A', 'Z')
- )
- .collect(
- StringBuilder::new,
- (sb, i) -> sb.append((char)i),
- (sb1, sb2) -> sb1.append(sb2)
- ).toString();
- System.out.println("randomString = " + randomString);
- init41();
- }
- private void init41() {
- List<Integer> list = Arrays.asList(1, 3, 5, 7, 9, 11);
- Iterator<Integer> iterator = list.iterator();
- Spliterator<Integer> spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED);
- Stream<Integer> stream = StreamSupport.stream(spliterator, false);
- stream.forEach(System.out::println);
- init42();
- }
- private void init42() {
- }
- public void shuffleArray(final Object[] array) {
- Collections.shuffle(Arrays.asList(Objects.requireNonNull(array, "array")));
- }
- private void register(final EventListener eventListener) {
- System.out.println("Registered " + eventListener);
- }
- private static class Event { }
- @Retention(RetentionPolicy.RUNTIME)
- @Target(ElementType.METHOD)
- private static @interface Annotation { }
- private static interface EventListener {
- @Annotation
- void apply(final Event event);
- }
- private static class EventListenerImpl implements EventListener {
- @Override
- public void apply(final Event event) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
- }
- private boolean stringMatchesChars(final String str, final List<Character> characters) {
- return (str.chars()
- .filter(ch -> characters.contains((char)ch))
- .count() == 1);
- }
- private void benchmark(final List<byte[]> arrays, final Consumer<byte[]> method, final String name) {
- long start = System.nanoTime();
- arrays.forEach(method);
- long end = System.nanoTime();
- double nanosecondsPerIteration = (end - start) * 1d / arrays.size();
- System.out.println("Benchmark: " + name + " / iterations: " + arrays.size() + " / time per iteration: " + nanosecondsPerIteration + "ns");
- }
- private List<byte[]> createByteArrays(final int amount) {
- Random random = new Random();
- List<byte[]> resultList = new ArrayList<>();
- for (int i = 0; i < amount; i++) {
- byte[] byteArray = new byte[4096];
- byteArray[random.nextInt(4096)] = 1;
- resultList.add(byteArray);
- }
- return resultList;
- }
- private boolean byteArrayCheck12(final byte[] array) {
- long sum = 0L;
- for (byte b : array) {
- sum += b;
- }
- return (sum == 0);
- }
- private boolean byteArrayCheck3(final byte[] array) {
- for (byte b : array) {
- if (b != 0) {
- return false;
- }
- }
- return true;
- }
- private boolean byteArrayCheck4(final byte[] array) {
- return (IntStream.range(0, array.length).map(i -> array[i]).sum() != 0);
- }
- private boolean byteArrayCheck5(final byte[] array) {
- return IntStream.range(0, array.length).map(i -> array[i]).anyMatch(i -> i != 0);
- }
- private List<Pixel> getNeighbours(final Picture picture, final IntTuple intTuple) {
- List<Pixel> pixels = new ArrayList<>();
- for (int x = intTuple.x - 1; x <= intTuple.x + 1; x++) {
- for (int y = intTuple.y - 1; y <= intTuple.y + 1; y++) {
- pixels.add(picture.getPixel(x, y));
- }
- }
- return pixels;
- }
- private void averagePixel(final Picture picture, final IntTuple intTuple) {
- double red = 0d;
- double green = 0d;
- double blue = 0d;
- List<Pixel> neighbours = getNeighbours(picture, intTuple);
- for (Pixel pixel : neighbours) {
- red += pixel.getRed();
- green += pixel.getGreen();
- blue += pixel.getBlue();
- }
- Pixel pixel = picture.getPixel(intTuple.x, intTuple.y);
- pixel.setRed((int)(red / neighbours.size()));
- pixel.setGreen((int)(green / neighbours.size()));
- pixel.setBlue((int)(blue / neighbours.size()));
- }
- private class Pixel {
- public int getRed() {
- return 0;
- }
- public int getGreen() {
- return 0;
- }
- public int getBlue() {
- return 0;
- }
- public void setRed(int red) { }
- public void setGreen(int red) { }
- public void setBlue(int red) { }
- }
- private class Picture {
- public Pixel getPixel(int x, int y) {
- return null;
- }
- }
- private class IntTuple {
- public final int x;
- public final int y;
- public IntTuple(final int x, final int y) {
- this.x = x;
- this.y = y;
- }
- }
- }
- @FunctionalInterface
- interface Test {
- void test();
- @Override
- boolean equals(Object other);
- }
- class BankAccount implements Serializable {
- private static final long serialVersionUID = 684656564655528L;
- private final String clientName;
- private BigDecimal balance;
- public BankAccount(final String clientName, final BigDecimal balance) {
- this.clientName = Objects.requireNonNull(clientName);
- this.balance = Objects.requireNonNull(balance);
- }
- private Object writeReplace() {
- return new SerializationProxy(this);
- }
- private void readObject(final ObjectInputStream stream) throws InvalidObjectException {
- throw new InvalidObjectException("Proxy required");
- }
- private static class SerializationProxy implements Serializable {
- private static final long serialVersionUID = 5684551235489465L;
- private final String clientName;
- private final BigDecimal balance;
- private SerializationProxy(final BankAccount bankAccount) {
- this.clientName = bankAccount.clientName;
- this.balance = bankAccount.balance;
- }
- private Object readResolve() {
- return new BankAccount(clientName, balance);
- }
- }
- }
- enum Component {
- ELECTRON, PROTON, NEUTRON;
- }
- interface GenericParticle {
- List<String> getNames();
- List<Component> getComponents();
- }
- enum BasicGenericParticle implements GenericParticle {
- ELECTRON(
- Arrays.asList("electron", "e"),
- Arrays.asList(Component.ELECTRON)
- ),
- HYDROGEN(
- Arrays.asList("hydrogen", "h"),
- Arrays.asList(Component.ELECTRON, Component.PROTON)
- )
- ;
- private final List<String> names;
- private final List<Component> components;
- private BasicGenericParticle(final List<String> names, final List<Component> components) {
- this.names = names;
- this.components = components;
- }
- @Override
- public List<String> getNames() {
- return new ArrayList<>(names);
- }
- @Override
- public List<Component> getComponents() {
- return new ArrayList<>(components);
- }
- }
- class GenericParticleBuilder {
- private List<String> names = new ArrayList<>();
- private List<Component> components = new ArrayList<>();
- public GenericParticleBuilder name(final String name) {
- names.add(name);
- return this;
- }
- public GenericParticleBuilder component(final Component component) {
- components.add(component);
- return this;
- }
- public GenericParticle build() {
- return new GenericParticleImpl(names, components);
- }
- private static class GenericParticleImpl implements GenericParticle {
- private List<String> names = new ArrayList<>();
- private List<Component> components = new ArrayList<>();
- public GenericParticleImpl(final List<String> names, final List<Component> components) {
- this.names = names;
- this.components = components;
- }
- @Override
- public List<String> getNames() {
- return new ArrayList<>(names);
- }
- @Override
- public List<Component> getComponents() {
- return new ArrayList<>(components);
- }
- }
- }
- class SquareRoot {
- private static final BigDecimal SQRT_DIG = new BigDecimal(150);
- private static final BigDecimal SQRT_PRE = new BigDecimal(10).pow(SQRT_DIG.intValue());
- /**
- * Private utility method used to compute the square root of a BigDecimal.
- *
- * @author Luciano Culacciatti
- * @url http://www.codeproject.com/Tips/257031/Implementing-SqrtRoot-in-BigDecimal
- */
- private static BigDecimal sqrtNewtonRaphson (BigDecimal c, BigDecimal xn, BigDecimal precision){
- BigDecimal fx = xn.pow(2).add(c.negate());
- BigDecimal fpx = xn.multiply(new BigDecimal(2));
- BigDecimal xn1 = fx.divide(fpx,2*SQRT_DIG.intValue(),RoundingMode.HALF_DOWN);
- xn1 = xn.add(xn1.negate());
- BigDecimal currentSquare = xn1.pow(2);
- BigDecimal currentPrecision = currentSquare.subtract(c);
- currentPrecision = currentPrecision.abs();
- if (currentPrecision.compareTo(precision) <= -1){
- return xn1;
- }
- return sqrtNewtonRaphson(c, xn1, precision);
- }
- /**
- * Uses Newton Raphson to compute the square root of a BigDecimal.
- *
- * @author Luciano Culacciatti
- * @url http://www.codeproject.com/Tips/257031/Implementing-SqrtRoot-in-BigDecimal
- */
- public static BigDecimal bigSqrt(BigDecimal c){
- return sqrtNewtonRaphson(c,new BigDecimal(1),new BigDecimal(1).divide(SQRT_PRE));
- }
- }
- class OptionalDoubleImproved {
- private static final OptionalDoubleImproved EMPTY = OptionalDoubleImproved.of(OptionalDouble.empty());
- private final OptionalDouble optionalDouble;
- private OptionalDoubleImproved(final OptionalDouble optionalDouble) {
- this.optionalDouble = Objects.requireNonNull(optionalDouble);
- }
- public static OptionalDoubleImproved of(final OptionalDouble optionalDouble) {
- return new OptionalDoubleImproved(optionalDouble);
- }
- public OptionalDoubleImproved applyFunction(final DoubleBinaryOperator operator, final OptionalDouble operand) {
- Objects.requireNonNull(operator);
- Objects.requireNonNull(operand);
- if (!optionalDouble.isPresent() || !operand.isPresent()) {
- return EMPTY;
- }
- return OptionalDoubleImproved.of(OptionalDouble.of(operator.applyAsDouble(optionalDouble.getAsDouble(), operand.getAsDouble())));
- }
- public OptionalDouble get() {
- return optionalDouble;
- }
- @Override
- public int hashCode() {
- int hash = 7;
- hash = 53 * hash + Objects.hashCode(this.optionalDouble);
- return hash;
- }
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final OptionalDoubleImproved other = (OptionalDoubleImproved) obj;
- if (!Objects.equals(this.optionalDouble, other.optionalDouble)) {
- return false;
- }
- return true;
- }
- @Override
- public String toString() {
- return "OptionalDoubleImproved[" + optionalDouble + "]";
- }
- }
- //enum Operation implements DoubleBinaryOperator {
- // PLUS("+") {
- // @Override
- // public double applyAsDouble(final double left, final double right) {
- // return left + right;
- // }
- // },
- // MINUS("-") {
- // @Override
- // public double applyAsDouble(final double left, final double right) {
- // return left - right;
- // }
- // },
- // MULTIPLY("*") {
- // @Override
- // public double applyAsDouble(final double left, final double right) {
- // return left * right;
- // }
- // },
- // DIVIDE("/") {
- // @Override
- // public double applyAsDouble(final double left, final double right) {
- // return left / right;
- // }
- // };
- //
- // private final String symbol;
- //
- // private Operation(final String symbol) {
- // this.symbol = symbol;
- // }
- //
- // public String getSymbol() {
- // return symbol;
- // }
- //}
- enum Operation implements DoubleBinaryOperator {
- PLUS ("+", (l, r) -> l + r),
- MINUS ("-", (l, r) -> l - r),
- MULTIPLY("*", (l, r) -> l * r),
- DIVIDE ("/", (l, r) -> l / r);
- private final String symbol;
- private final DoubleBinaryOperator binaryOperator;
- private Operation(final String symbol, final DoubleBinaryOperator binaryOperator) {
- this.symbol = symbol;
- this.binaryOperator = binaryOperator;
- }
- public String getSymbol() {
- return symbol;
- }
- @Override
- public double applyAsDouble(final double left, final double right) {
- return binaryOperator.applyAsDouble(left, right);
- }
- }
- enum ContentType {
- TITLE("$$title$$",SubType.MAIL),
- BODY("$$body$$",SubType.MAIL),
- MESSAGE("$$message$$",SubType.MAIL),
- EVENTS("$$events$$",SubType.DEFAULT);
- private static final EnumMap<SubType, Set<ContentType>> SETS_BY_SUBTYPE;
- static {
- SETS_BY_SUBTYPE = Arrays.stream(values())
- .collect(Collectors.groupingBy(
- ContentType::getSubType,
- () -> new EnumMap<>(SubType.class),
- Collectors.toSet()
- ));
- }
- private final String replaceWord;
- private final SubType subType;
- private ContentType(final String replaceWord, final SubType subType) {
- this.replaceWord = replaceWord;
- this.subType = subType;
- }
- public String getReplaceWord() {
- return replaceWord;
- }
- private SubType getSubType() {
- return subType;
- }
- public static Set<ContentType> values(final SubType subType) {
- return SETS_BY_SUBTYPE.get(subType);
- }
- }
- enum SubType {
- MAIL,
- DEFAULT;
- }
- class Pet {
- }
- class Pair<T, U> {
- private final T t;
- private final U u;
- public Pair(final T t, final U u) {
- this.t = t;
- this.u = u;
- }
- @Override
- public String toString() {
- return "(" + t + ", " + u + ")";
- }
- }
- class CustomOptionalOld<T> {
- private final Optional<T> optional;
- private CustomOptionalOld() {
- this.optional = Optional.empty();
- }
- private CustomOptionalOld(final T value) {
- this.optional = Optional.of(value);
- }
- private CustomOptionalOld(final Optional<T> optional) {
- this.optional = optional;
- }
- public Optional<T> getOptional() {
- return optional;
- }
- public static <T> CustomOptionalOld<T> empty() {
- return new CustomOptionalOld<>();
- }
- public static <T> CustomOptionalOld<T> of(final T value) {
- return new CustomOptionalOld<>(value);
- }
- public static <T> CustomOptionalOld<T> ofNullable(final T value) {
- return (value == null) ? empty() : of(value);
- }
- public T get() {
- return optional.get();
- }
- public boolean isPresent() {
- return optional.isPresent();
- }
- public void ifPresent(final Consumer<? super T> consumer) {
- optional.ifPresent(consumer);
- }
- public CustomOptionalOld<T> filter(final Predicate<? super T> predicate) {
- return new CustomOptionalOld<>(optional.filter(predicate));
- }
- public <U> CustomOptionalOld<U> map(final Function<? super T, ? extends U> mapper) {
- return new CustomOptionalOld<>(optional.map(mapper));
- }
- public <U> CustomOptionalOld<U> flatMap(final Function<? super T, ? extends CustomOptionalOld<U>> mapper) {
- return new CustomOptionalOld<>(optional.flatMap(mapper.andThen(CustomOptionalOld::getOptional)));
- // return new CustomOptionalOld<>(optional.flatMap(mapper.andThen(cu -> cu.getOptional())));
- }
- public T orElse(final T other) {
- return optional.orElse(other);
- }
- public T orElseGet(final Supplier<? extends T> other) {
- return optional.orElseGet(other);
- }
- public <X extends Throwable> T orElseThrow(final Supplier<? extends X> exceptionSuppier) throws X {
- return optional.orElseThrow(exceptionSuppier);
- }
- public Stream<T> flatStream() {
- if (!optional.isPresent()) {
- return Stream.empty();
- }
- return Stream.of(get());
- }
- public T getTOrNull() {
- if (!optional.isPresent()) {
- return null;
- }
- return get();
- }
- @Override
- public boolean equals(final Object obj) {
- return optional.equals(obj);
- }
- @Override
- public int hashCode() {
- return optional.hashCode();
- }
- @Override
- public String toString() {
- return optional.toString();
- }
- }
- class AnimalAI {
- }
- class Lion extends AnimalAI {
- }
- class Zebra extends AnimalAI {
- }
- class YourClass {
- static {
- System.out.println("I got loaded!");
- }
- }
- class CustomList<T> extends ArrayList<T> {
- public void printRandom() {
- System.out.println("random");
- }
- }
- class Player {
- public String player_name;
- public int number;
- public int getNumber() {
- return number;
- }
- }
- class User {
- @Override
- public String toString() {
- return id + " - " + username;
- }
- int id;
- String username;
- public User() {
- }
- public User(int id, String username) {
- this.id = id;
- this.username = username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getUsername() {
- return username;
- }
- public int getId() {
- return id;
- }
- }
- @FunctionalInterface
- interface CustomPredicate<T> extends Function<T, Boolean> {
- boolean test(T value);
- @Override
- default Boolean apply(T t) {
- return test(t);
- }
- }
- class Invoice {
- String company;
- String invoice_number;
- BigDecimal unit_price;
- BigDecimal quantity;
- public Invoice() {
- unit_price = BigDecimal.ZERO;
- quantity = BigDecimal.ZERO;
- }
- public Invoice(String company, String invoice_number, BigDecimal unit_price, BigDecimal quantity) {
- this.company = company;
- this.invoice_number = invoice_number;
- this.unit_price = unit_price;
- this.quantity = quantity;
- }
- public BigDecimal total() {
- return unit_price.multiply(quantity);
- }
- public void setUnit_price(BigDecimal unit_price) {
- this.unit_price = unit_price;
- }
- public void setQuantity(BigDecimal quantity) {
- this.quantity = quantity;
- }
- public void setInvoice_number(String invoice_number) {
- this.invoice_number = invoice_number;
- }
- public void setCompany(String company) {
- this.company = company;
- }
- public BigDecimal getUnit_price() {
- return unit_price;
- }
- public BigDecimal getQuantity() {
- return quantity;
- }
- public String getInvoice_number() {
- return invoice_number;
- }
- public String getCompany() {
- return company;
- }
- }
- class Person {
- private String firstName;
- private String lastName;
- public Person(final String firstName, final String lastName) {
- this.firstName = firstName;
- this.lastName = lastName;
- }
- public String getFirstName() {
- return firstName;
- }
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- public String getLastName() {
- return lastName;
- }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- @Override
- public String toString() {
- return firstName + " " + lastName;
- }
- }
- class Car implements Drivable {
- @Override
- public void drive() {
- System.out.println("Starting to drive");
- }
- @Override
- public int getWheelCount() {
- return 0;
- }
- }
- interface Drivable {
- public void drive();
- public int getWheelCount();
- }
- class UnrelatedClass implements UnrelatedInterfaceDefault {
- @Override
- public void unrelate2() {
- System.out.println("Unrelated");
- }
- }
- interface UnrelatedInterfaceDefault extends UnrelatedInterfaceOne, UnrelatedInterfaceTwo {
- default public void unrelate() {
- // UnrelatedInterfaceOne.super.unrelate2();
- // UnrelatedInterfaceTwo.super.unrelate2();
- // ((UnrelatedInterfaceOne)this).unrelate2();
- // ((UnrelatedInterfaceTwo)this).unrelate2();
- unrelate2();
- }
- }
- interface UnrelatedInterfaceOne {
- public void unrelate2();
- }
- interface UnrelatedInterfaceTwo {
- public void unrelate2();
- }
- class SuperClass {
- public SuperClass(){
- System.out.println("Super Constructor");
- }
- public SuperClass(int i){
- this();
- System.out.println("Parameterized Super Constructor");
- }
- }
- class SubClass extends SuperClass {
- public SubClass(){
- System.out.println("Sub Constructor");
- }
- public SubClass(int i){
- super(i); /* Need to call **this()** here .. Is this possible? */
- System.out.println("Parameterized Sub Constructor");
- }
- }
- class Employee {
- private int empSalary;
- private String empName;
- public int getEmpSalary() {
- return empSalary;
- }
- public String getEmpName() {
- return empName;
- }
- }
- class MoneyFormatCell extends TableCell<Factura, BigDecimal> {
- public MoneyFormatCell() {
- }
- }
- class Factura {
- }
- class MutableNonSafeInt {
- private int i = 0;
- public void increase() {
- i++;
- }
- public int get() {
- return i;
- }
- }
- interface Notifiable {
- }
- class NotifiableImpl1 implements Notifiable {
- }
- class NotifiableImpl2 implements Notifiable {
- }
- class NotifiableImpl3 implements Notifiable {
- }
- interface Number {
- public int intValue();
- public long longValue();
- public float floatValue();
- public double doubleValue();
- default public byte byteValue() {
- return (byte)intValue();
- }
- default public short shortValue() {
- return (short)intValue();
- }
- }
- //
- //class LinkedList {
- // private Node head = new Node();
- // private Node tail = new Node();
- //
- // {
- // connect(head, tail);
- // }
- //
- // public LinkedList() {
- // /* Constructor one */
- // }
- //
- // public LinkedList(final Object something) {
- // /* Constructor two */
- // }
- //
- // private void connect(Node head, Node tail) {
- // /* Connect the nodes */
- // }
- //
- // private class Node { }
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement