Home Uncategorized get modules

get modules

1
 String bankCode = "30006" ;
      String branchCode = "00001" ;
      Random r = new Random();
      int Low = 10;
      int High = 1000000;
      int AccountNumberInt = r.nextInt(High-Low) + Low;
      String AccountNumberStr = String.valueOf(AccountNumberInt);
      String AccountNumber = StringUtils.repeat("0", 11 - AccountNumberStr.length()) + AccountNumberStr;
      long a100000000000 =  (long) 100000000000.0;
      Long nationalCheckDigitInt = 97 - (((Long.valueOf(bankCode) % 97 * 100000 + Integer.valueOf(branchCode)) % 97 * a100000000000 + Integer.valueOf(AccountNumber)) % 97) * 100 % 97;
       String nationalCheckDigit = String.valueOf(nationalCheckDigitInt) ;
       Iban iban = new Iban.Builder().countryCode(CountryCode.FR).bankCode(bankCode).branchCode(branchCode).accountNumber(AccountNumber).nationalCheckDigit(nationalCheckDigit).buildRandom();

1 COMMENT

  1. package com.baeldung.chroniclemap;

    import static org.hamcrest.CoreMatchers.equalTo;
    import static org.hamcrest.CoreMatchers.is;
    import static org.junit.Assert.assertThat;

    import java.io.File;
    import java.util.HashSet;
    import java.util.Set;
    import java.util.stream.Collectors;
    import java.util.stream.IntStream;

    import org.junit.AfterClass;
    import org.junit.BeforeClass;
    import org.junit.Test;

    import net.openhft.chronicle.core.values.LongValue;
    import net.openhft.chronicle.map.ChronicleMap;
    import net.openhft.chronicle.map.ExternalMapQueryContext;
    import net.openhft.chronicle.map.MapEntry;
    import net.openhft.chronicle.values.Values;

    public class ChronicleMapUnitTest {

    static ChronicleMap persistedCountryMap = null;

    static ChronicleMap inMemoryCountryMap = null;

    static ChronicleMap<Integer, Set> multiMap = null;

    @SuppressWarnings({ “unchecked”, “rawtypes” })
    @BeforeClass
    public static void init() {
    try {
    inMemoryCountryMap = ChronicleMap.of(LongValue.class, CharSequence.class)
    .name(“country-map”)
    .entries(50)
    .averageValue(“America”)
    .create();

    persistedCountryMap = ChronicleMap.of(LongValue.class, CharSequence.class)
    .name(“country-map”)
    .entries(50)
    .averageValue(“America”)
    .createPersistedTo(new File(System.getProperty(“user.home”) + “/country-details.dat”));

    Set averageValue = IntStream.of(1, 2)
    .boxed()
    .collect(Collectors.toSet());
    multiMap = ChronicleMap.of(Integer.class, (Class<Set>) (Class) Set.class)
    .name(“multi-map”)
    .entries(50)
    .averageValue(averageValue)
    .create();

    LongValue qatarKey = Values.newHeapInstance(LongValue.class);
    qatarKey.setValue(1);
    inMemoryCountryMap.put(qatarKey, “Qatar”);

    LongValue key = Values.newHeapInstance(LongValue.class);
    key.setValue(1);
    persistedCountryMap.put(key, “Romania”);
    key.setValue(2);
    persistedCountryMap.put(key, “India”);

    Set set1 = new HashSet();
    set1.add(1);
    set1.add(2);
    multiMap.put(1, set1);

    Set set2 = new HashSet();
    set2.add(3);
    multiMap.put(2, set2);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    @Test
    public void givenGetQuery_whenCalled_shouldReturnResult() {
    LongValue key = Values.newHeapInstance(LongValue.class);
    key.setValue(1);
    CharSequence country = inMemoryCountryMap.get(key);
    assertThat(country.toString(), is(equalTo(“Qatar”)));
    }

    @Test
    public void givenGetUsingQuery_whenCalled_shouldReturnResult() {
    LongValue key = Values.newHeapInstance(LongValue.class);
    StringBuilder country = new StringBuilder();
    key.setValue(1);
    persistedCountryMap.getUsing(key, country);
    assertThat(country.toString(), is(equalTo(“Romania”)));
    key.setValue(2);
    persistedCountryMap.getUsing(key, country);
    assertThat(country.toString(), is(equalTo(“India”)));
    }

    @Test
    public void givenMultipleKeyQuery_whenProcessed_shouldChangeTheValue() {
    try (ExternalMapQueryContext<Integer, Set, ?> fistContext = multiMap.queryContext(1)) {
    try (ExternalMapQueryContext<Integer, Set, ?> secondContext = multiMap.queryContext(2)) {
    fistContext.updateLock()
    .lock();
    secondContext.updateLock()
    .lock();
    MapEntry<Integer, Set> firstEntry = fistContext.entry();
    Set firstSet = firstEntry.value()
    .get();
    firstSet.remove(2);
    MapEntry<Integer, Set> secondEntry = secondContext.entry();
    Set secondSet = secondEntry.value()
    .get();
    secondSet.add(4);
    firstEntry.doReplaceValue(fistContext.wrapValueAsData(firstSet));
    secondEntry.doReplaceValue(secondContext.wrapValueAsData(secondSet));
    }
    } finally {
    assertThat(multiMap.get(1)
    .size(), is(equalTo(1)));
    assertThat(multiMap.get(2)
    .size(), is(equalTo(2)));
    }
    }

    @AfterClass
    public static void finish() {
    persistedCountryMap.close();
    inMemoryCountryMap.close();
    multiMap.close();
    }
    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version