target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void hasCorrectNumberField() { Field field = subject.getFields().get(4); assertEquals("GPA", field.getTitle()); assertEquals("3.7", field.getValue()); }
|
public List<Field> getFields() { return mFields; }
|
Metadata { public List<Field> getFields() { return mFields; } }
|
Metadata { public List<Field> getFields() { return mFields; } Metadata(List<String> displayOrder, Map<String, JsonObject> groups, Map<String, GroupDef> groupDefinitions, List<Field> fields); }
|
Metadata { public List<Field> getFields() { return mFields; } Metadata(List<String> displayOrder, Map<String, JsonObject> groups, Map<String, GroupDef> groupDefinitions, List<Field> fields); List<String> getDisplayOrder(); Map<String, JsonObject> getGroups(); Map<String, GroupDef> getGroupDefinitions(); List<Field> getFields(); }
|
Metadata { public List<Field> getFields() { return mFields; } Metadata(List<String> displayOrder, Map<String, JsonObject> groups, Map<String, GroupDef> groupDefinitions, List<Field> fields); List<String> getDisplayOrder(); Map<String, JsonObject> getGroups(); Map<String, GroupDef> getGroupDefinitions(); List<Field> getFields(); }
|
@Test public void hasCorrectBooleanField() { Field field = subject.getFields().get(6); assertEquals("is this a boolean?", field.getTitle()); assertEquals("True", field.getValue()); }
|
public List<Field> getFields() { return mFields; }
|
Metadata { public List<Field> getFields() { return mFields; } }
|
Metadata { public List<Field> getFields() { return mFields; } Metadata(List<String> displayOrder, Map<String, JsonObject> groups, Map<String, GroupDef> groupDefinitions, List<Field> fields); }
|
Metadata { public List<Field> getFields() { return mFields; } Metadata(List<String> displayOrder, Map<String, JsonObject> groups, Map<String, GroupDef> groupDefinitions, List<Field> fields); List<String> getDisplayOrder(); Map<String, JsonObject> getGroups(); Map<String, GroupDef> getGroupDefinitions(); List<Field> getFields(); }
|
Metadata { public List<Field> getFields() { return mFields; } Metadata(List<String> displayOrder, Map<String, JsonObject> groups, Map<String, GroupDef> groupDefinitions, List<Field> fields); List<String> getDisplayOrder(); Map<String, JsonObject> getGroups(); Map<String, GroupDef> getGroupDefinitions(); List<Field> getFields(); }
|
@Test public void testGenerateMnemonic() throws Exception { byte[] seedData = new byte[32]; String expectedMnemonic = ABANDON_ABANDON_ART; List<String> seedPhrase = BitcoinUtils.generateMnemonic(seedData); assertFalse(ListUtils.isEmpty(seedPhrase)); String mnemonic = StringUtils.join(" ", seedPhrase); assertFalse("Mnemonic phrase should not be empty", mnemonic.isEmpty()); assertEquals("0-seed should generate simple mnemonic phrase", expectedMnemonic, mnemonic); }
|
public static List<String> generateMnemonic(byte[] seedData) { if (MnemonicCode.INSTANCE == null) { return null; } try { return MnemonicCode.INSTANCE.toMnemonic(seedData); } catch (MnemonicException.MnemonicLengthException e) { Timber.e(e, "Unable to create mnemonic from word list"); } return null; }
|
BitcoinUtils { public static List<String> generateMnemonic(byte[] seedData) { if (MnemonicCode.INSTANCE == null) { return null; } try { return MnemonicCode.INSTANCE.toMnemonic(seedData); } catch (MnemonicException.MnemonicLengthException e) { Timber.e(e, "Unable to create mnemonic from word list"); } return null; } }
|
BitcoinUtils { public static List<String> generateMnemonic(byte[] seedData) { if (MnemonicCode.INSTANCE == null) { return null; } try { return MnemonicCode.INSTANCE.toMnemonic(seedData); } catch (MnemonicException.MnemonicLengthException e) { Timber.e(e, "Unable to create mnemonic from word list"); } return null; } }
|
BitcoinUtils { public static List<String> generateMnemonic(byte[] seedData) { if (MnemonicCode.INSTANCE == null) { return null; } try { return MnemonicCode.INSTANCE.toMnemonic(seedData); } catch (MnemonicException.MnemonicLengthException e) { Timber.e(e, "Unable to create mnemonic from word list"); } return null; } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
BitcoinUtils { public static List<String> generateMnemonic(byte[] seedData) { if (MnemonicCode.INSTANCE == null) { return null; } try { return MnemonicCode.INSTANCE.toMnemonic(seedData); } catch (MnemonicException.MnemonicLengthException e) { Timber.e(e, "Unable to create mnemonic from word list"); } return null; } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
@Test public void createWalletFromSeedPhrase() { String seedPhrase = ABANDON_ABANDON_ART; NetworkParameters params = MainNetParams.get(); Wallet wallet = BitcoinUtils.createWallet(params, seedPhrase); Address firstAddress = wallet.freshReceiveAddress(); Address secondAddress = wallet.freshReceiveAddress(); assertEquals("1KBdbBJRVYffWHWWZ1moECfdVBSEnDpLHi", firstAddress.toBase58()); assertEquals("1EiJMaaahrhpbhgaNzMeUe1ZoiXdbBhWhR", secondAddress.toBase58()); }
|
public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
@Test public void createWalletFromEntropy() { byte[] entropy = new byte[32]; NetworkParameters params = MainNetParams.get(); Wallet wallet = BitcoinUtils.createWallet(params, entropy); Address firstAddress = wallet.freshReceiveAddress(); Address secondAddress = wallet.freshReceiveAddress(); assertEquals("1KBdbBJRVYffWHWWZ1moECfdVBSEnDpLHi", firstAddress.toBase58()); assertEquals("1EiJMaaahrhpbhgaNzMeUe1ZoiXdbBhWhR", secondAddress.toBase58()); }
|
public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
@Test public void keychainSeedMatches() { String bip39seed = "408b285c123836004f4b8842c89324c1f01382450c0d439af345ba7fc49acf705489c6fc77dbd4e3dc1dd8cc6bc9f043db8ada1e243c4a0eafb290d399480840"; byte[] entropy = new byte[32]; NetworkParameters params = MainNetParams.get(); Wallet wallet = BitcoinUtils.createWallet(params, entropy); DeterministicSeed keyChainSeed = wallet.getKeyChainSeed(); byte[] seedBytes = keyChainSeed.getSeedBytes(); String encodedSeedBytes = Utils.HEX.encode(seedBytes); assertEquals(bip39seed, encodedSeedBytes); }
|
public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
@Test public void detectsValidPassphrases() { String seedPhrase = ABANDON_ABANDON_ART; assertTrue("This should be a valid phrase", BitcoinUtils.isValidPassphrase(seedPhrase)); }
|
public static boolean isValidPassphrase(String passphrase) { try { byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(passphrase.split(" "))); return entropy.length > 0; } catch (MnemonicException e) { Timber.e(e, "Invalid passphrase"); return false; } }
|
BitcoinUtils { public static boolean isValidPassphrase(String passphrase) { try { byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(passphrase.split(" "))); return entropy.length > 0; } catch (MnemonicException e) { Timber.e(e, "Invalid passphrase"); return false; } } }
|
BitcoinUtils { public static boolean isValidPassphrase(String passphrase) { try { byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(passphrase.split(" "))); return entropy.length > 0; } catch (MnemonicException e) { Timber.e(e, "Invalid passphrase"); return false; } } }
|
BitcoinUtils { public static boolean isValidPassphrase(String passphrase) { try { byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(passphrase.split(" "))); return entropy.length > 0; } catch (MnemonicException e) { Timber.e(e, "Invalid passphrase"); return false; } } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
BitcoinUtils { public static boolean isValidPassphrase(String passphrase) { try { byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(passphrase.split(" "))); return entropy.length > 0; } catch (MnemonicException e) { Timber.e(e, "Invalid passphrase"); return false; } } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
@Test public void nullLaunchUrlLaunchesOnboarding() { LaunchData launchData = SplashUrlDecoder.getLaunchType(null); assertEquals(ONBOARDING, launchData.getLaunchType()); }
|
public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
@Test public void detectsInvalidPassphrases() { String seedPhrase = "This phrase is too short and not random enough"; assertFalse("This should be an invalid phrase", BitcoinUtils.isValidPassphrase(seedPhrase)); }
|
public static boolean isValidPassphrase(String passphrase) { try { byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(passphrase.split(" "))); return entropy.length > 0; } catch (MnemonicException e) { Timber.e(e, "Invalid passphrase"); return false; } }
|
BitcoinUtils { public static boolean isValidPassphrase(String passphrase) { try { byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(passphrase.split(" "))); return entropy.length > 0; } catch (MnemonicException e) { Timber.e(e, "Invalid passphrase"); return false; } } }
|
BitcoinUtils { public static boolean isValidPassphrase(String passphrase) { try { byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(passphrase.split(" "))); return entropy.length > 0; } catch (MnemonicException e) { Timber.e(e, "Invalid passphrase"); return false; } } }
|
BitcoinUtils { public static boolean isValidPassphrase(String passphrase) { try { byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(passphrase.split(" "))); return entropy.length > 0; } catch (MnemonicException e) { Timber.e(e, "Invalid passphrase"); return false; } } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
BitcoinUtils { public static boolean isValidPassphrase(String passphrase) { try { byte[] entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(passphrase.split(" "))); return entropy.length > 0; } catch (MnemonicException e) { Timber.e(e, "Invalid passphrase"); return false; } } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
@Test public void pubKeyOwnershipConfirmed() { String pubKeyString = "03f5b5836e454ac540c912371d44b4bed1123be954644876a72571dc679f8e89d0"; byte[] pubKey = Utils.HEX.decode(pubKeyString); String seedPhrase = ABANDON_ABANDON_ART; NetworkParameters params = MainNetParams.get(); Wallet wallet = BitcoinUtils.createWallet(params, seedPhrase); assertTrue("Should be the owner of this pub key", wallet.isPubKeyMine(pubKey)); }
|
public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
@Test public void pubKeyNonOwnershipDetected() { String pubKeyString = "444444444444444444444444444444444444444444444444444444444444444444"; byte[] pubKey = Utils.HEX.decode(pubKeyString); String seedPhrase = ABANDON_ABANDON_ART; NetworkParameters params = MainNetParams.get(); Wallet wallet = BitcoinUtils.createWallet(params, seedPhrase); assertFalse("Should not be the owner of this pub key", wallet.isPubKeyMine(pubKey)); }
|
public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
@Test public void previousReceiveAddressesOwnershipVerified() { String seedPhrase = ABANDON_ABANDON_ART; NetworkParameters params = MainNetParams.get(); Wallet wallet = BitcoinUtils.createWallet(params, seedPhrase); Address address1 = wallet.freshReceiveAddress(); Address address2 = wallet.freshReceiveAddress(); Address address3 = wallet.freshReceiveAddress(); Address address = Address.fromBase58(params, "1H13uL5vSVvgPcJm16WjA6TPqGmouQaKtn"); assertFalse("Should not contain the non-issued address", wallet.getIssuedReceiveAddresses().contains(address)); Address address4 = wallet.freshReceiveAddress(); assertTrue("Should contain the issued address", wallet.getIssuedReceiveAddresses().contains(address)); }
|
public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
@Test public void savedWalletResumesFreshReceiveAddresses() throws IOException, UnreadableWalletException { String seedPhrase = ABANDON_ABANDON_ART; NetworkParameters params = MainNetParams.get(); Wallet wallet = BitcoinUtils.createWallet(params, seedPhrase); File tempFile = File.createTempFile("temp", "wallet"); Address address1 = wallet.freshReceiveAddress(); Address address2 = wallet.freshReceiveAddress(); wallet.saveToFile(tempFile); Wallet walletFromFile = Wallet.loadFromFile(tempFile); Address address3 = walletFromFile.freshReceiveAddress(); Address address4 = walletFromFile.freshReceiveAddress(); assertEquals("1KBdbBJRVYffWHWWZ1moECfdVBSEnDpLHi", address1.toBase58()); assertEquals("1EiJMaaahrhpbhgaNzMeUe1ZoiXdbBhWhR", address2.toBase58()); assertEquals("1AxcesYVBs6ddjcuXDLLBMkgYwjkh8mora", address3.toBase58()); assertEquals("1H13uL5vSVvgPcJm16WjA6TPqGmouQaKtn", address4.toBase58()); }
|
public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
BitcoinUtils { public static Wallet createWallet(NetworkParameters params, String seedPhrase) { byte[] entropy; try { entropy = MnemonicCode.INSTANCE.toEntropy(Arrays.asList(seedPhrase.split(" "))); } catch (MnemonicException e) { Timber.e(e, "Could not convert passphrase to entropy"); return null; } return createWallet(params, entropy); } static void init(Context context); static List<String> generateMnemonic(byte[] seedData); static Wallet createWallet(NetworkParameters params, String seedPhrase); @NonNull static Wallet createWallet(NetworkParameters params, byte[] entropy); static Wallet loadWallet(InputStream walletStream, NetworkParameters networkParameters); static boolean updateRequired(Wallet wallet); static Wallet updateWallet(Wallet wallet); static boolean isValidPassphrase(String passphrase); }
|
@Test public void issuerUrlLaunchesIssuerFlow() { LaunchData launchData = SplashUrlDecoder.getLaunchType(ADD_ISSUER_URL); assertEquals(ADD_ISSUER, launchData.getLaunchType()); assertEquals("https: assertEquals("a*bcd", launchData.getNonce()); }
|
public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
@Test public void shortIssuerUrlLaunchesDefault() { LaunchData launchData = SplashUrlDecoder.getLaunchType("https: assertEquals(ONBOARDING, launchData.getLaunchType()); }
|
public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
@Test public void longIssuerUrlLaunchesIssuerFlow() { LaunchData launchData = SplashUrlDecoder.getLaunchType(ADD_ISSUER_URL + "/extra"); assertEquals(ADD_ISSUER, launchData.getLaunchType()); assertEquals("https: assertEquals("a*bcd", launchData.getNonce()); }
|
public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
@Test public void certificateUrlLaunchesCertificateFlow() { LaunchData launchData = SplashUrlDecoder.getLaunchType(ADD_CERTIFICATE_URL); assertEquals(ADD_CERTIFICATE, launchData.getLaunchType()); assertEquals("https: }
|
public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
@Test public void shortCertificateUrlLaunchesDefault() { LaunchData launchData = SplashUrlDecoder.getLaunchType("https: assertEquals(ONBOARDING, launchData.getLaunchType()); }
|
public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
@Test public void blockcertsAddIssuerUrlLaunchesIssuerFlow() { LaunchData launchData = SplashUrlDecoder.getLaunchType(BLOCKCERTS_ADD_ISSUER_URL); assertEquals(ADD_ISSUER, launchData.getLaunchType()); assertEquals("https: assertEquals("a*bcd", launchData.getNonce()); }
|
public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
@Test public void blockcertsCertificateUrlLaunchesCertificateFlow() { LaunchData launchData = SplashUrlDecoder.getLaunchType(BLOCKCERTS_ADD_CERTIFICATE_URL); assertEquals(ADD_CERTIFICATE, launchData.getLaunchType()); assertEquals("https: }
|
public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
@Test public void blockcertsDirectAddIssuerUrlLaunchesIssuerFlow() { LaunchData launchData = SplashUrlDecoder.getLaunchType(BLOCKCERTS_DIRECT_ADD_ISSUER_URL); assertEquals(ADD_ISSUER, launchData.getLaunchType()); assertEquals("https: assertEquals("a*bcd", launchData.getNonce()); }
|
public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
SplashUrlDecoder { public static LaunchData getLaunchType(String launchUri) { if (launchUri == null) { launchUri = ""; } LaunchData data; if (launchUri.contains(ADD_ISSUER_PATH)) { data = handleAddIssuerUri(launchUri); if (data != null) { return data; } } else if (launchUri.contains(ADD_CERT_PATH)) { data = handleAddCertificateUri(launchUri); if (data != null) { return data; } } return new LaunchData(LaunchType.ONBOARDING); } static LaunchData getLaunchType(String launchUri); }
|
@Test public void testPacketsCreationFile() { Cloud cloud = new Cloud(); cloud.createPacketsFile(); File file = new File(cloud.getSharedDir(), "Packets.txt"); try (BufferedReader inputStream = new BufferedReader(new FileReader(file))) { List<String> lines = inputStream.lines().collect(Collectors.toList()); for (int i = 0; i < lines.size(); i++) { assertEquals(PacketManager.getInstance().getPackets().get(i).getSimpleName(), lines.get(i)); } } catch (IOException e) { e.printStackTrace(); } }
|
public void createPacketsFile() { File packetsFile = new File(this.sharedDir, "Packets.txt"); if (packetsFile.exists()) { try { packetsFile.createNewFile(); } catch (IOException e) { log.error("Cannot create", e); } } try (PrintWriter writer = new PrintWriter(new FileOutputStream(packetsFile))) { for (Class<? extends Packet> packet : PacketManager.getInstance().getPackets()) writer.println(packet.getSimpleName()); } catch (FileNotFoundException e) { log.error("file not found", e); } }
|
Cloud { public void createPacketsFile() { File packetsFile = new File(this.sharedDir, "Packets.txt"); if (packetsFile.exists()) { try { packetsFile.createNewFile(); } catch (IOException e) { log.error("Cannot create", e); } } try (PrintWriter writer = new PrintWriter(new FileOutputStream(packetsFile))) { for (Class<? extends Packet> packet : PacketManager.getInstance().getPackets()) writer.println(packet.getSimpleName()); } catch (FileNotFoundException e) { log.error("file not found", e); } } }
|
Cloud { public void createPacketsFile() { File packetsFile = new File(this.sharedDir, "Packets.txt"); if (packetsFile.exists()) { try { packetsFile.createNewFile(); } catch (IOException e) { log.error("Cannot create", e); } } try (PrintWriter writer = new PrintWriter(new FileOutputStream(packetsFile))) { for (Class<? extends Packet> packet : PacketManager.getInstance().getPackets()) writer.println(packet.getSimpleName()); } catch (FileNotFoundException e) { log.error("file not found", e); } } Cloud(); }
|
Cloud { public void createPacketsFile() { File packetsFile = new File(this.sharedDir, "Packets.txt"); if (packetsFile.exists()) { try { packetsFile.createNewFile(); } catch (IOException e) { log.error("Cannot create", e); } } try (PrintWriter writer = new PrintWriter(new FileOutputStream(packetsFile))) { for (Class<? extends Packet> packet : PacketManager.getInstance().getPackets()) writer.println(packet.getSimpleName()); } catch (FileNotFoundException e) { log.error("file not found", e); } } Cloud(); void stop(); void createPacketsFile(); static Logger getLogger(); static void main(String... args); }
|
Cloud { public void createPacketsFile() { File packetsFile = new File(this.sharedDir, "Packets.txt"); if (packetsFile.exists()) { try { packetsFile.createNewFile(); } catch (IOException e) { log.error("Cannot create", e); } } try (PrintWriter writer = new PrintWriter(new FileOutputStream(packetsFile))) { for (Class<? extends Packet> packet : PacketManager.getInstance().getPackets()) writer.println(packet.getSimpleName()); } catch (FileNotFoundException e) { log.error("file not found", e); } } Cloud(); void stop(); void createPacketsFile(); static Logger getLogger(); static void main(String... args); }
|
@Test public void loadQuestions_ShouldReturnCache_IfItIsAvailable() { repository.caches.addAll(questions); repository.loadQuestions(false).subscribe(questionsTestSubscriber); verifyZeroInteractions(localDataSource); verifyZeroInteractions(remoteDataSource); questionsTestSubscriber.assertValue(questions); }
|
@Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { if (forceRemote) { return refreshData(); } else { if (caches.size() > 0) { return Flowable.just(caches); } else { return localDataSource.loadQuestions(false) .take(1) .flatMap(Flowable::fromIterable) .doOnNext(question -> caches.add(question)) .toList() .toFlowable() .filter(list -> !list.isEmpty()) .switchIfEmpty( refreshData()); } } }
|
QuestionRepository implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { if (forceRemote) { return refreshData(); } else { if (caches.size() > 0) { return Flowable.just(caches); } else { return localDataSource.loadQuestions(false) .take(1) .flatMap(Flowable::fromIterable) .doOnNext(question -> caches.add(question)) .toList() .toFlowable() .filter(list -> !list.isEmpty()) .switchIfEmpty( refreshData()); } } } }
|
QuestionRepository implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { if (forceRemote) { return refreshData(); } else { if (caches.size() > 0) { return Flowable.just(caches); } else { return localDataSource.loadQuestions(false) .take(1) .flatMap(Flowable::fromIterable) .doOnNext(question -> caches.add(question)) .toList() .toFlowable() .filter(list -> !list.isEmpty()) .switchIfEmpty( refreshData()); } } } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); }
|
QuestionRepository implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { if (forceRemote) { return refreshData(); } else { if (caches.size() > 0) { return Flowable.just(caches); } else { return localDataSource.loadQuestions(false) .take(1) .flatMap(Flowable::fromIterable) .doOnNext(question -> caches.add(question)) .toList() .toFlowable() .filter(list -> !list.isEmpty()) .switchIfEmpty( refreshData()); } } } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); Flowable<Question> getQuestion(long questionId); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionRepository implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { if (forceRemote) { return refreshData(); } else { if (caches.size() > 0) { return Flowable.just(caches); } else { return localDataSource.loadQuestions(false) .take(1) .flatMap(Flowable::fromIterable) .doOnNext(question -> caches.add(question)) .toList() .toFlowable() .filter(list -> !list.isEmpty()) .switchIfEmpty( refreshData()); } } } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); Flowable<Question> getQuestion(long questionId); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test(expected = UnsupportedOperationException.class) public void clearData_NoThingToDoWithRemoteService() { remoteDataSource.clearData(); then(questionService).shouldHaveZeroInteractions(); }
|
@Override public void clearData() { throw new UnsupportedOperationException("Unsupported operation"); }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public void clearData() { throw new UnsupportedOperationException("Unsupported operation"); } }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public void clearData() { throw new UnsupportedOperationException("Unsupported operation"); } @Inject QuestionRemoteDataSource(QuestionService questionService); }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public void clearData() { throw new UnsupportedOperationException("Unsupported operation"); } @Inject QuestionRemoteDataSource(QuestionService questionService); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public void clearData() { throw new UnsupportedOperationException("Unsupported operation"); } @Inject QuestionRemoteDataSource(QuestionService questionService); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test public void loadQuestions_ShouldReturnFromLocal_IfCacheIsNotAvailable() { doReturn(Flowable.just(questions)).when(localDataSource).loadQuestions(false); doReturn(Flowable.just(questions)).when(remoteDataSource).loadQuestions(true); repository.loadQuestions(false).subscribe(questionsTestSubscriber); verify(localDataSource).loadQuestions(false); verify(remoteDataSource).loadQuestions(true); questionsTestSubscriber.assertValue(questions); }
|
@Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { if (forceRemote) { return refreshData(); } else { if (caches.size() > 0) { return Flowable.just(caches); } else { return localDataSource.loadQuestions(false) .take(1) .flatMap(Flowable::fromIterable) .doOnNext(question -> caches.add(question)) .toList() .toFlowable() .filter(list -> !list.isEmpty()) .switchIfEmpty( refreshData()); } } }
|
QuestionRepository implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { if (forceRemote) { return refreshData(); } else { if (caches.size() > 0) { return Flowable.just(caches); } else { return localDataSource.loadQuestions(false) .take(1) .flatMap(Flowable::fromIterable) .doOnNext(question -> caches.add(question)) .toList() .toFlowable() .filter(list -> !list.isEmpty()) .switchIfEmpty( refreshData()); } } } }
|
QuestionRepository implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { if (forceRemote) { return refreshData(); } else { if (caches.size() > 0) { return Flowable.just(caches); } else { return localDataSource.loadQuestions(false) .take(1) .flatMap(Flowable::fromIterable) .doOnNext(question -> caches.add(question)) .toList() .toFlowable() .filter(list -> !list.isEmpty()) .switchIfEmpty( refreshData()); } } } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); }
|
QuestionRepository implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { if (forceRemote) { return refreshData(); } else { if (caches.size() > 0) { return Flowable.just(caches); } else { return localDataSource.loadQuestions(false) .take(1) .flatMap(Flowable::fromIterable) .doOnNext(question -> caches.add(question)) .toList() .toFlowable() .filter(list -> !list.isEmpty()) .switchIfEmpty( refreshData()); } } } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); Flowable<Question> getQuestion(long questionId); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionRepository implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { if (forceRemote) { return refreshData(); } else { if (caches.size() > 0) { return Flowable.just(caches); } else { return localDataSource.loadQuestions(false) .take(1) .flatMap(Flowable::fromIterable) .doOnNext(question -> caches.add(question)) .toList() .toFlowable() .filter(list -> !list.isEmpty()) .switchIfEmpty( refreshData()); } } } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); Flowable<Question> getQuestion(long questionId); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test public void getQuestion_ShouldReturnFromCache() { question1.setId(1); question2.setId(2); question3.setId(3); repository.caches.addAll(questions); TestSubscriber<Question> subscriber = new TestSubscriber<>(); repository.getQuestion(1).subscribe(subscriber); then(localDataSource).shouldHaveZeroInteractions(); then(remoteDataSource).shouldHaveZeroInteractions(); subscriber.assertValue(question1); }
|
public Flowable<Question> getQuestion(long questionId) { return Flowable.fromIterable(caches).filter(question -> question.getId() == questionId); }
|
QuestionRepository implements QuestionDataSource { public Flowable<Question> getQuestion(long questionId) { return Flowable.fromIterable(caches).filter(question -> question.getId() == questionId); } }
|
QuestionRepository implements QuestionDataSource { public Flowable<Question> getQuestion(long questionId) { return Flowable.fromIterable(caches).filter(question -> question.getId() == questionId); } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); }
|
QuestionRepository implements QuestionDataSource { public Flowable<Question> getQuestion(long questionId) { return Flowable.fromIterable(caches).filter(question -> question.getId() == questionId); } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); Flowable<Question> getQuestion(long questionId); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionRepository implements QuestionDataSource { public Flowable<Question> getQuestion(long questionId) { return Flowable.fromIterable(caches).filter(question -> question.getId() == questionId); } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); Flowable<Question> getQuestion(long questionId); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test public void clearData_ShouldClearCachesAndLocalData() { repository.caches.addAll(questions); repository.clearData(); assertThat(repository.caches, empty()); then(localDataSource).should().clearData(); }
|
@Override public void clearData() { caches.clear(); localDataSource.clearData(); }
|
QuestionRepository implements QuestionDataSource { @Override public void clearData() { caches.clear(); localDataSource.clearData(); } }
|
QuestionRepository implements QuestionDataSource { @Override public void clearData() { caches.clear(); localDataSource.clearData(); } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); }
|
QuestionRepository implements QuestionDataSource { @Override public void clearData() { caches.clear(); localDataSource.clearData(); } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); Flowable<Question> getQuestion(long questionId); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionRepository implements QuestionDataSource { @Override public void clearData() { caches.clear(); localDataSource.clearData(); } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); Flowable<Question> getQuestion(long questionId); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test(expected = UnsupportedOperationException.class) public void addQuestion_ShouldThrowException() { repository.addQuestion(question1); }
|
@Override public void addQuestion(Question question) { throw new UnsupportedOperationException("Unsupported operation"); }
|
QuestionRepository implements QuestionDataSource { @Override public void addQuestion(Question question) { throw new UnsupportedOperationException("Unsupported operation"); } }
|
QuestionRepository implements QuestionDataSource { @Override public void addQuestion(Question question) { throw new UnsupportedOperationException("Unsupported operation"); } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); }
|
QuestionRepository implements QuestionDataSource { @Override public void addQuestion(Question question) { throw new UnsupportedOperationException("Unsupported operation"); } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); Flowable<Question> getQuestion(long questionId); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionRepository implements QuestionDataSource { @Override public void addQuestion(Question question) { throw new UnsupportedOperationException("Unsupported operation"); } @Inject QuestionRepository(@Local QuestionDataSource localDataSource,
@Remote QuestionDataSource remoteDataSource); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); Flowable<Question> getQuestion(long questionId); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test public void loadQuestions_ShouldReturnFromDatabase() { List<Question> questions = Arrays.asList(new Question(), new Question()); TestSubscriber<List<Question>> subscriber = new TestSubscriber<>(); given(questionDao.getAllQuestions()).willReturn(Flowable.just(questions)); localDataSource.loadQuestions(false).subscribe(subscriber); then(questionDao).should().getAllQuestions(); }
|
@Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { return questionDao.getAllQuestions(); }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { return questionDao.getAllQuestions(); } }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { return questionDao.getAllQuestions(); } @Inject QuestionLocalDataSource(QuestionDao questionDao); }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { return questionDao.getAllQuestions(); } @Inject QuestionLocalDataSource(QuestionDao questionDao); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { return questionDao.getAllQuestions(); } @Inject QuestionLocalDataSource(QuestionDao questionDao); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test public void addQuestion_ShouldInsertToDatabase() { Question question = new Question(); localDataSource.addQuestion(question); then(questionDao).should().insert(question); }
|
@Override public void addQuestion(Question question) { questionDao.insert(question); }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public void addQuestion(Question question) { questionDao.insert(question); } }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public void addQuestion(Question question) { questionDao.insert(question); } @Inject QuestionLocalDataSource(QuestionDao questionDao); }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public void addQuestion(Question question) { questionDao.insert(question); } @Inject QuestionLocalDataSource(QuestionDao questionDao); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public void addQuestion(Question question) { questionDao.insert(question); } @Inject QuestionLocalDataSource(QuestionDao questionDao); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test public void clearData_ShouldDeleteAllDataInDatabase() { localDataSource.clearData(); then(questionDao).should().deleteAll(); }
|
@Override public void clearData() { questionDao.deleteAll(); }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public void clearData() { questionDao.deleteAll(); } }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public void clearData() { questionDao.deleteAll(); } @Inject QuestionLocalDataSource(QuestionDao questionDao); }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public void clearData() { questionDao.deleteAll(); } @Inject QuestionLocalDataSource(QuestionDao questionDao); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionLocalDataSource implements QuestionDataSource { @Override public void clearData() { questionDao.deleteAll(); } @Inject QuestionLocalDataSource(QuestionDao questionDao); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test public void loadQuestions_ShouldReturnFromRemoteService() { QuestionResponse questionResponse = new QuestionResponse(); TestSubscriber<List<Question>> subscriber = new TestSubscriber<>(); given(questionService.loadQuestionsByTag(Config.ANDROID_QUESTION_TAG)).willReturn(Flowable.just(questionResponse)); remoteDataSource.loadQuestions(anyBoolean()).subscribe(subscriber); then(questionService).should().loadQuestionsByTag(Config.ANDROID_QUESTION_TAG); }
|
@Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { return questionService.loadQuestionsByTag(Config.ANDROID_QUESTION_TAG).map(QuestionResponse::getQuestions); }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { return questionService.loadQuestionsByTag(Config.ANDROID_QUESTION_TAG).map(QuestionResponse::getQuestions); } }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { return questionService.loadQuestionsByTag(Config.ANDROID_QUESTION_TAG).map(QuestionResponse::getQuestions); } @Inject QuestionRemoteDataSource(QuestionService questionService); }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { return questionService.loadQuestionsByTag(Config.ANDROID_QUESTION_TAG).map(QuestionResponse::getQuestions); } @Inject QuestionRemoteDataSource(QuestionService questionService); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public Flowable<List<Question>> loadQuestions(boolean forceRemote) { return questionService.loadQuestionsByTag(Config.ANDROID_QUESTION_TAG).map(QuestionResponse::getQuestions); } @Inject QuestionRemoteDataSource(QuestionService questionService); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test(expected = UnsupportedOperationException.class) public void addQuestion_NoThingToDoWithRemoteService() { Question question = mock(Question.class); remoteDataSource.addQuestion(question); then(questionService).shouldHaveZeroInteractions(); }
|
@Override public void addQuestion(Question question) { throw new UnsupportedOperationException("Unsupported operation"); }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public void addQuestion(Question question) { throw new UnsupportedOperationException("Unsupported operation"); } }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public void addQuestion(Question question) { throw new UnsupportedOperationException("Unsupported operation"); } @Inject QuestionRemoteDataSource(QuestionService questionService); }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public void addQuestion(Question question) { throw new UnsupportedOperationException("Unsupported operation"); } @Inject QuestionRemoteDataSource(QuestionService questionService); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
QuestionRemoteDataSource implements QuestionDataSource { @Override public void addQuestion(Question question) { throw new UnsupportedOperationException("Unsupported operation"); } @Inject QuestionRemoteDataSource(QuestionService questionService); @Override Flowable<List<Question>> loadQuestions(boolean forceRemote); @Override void addQuestion(Question question); @Override void clearData(); }
|
@Test public void pathUtilTest1() { File[] roots = File.listRoots(); if (roots.length > 1) { File basePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "test.txt"); File relativePath = new File(roots[1] + "some" + File.separatorChar + "dir" + File.separatorChar + "test.txt"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, relativePath.getPath()); } }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest11() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some"); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "dir2"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "dir" + File.separatorChar + "dir2"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest12() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "dir2" + File.separatorChar); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "dir" + File.separatorChar + "dir2"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest13() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some"); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "dir2" + File.separatorChar); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "dir" + File.separatorChar + "dir2"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest14() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "dir2"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "dir" + File.separatorChar + "dir2"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest15() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar + "dir3"); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "dir2"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, ".." + File.separatorChar + "dir" + File.separatorChar + "dir2"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest16() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some2" + File.separatorChar + "dir3"); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "dir2"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, ".." + File.separatorChar + ".." + File.separatorChar + "some" + File.separatorChar + "dir" + File.separatorChar + "dir2"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest17() { File[] roots = File.listRoots(); File basePath = new File(roots[0].getPath()); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "dir2"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "some" + File.separatorChar + "dir" + File.separatorChar + "dir2"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest18() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar + "dir"); File relativePath = new File(roots[0] + "some"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, ".."); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest19() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "dir2"); File relativePath = new File(roots[0] + "some"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, ".." + File.separatorChar + ".."); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest2() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "test.txt"); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar + "test.txt"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "."); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest3() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "."); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest4() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar + "dir"); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "."); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest5() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar + "dir"); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "."); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest6() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "."); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest7() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some"); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "dir"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest8() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "dir"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest9() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some"); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir" + File.separatorChar); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "dir"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void pathUtilTest10() { File[] roots = File.listRoots(); File basePath = new File(roots[0] + "some" + File.separatorChar); File relativePath = new File(roots[0] + "some" + File.separatorChar + "dir"); String path = PathUtil.getRelativeFileInternal(basePath, relativePath); Assert.assertEquals(path, "dir"); }
|
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
PathUtil { static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) { ArrayList<String> basePath = getPathComponents(canonicalBaseFile); ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize); if (!basePath.get(0).equals(pathToRelativize.get(0))) { return canonicalFileToRelativize.getPath(); } int commonDirs; StringBuilder sb = new StringBuilder(); for (commonDirs=1; commonDirs<basePath.size() && commonDirs<pathToRelativize.size(); commonDirs++) { if (!basePath.get(commonDirs).equals(pathToRelativize.get(commonDirs))) { break; } } boolean first = true; for (int i=commonDirs; i<basePath.size(); i++) { if (!first) { sb.append(File.separatorChar); } else { first = false; } sb.append(".."); } first = true; for (int i=commonDirs; i<pathToRelativize.size(); i++) { if (first) { if (sb.length() != 0) { sb.append(File.separatorChar); } first = false; } else { sb.append(File.separatorChar); } sb.append(pathToRelativize.get(i)); } if (sb.length() == 0) { return "."; } return sb.toString(); } private PathUtil(); static File getRelativeFile(File baseFile, File fileToRelativize); static String getRelativePath(String basePath, String pathToRelativize); }
|
@Test public void testArrayParser() { IsClass clsArray = service.toClass("java.lang.Class[]"); Assert.assertNotNull(clsArray); }
|
@Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); @Override IsClass toClass(String binaryName); @Override IsMethod toMethod(CtMethod type); @Override IsField toField(CtField type); @Override IsAnnotation toAnnotation(Annotation type); IsType[] toTypes(CtClass[] parameterTypes); static MappedIterable<Method> getMethodsInDeclaredOrder(Class<?> type); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); @Override IsClass toClass(String binaryName); @Override IsMethod toMethod(CtMethod type); @Override IsField toField(CtField type); @Override IsAnnotation toAnnotation(Annotation type); IsType[] toTypes(CtClass[] parameterTypes); static MappedIterable<Method> getMethodsInDeclaredOrder(Class<?> type); }
|
@Test public void testUserToStringNamed() { ToStringUserInterface ui = X_AutoUi.makeUi(MODEL, UserViewNamed.class, ToStringUserInterface.class); Assert.assertEquals("email: email,\nname: name,\nid: id", ui.toString()); }
|
@Override public String toString() { return b.toString(); }
|
ToStringUserInterface extends AbstractUserInterface implements Appendable { @Override public String toString() { return b.toString(); } }
|
ToStringUserInterface extends AbstractUserInterface implements Appendable { @Override public String toString() { return b.toString(); } }
|
ToStringUserInterface extends AbstractUserInterface implements Appendable { @Override public String toString() { return b.toString(); } @Override int hashCode(); @Override String toString(); @Override boolean equals(Object obj); @Override Appendable append(CharSequence csq); @Override Appendable append(CharSequence csq, int start, int end); @Override Appendable append(char c); }
|
ToStringUserInterface extends AbstractUserInterface implements Appendable { @Override public String toString() { return b.toString(); } @Override int hashCode(); @Override String toString(); @Override boolean equals(Object obj); @Override Appendable append(CharSequence csq); @Override Appendable append(CharSequence csq, int start, int end); @Override Appendable append(char c); }
|
@Test public void testAnnotationLexer() { final short[] success = new short[1]; final String annoBody = "name=\"one \\\"\\\"two\\\"\\\" three\\\\\", " + "{1, 2.0, false}, values={1, \"string\", com.test.Class.class}"; JavaLexer.visitAnnotation(new AnnotationVisitor<Void>(){ @Override public AnnotationMemberVisitor<Void> visitAnnotation(String annoName, String annoContent, Void receiver) { success[0] = 1; Assert.assertEquals(annoName, "java.lang.Annotation"); Assert.assertEquals(annoContent, annoBody); return null; } }, null, "@java.lang.Annotation(" + annoBody + ")" , 0); Assert.assertEquals(success[0], 1); }
|
public static <R> int visitAnnotation (final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos) { pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } int start = pos; try { while(chars.charAt(pos) == '@') { pos = eatJavaname(chars, pos + 1); final String annoName = chars.subSequence(start + 1, pos).toString(); String annoBody = ""; pos = eatWhitespace(chars, pos); if (pos < chars.length() && chars.charAt(pos) == '(') { final int bodyStart = pos+1; pos = eatAnnotationBody(visitor, receiver, chars, pos); annoBody = chars.subSequence(bodyStart, pos).toString(); pos ++; } final AnnotationMemberVisitor<R> bodyVisitor = visitor.visitAnnotation(annoName, annoBody, receiver); if (bodyVisitor != null && annoBody.length() > 0) { visitAnnotationMembers(bodyVisitor, receiver, annoBody, 0); } start = pos = eatWhitespace(chars, pos); if (pos == chars.length()) { break; } } } catch (final IndexOutOfBoundsException e) { error( e, "Error parsing annotation on: " + chars.subSequence(start, chars.length())); } return pos; }
|
JavaLexer { public static <R> int visitAnnotation (final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos) { pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } int start = pos; try { while(chars.charAt(pos) == '@') { pos = eatJavaname(chars, pos + 1); final String annoName = chars.subSequence(start + 1, pos).toString(); String annoBody = ""; pos = eatWhitespace(chars, pos); if (pos < chars.length() && chars.charAt(pos) == '(') { final int bodyStart = pos+1; pos = eatAnnotationBody(visitor, receiver, chars, pos); annoBody = chars.subSequence(bodyStart, pos).toString(); pos ++; } final AnnotationMemberVisitor<R> bodyVisitor = visitor.visitAnnotation(annoName, annoBody, receiver); if (bodyVisitor != null && annoBody.length() > 0) { visitAnnotationMembers(bodyVisitor, receiver, annoBody, 0); } start = pos = eatWhitespace(chars, pos); if (pos == chars.length()) { break; } } } catch (final IndexOutOfBoundsException e) { error( e, "Error parsing annotation on: " + chars.subSequence(start, chars.length())); } return pos; } }
|
JavaLexer { public static <R> int visitAnnotation (final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos) { pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } int start = pos; try { while(chars.charAt(pos) == '@') { pos = eatJavaname(chars, pos + 1); final String annoName = chars.subSequence(start + 1, pos).toString(); String annoBody = ""; pos = eatWhitespace(chars, pos); if (pos < chars.length() && chars.charAt(pos) == '(') { final int bodyStart = pos+1; pos = eatAnnotationBody(visitor, receiver, chars, pos); annoBody = chars.subSequence(bodyStart, pos).toString(); pos ++; } final AnnotationMemberVisitor<R> bodyVisitor = visitor.visitAnnotation(annoName, annoBody, receiver); if (bodyVisitor != null && annoBody.length() > 0) { visitAnnotationMembers(bodyVisitor, receiver, annoBody, 0); } start = pos = eatWhitespace(chars, pos); if (pos == chars.length()) { break; } } } catch (final IndexOutOfBoundsException e) { error( e, "Error parsing annotation on: " + chars.subSequence(start, chars.length())); } return pos; } JavaLexer(String definition); }
|
JavaLexer { public static <R> int visitAnnotation (final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos) { pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } int start = pos; try { while(chars.charAt(pos) == '@') { pos = eatJavaname(chars, pos + 1); final String annoName = chars.subSequence(start + 1, pos).toString(); String annoBody = ""; pos = eatWhitespace(chars, pos); if (pos < chars.length() && chars.charAt(pos) == '(') { final int bodyStart = pos+1; pos = eatAnnotationBody(visitor, receiver, chars, pos); annoBody = chars.subSequence(bodyStart, pos).toString(); pos ++; } final AnnotationMemberVisitor<R> bodyVisitor = visitor.visitAnnotation(annoName, annoBody, receiver); if (bodyVisitor != null && annoBody.length() > 0) { visitAnnotationMembers(bodyVisitor, receiver, annoBody, 0); } start = pos = eatWhitespace(chars, pos); if (pos == chars.length()) { break; } } } catch (final IndexOutOfBoundsException e) { error( e, "Error parsing annotation on: " + chars.subSequence(start, chars.length())); } return pos; } JavaLexer(String definition); static int visitJavadoc(final JavadocVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotation(final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotationMembers(final AnnotationMemberVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitModifier(final ModifierVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitGeneric(final GenericVisitor<R> visitor, final R receiver,
final CharSequence chars, int pos); static int visitMethodSignature(final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static TypeDef extractType(final CharSequence chars, int pos); static SimpleStack<IsGeneric> extractGenerics(final CharSequence chars, final int pos); String getClassName(); int getPrivacy(); int getModifier(); String getSuperClass(); String[] getGenerics(); String[] getImports(); String[] getInterfaces(); boolean isPublic(); boolean isPrivate(); boolean isProtected(); boolean isStatic(); boolean isFinal(); boolean isAbstract(); boolean isNative(); boolean isClass(); boolean isAnnotation(); boolean isEnum(); boolean hasGenerics(); static Iterable<String> findImportsInGeneric(final String generic); static IsParameter lexParam(final CharSequence chars); static int visitClassFile(final ClassVisitor<Param> extractor,
final Param receiver, final CharSequence chars, int pos); }
|
JavaLexer { public static <R> int visitAnnotation (final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos) { pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } int start = pos; try { while(chars.charAt(pos) == '@') { pos = eatJavaname(chars, pos + 1); final String annoName = chars.subSequence(start + 1, pos).toString(); String annoBody = ""; pos = eatWhitespace(chars, pos); if (pos < chars.length() && chars.charAt(pos) == '(') { final int bodyStart = pos+1; pos = eatAnnotationBody(visitor, receiver, chars, pos); annoBody = chars.subSequence(bodyStart, pos).toString(); pos ++; } final AnnotationMemberVisitor<R> bodyVisitor = visitor.visitAnnotation(annoName, annoBody, receiver); if (bodyVisitor != null && annoBody.length() > 0) { visitAnnotationMembers(bodyVisitor, receiver, annoBody, 0); } start = pos = eatWhitespace(chars, pos); if (pos == chars.length()) { break; } } } catch (final IndexOutOfBoundsException e) { error( e, "Error parsing annotation on: " + chars.subSequence(start, chars.length())); } return pos; } JavaLexer(String definition); static int visitJavadoc(final JavadocVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotation(final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotationMembers(final AnnotationMemberVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitModifier(final ModifierVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitGeneric(final GenericVisitor<R> visitor, final R receiver,
final CharSequence chars, int pos); static int visitMethodSignature(final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static TypeDef extractType(final CharSequence chars, int pos); static SimpleStack<IsGeneric> extractGenerics(final CharSequence chars, final int pos); String getClassName(); int getPrivacy(); int getModifier(); String getSuperClass(); String[] getGenerics(); String[] getImports(); String[] getInterfaces(); boolean isPublic(); boolean isPrivate(); boolean isProtected(); boolean isStatic(); boolean isFinal(); boolean isAbstract(); boolean isNative(); boolean isClass(); boolean isAnnotation(); boolean isEnum(); boolean hasGenerics(); static Iterable<String> findImportsInGeneric(final String generic); static IsParameter lexParam(final CharSequence chars); static int visitClassFile(final ClassVisitor<Param> extractor,
final Param receiver, final CharSequence chars, int pos); }
|
@Test public void testTypeLexer() { String type = "java.lang.Class"; TypeData data = JavaLexer.extractType(type, 0); Assert.assertEquals("java.lang", data.pkgName); Assert.assertEquals("Class", data.clsName); Assert.assertEquals("Class", data.simpleName); Assert.assertEquals(type, data.toString()); String generics = "<SomeGenerics<With, Generics, In<Them>>>"; type = "com.foo.Outer.Inner" + generics + " [] [][ ]"; data = JavaLexer.extractType(type, 0); Assert.assertEquals("com.foo", data.pkgName); Assert.assertEquals("Outer.Inner", data.clsName); Assert.assertEquals("Inner", data.simpleName); Assert.assertEquals(3, data.arrayDepth); Assert.assertEquals(generics, data.generics); }
|
public static TypeDef extractType(final CharSequence chars, int pos) { int start = pos = eatWhitespace(chars, pos); int lastPeriod = -1; final int max = chars.length()-1; boolean doneParsing = false; final StringBuilder pkg = new StringBuilder(); package_loop: if (Character.isLowerCase(chars.charAt(pos))) { while(true) { pos = eatWhitespace(chars, pos); while(Character.isJavaIdentifierPart(chars.charAt(++pos))){ if (pos == max){ if (lastPeriod == -1) { doneParsing = true; } else { start = pos = lastPeriod + 1; } break package_loop; } } final int whitespace = eatWhitespace(chars, pos); final int next = chars.charAt(whitespace); if (next == '.') { if (whitespace > pos && chars.charAt(whitespace+1)=='.') { break package_loop; } if (lastPeriod != -1) { pkg.append('.'); } lastPeriod = pos = whitespace; pkg.append(chars.subSequence(start, pos).toString().trim()); pos = start = eatWhitespace(chars, pos+1); if (Character.isUpperCase(chars.charAt(start))) { break package_loop; } } else { if (whitespace > pos || next == '[' || next == '<') { doneParsing = true; break package_loop; } } } } TypeDef def; if (doneParsing){ if (pos == max) { return new TypeDef(chars.subSequence(start, pos+1).toString(), pos); } def = new TypeDef(chars.subSequence(start, pos).toString()); } else { final StringBuilder typeName = new StringBuilder(); lastPeriod = -1; typeloop: while (true) { pos = eatWhitespace(chars, pos); if (!Character.isJavaIdentifierStart(chars.charAt(pos))){ if (pos > start) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos).toString().trim()); } break; } while(Character.isJavaIdentifierPart(chars.charAt(++pos))) { if (pos == max) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos+1).toString().trim()); break typeloop; } } final int whitespace = eatWhitespace(chars, pos); if (chars.charAt(whitespace) == '.') { if (lastPeriod != -1) { typeName.append('.'); } if (pos != whitespace && chars.charAt(whitespace + 1) == '.') { typeName.append(chars.subSequence(start, pos).toString().trim()); break; } lastPeriod = pos = whitespace; typeName.append(chars.subSequence(start, pos).toString()); start = pos = eatWhitespace(chars, pos+1); } else { if (whitespace > pos) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos).toString().trim()); break; } } } def = new TypeDef(typeName.toString()); if (pos == max) { pos++; } } def.pkgName = pkg.toString(); start = pos = eatWhitespace(chars, pos); if (pos < chars.length()) { pos = eatGeneric(chars, pos); if (pos != start) { def.generics = chars.subSequence(start, ++pos).toString(); } } pos = eatWhitespace(chars, pos); while (pos < max && chars.charAt(pos) == '[') { def.arrayDepth ++; while (chars.charAt(++pos)!=']') { ; } pos = eatWhitespace(chars, pos+1); } if (pos < chars.length() && chars.charAt(pos) == '.') { assert chars.charAt(pos+1) == '.'; assert chars.charAt(pos+2) == '.'; def.arrayDepth++; def.varargs = true; pos = eatWhitespace(chars, pos+3); } def.index = pos; return def; }
|
JavaLexer { public static TypeDef extractType(final CharSequence chars, int pos) { int start = pos = eatWhitespace(chars, pos); int lastPeriod = -1; final int max = chars.length()-1; boolean doneParsing = false; final StringBuilder pkg = new StringBuilder(); package_loop: if (Character.isLowerCase(chars.charAt(pos))) { while(true) { pos = eatWhitespace(chars, pos); while(Character.isJavaIdentifierPart(chars.charAt(++pos))){ if (pos == max){ if (lastPeriod == -1) { doneParsing = true; } else { start = pos = lastPeriod + 1; } break package_loop; } } final int whitespace = eatWhitespace(chars, pos); final int next = chars.charAt(whitespace); if (next == '.') { if (whitespace > pos && chars.charAt(whitespace+1)=='.') { break package_loop; } if (lastPeriod != -1) { pkg.append('.'); } lastPeriod = pos = whitespace; pkg.append(chars.subSequence(start, pos).toString().trim()); pos = start = eatWhitespace(chars, pos+1); if (Character.isUpperCase(chars.charAt(start))) { break package_loop; } } else { if (whitespace > pos || next == '[' || next == '<') { doneParsing = true; break package_loop; } } } } TypeDef def; if (doneParsing){ if (pos == max) { return new TypeDef(chars.subSequence(start, pos+1).toString(), pos); } def = new TypeDef(chars.subSequence(start, pos).toString()); } else { final StringBuilder typeName = new StringBuilder(); lastPeriod = -1; typeloop: while (true) { pos = eatWhitespace(chars, pos); if (!Character.isJavaIdentifierStart(chars.charAt(pos))){ if (pos > start) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos).toString().trim()); } break; } while(Character.isJavaIdentifierPart(chars.charAt(++pos))) { if (pos == max) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos+1).toString().trim()); break typeloop; } } final int whitespace = eatWhitespace(chars, pos); if (chars.charAt(whitespace) == '.') { if (lastPeriod != -1) { typeName.append('.'); } if (pos != whitespace && chars.charAt(whitespace + 1) == '.') { typeName.append(chars.subSequence(start, pos).toString().trim()); break; } lastPeriod = pos = whitespace; typeName.append(chars.subSequence(start, pos).toString()); start = pos = eatWhitespace(chars, pos+1); } else { if (whitespace > pos) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos).toString().trim()); break; } } } def = new TypeDef(typeName.toString()); if (pos == max) { pos++; } } def.pkgName = pkg.toString(); start = pos = eatWhitespace(chars, pos); if (pos < chars.length()) { pos = eatGeneric(chars, pos); if (pos != start) { def.generics = chars.subSequence(start, ++pos).toString(); } } pos = eatWhitespace(chars, pos); while (pos < max && chars.charAt(pos) == '[') { def.arrayDepth ++; while (chars.charAt(++pos)!=']') { ; } pos = eatWhitespace(chars, pos+1); } if (pos < chars.length() && chars.charAt(pos) == '.') { assert chars.charAt(pos+1) == '.'; assert chars.charAt(pos+2) == '.'; def.arrayDepth++; def.varargs = true; pos = eatWhitespace(chars, pos+3); } def.index = pos; return def; } }
|
JavaLexer { public static TypeDef extractType(final CharSequence chars, int pos) { int start = pos = eatWhitespace(chars, pos); int lastPeriod = -1; final int max = chars.length()-1; boolean doneParsing = false; final StringBuilder pkg = new StringBuilder(); package_loop: if (Character.isLowerCase(chars.charAt(pos))) { while(true) { pos = eatWhitespace(chars, pos); while(Character.isJavaIdentifierPart(chars.charAt(++pos))){ if (pos == max){ if (lastPeriod == -1) { doneParsing = true; } else { start = pos = lastPeriod + 1; } break package_loop; } } final int whitespace = eatWhitespace(chars, pos); final int next = chars.charAt(whitespace); if (next == '.') { if (whitespace > pos && chars.charAt(whitespace+1)=='.') { break package_loop; } if (lastPeriod != -1) { pkg.append('.'); } lastPeriod = pos = whitespace; pkg.append(chars.subSequence(start, pos).toString().trim()); pos = start = eatWhitespace(chars, pos+1); if (Character.isUpperCase(chars.charAt(start))) { break package_loop; } } else { if (whitespace > pos || next == '[' || next == '<') { doneParsing = true; break package_loop; } } } } TypeDef def; if (doneParsing){ if (pos == max) { return new TypeDef(chars.subSequence(start, pos+1).toString(), pos); } def = new TypeDef(chars.subSequence(start, pos).toString()); } else { final StringBuilder typeName = new StringBuilder(); lastPeriod = -1; typeloop: while (true) { pos = eatWhitespace(chars, pos); if (!Character.isJavaIdentifierStart(chars.charAt(pos))){ if (pos > start) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos).toString().trim()); } break; } while(Character.isJavaIdentifierPart(chars.charAt(++pos))) { if (pos == max) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos+1).toString().trim()); break typeloop; } } final int whitespace = eatWhitespace(chars, pos); if (chars.charAt(whitespace) == '.') { if (lastPeriod != -1) { typeName.append('.'); } if (pos != whitespace && chars.charAt(whitespace + 1) == '.') { typeName.append(chars.subSequence(start, pos).toString().trim()); break; } lastPeriod = pos = whitespace; typeName.append(chars.subSequence(start, pos).toString()); start = pos = eatWhitespace(chars, pos+1); } else { if (whitespace > pos) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos).toString().trim()); break; } } } def = new TypeDef(typeName.toString()); if (pos == max) { pos++; } } def.pkgName = pkg.toString(); start = pos = eatWhitespace(chars, pos); if (pos < chars.length()) { pos = eatGeneric(chars, pos); if (pos != start) { def.generics = chars.subSequence(start, ++pos).toString(); } } pos = eatWhitespace(chars, pos); while (pos < max && chars.charAt(pos) == '[') { def.arrayDepth ++; while (chars.charAt(++pos)!=']') { ; } pos = eatWhitespace(chars, pos+1); } if (pos < chars.length() && chars.charAt(pos) == '.') { assert chars.charAt(pos+1) == '.'; assert chars.charAt(pos+2) == '.'; def.arrayDepth++; def.varargs = true; pos = eatWhitespace(chars, pos+3); } def.index = pos; return def; } JavaLexer(String definition); }
|
JavaLexer { public static TypeDef extractType(final CharSequence chars, int pos) { int start = pos = eatWhitespace(chars, pos); int lastPeriod = -1; final int max = chars.length()-1; boolean doneParsing = false; final StringBuilder pkg = new StringBuilder(); package_loop: if (Character.isLowerCase(chars.charAt(pos))) { while(true) { pos = eatWhitespace(chars, pos); while(Character.isJavaIdentifierPart(chars.charAt(++pos))){ if (pos == max){ if (lastPeriod == -1) { doneParsing = true; } else { start = pos = lastPeriod + 1; } break package_loop; } } final int whitespace = eatWhitespace(chars, pos); final int next = chars.charAt(whitespace); if (next == '.') { if (whitespace > pos && chars.charAt(whitespace+1)=='.') { break package_loop; } if (lastPeriod != -1) { pkg.append('.'); } lastPeriod = pos = whitespace; pkg.append(chars.subSequence(start, pos).toString().trim()); pos = start = eatWhitespace(chars, pos+1); if (Character.isUpperCase(chars.charAt(start))) { break package_loop; } } else { if (whitespace > pos || next == '[' || next == '<') { doneParsing = true; break package_loop; } } } } TypeDef def; if (doneParsing){ if (pos == max) { return new TypeDef(chars.subSequence(start, pos+1).toString(), pos); } def = new TypeDef(chars.subSequence(start, pos).toString()); } else { final StringBuilder typeName = new StringBuilder(); lastPeriod = -1; typeloop: while (true) { pos = eatWhitespace(chars, pos); if (!Character.isJavaIdentifierStart(chars.charAt(pos))){ if (pos > start) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos).toString().trim()); } break; } while(Character.isJavaIdentifierPart(chars.charAt(++pos))) { if (pos == max) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos+1).toString().trim()); break typeloop; } } final int whitespace = eatWhitespace(chars, pos); if (chars.charAt(whitespace) == '.') { if (lastPeriod != -1) { typeName.append('.'); } if (pos != whitespace && chars.charAt(whitespace + 1) == '.') { typeName.append(chars.subSequence(start, pos).toString().trim()); break; } lastPeriod = pos = whitespace; typeName.append(chars.subSequence(start, pos).toString()); start = pos = eatWhitespace(chars, pos+1); } else { if (whitespace > pos) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos).toString().trim()); break; } } } def = new TypeDef(typeName.toString()); if (pos == max) { pos++; } } def.pkgName = pkg.toString(); start = pos = eatWhitespace(chars, pos); if (pos < chars.length()) { pos = eatGeneric(chars, pos); if (pos != start) { def.generics = chars.subSequence(start, ++pos).toString(); } } pos = eatWhitespace(chars, pos); while (pos < max && chars.charAt(pos) == '[') { def.arrayDepth ++; while (chars.charAt(++pos)!=']') { ; } pos = eatWhitespace(chars, pos+1); } if (pos < chars.length() && chars.charAt(pos) == '.') { assert chars.charAt(pos+1) == '.'; assert chars.charAt(pos+2) == '.'; def.arrayDepth++; def.varargs = true; pos = eatWhitespace(chars, pos+3); } def.index = pos; return def; } JavaLexer(String definition); static int visitJavadoc(final JavadocVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotation(final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotationMembers(final AnnotationMemberVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitModifier(final ModifierVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitGeneric(final GenericVisitor<R> visitor, final R receiver,
final CharSequence chars, int pos); static int visitMethodSignature(final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static TypeDef extractType(final CharSequence chars, int pos); static SimpleStack<IsGeneric> extractGenerics(final CharSequence chars, final int pos); String getClassName(); int getPrivacy(); int getModifier(); String getSuperClass(); String[] getGenerics(); String[] getImports(); String[] getInterfaces(); boolean isPublic(); boolean isPrivate(); boolean isProtected(); boolean isStatic(); boolean isFinal(); boolean isAbstract(); boolean isNative(); boolean isClass(); boolean isAnnotation(); boolean isEnum(); boolean hasGenerics(); static Iterable<String> findImportsInGeneric(final String generic); static IsParameter lexParam(final CharSequence chars); static int visitClassFile(final ClassVisitor<Param> extractor,
final Param receiver, final CharSequence chars, int pos); }
|
JavaLexer { public static TypeDef extractType(final CharSequence chars, int pos) { int start = pos = eatWhitespace(chars, pos); int lastPeriod = -1; final int max = chars.length()-1; boolean doneParsing = false; final StringBuilder pkg = new StringBuilder(); package_loop: if (Character.isLowerCase(chars.charAt(pos))) { while(true) { pos = eatWhitespace(chars, pos); while(Character.isJavaIdentifierPart(chars.charAt(++pos))){ if (pos == max){ if (lastPeriod == -1) { doneParsing = true; } else { start = pos = lastPeriod + 1; } break package_loop; } } final int whitespace = eatWhitespace(chars, pos); final int next = chars.charAt(whitespace); if (next == '.') { if (whitespace > pos && chars.charAt(whitespace+1)=='.') { break package_loop; } if (lastPeriod != -1) { pkg.append('.'); } lastPeriod = pos = whitespace; pkg.append(chars.subSequence(start, pos).toString().trim()); pos = start = eatWhitespace(chars, pos+1); if (Character.isUpperCase(chars.charAt(start))) { break package_loop; } } else { if (whitespace > pos || next == '[' || next == '<') { doneParsing = true; break package_loop; } } } } TypeDef def; if (doneParsing){ if (pos == max) { return new TypeDef(chars.subSequence(start, pos+1).toString(), pos); } def = new TypeDef(chars.subSequence(start, pos).toString()); } else { final StringBuilder typeName = new StringBuilder(); lastPeriod = -1; typeloop: while (true) { pos = eatWhitespace(chars, pos); if (!Character.isJavaIdentifierStart(chars.charAt(pos))){ if (pos > start) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos).toString().trim()); } break; } while(Character.isJavaIdentifierPart(chars.charAt(++pos))) { if (pos == max) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos+1).toString().trim()); break typeloop; } } final int whitespace = eatWhitespace(chars, pos); if (chars.charAt(whitespace) == '.') { if (lastPeriod != -1) { typeName.append('.'); } if (pos != whitespace && chars.charAt(whitespace + 1) == '.') { typeName.append(chars.subSequence(start, pos).toString().trim()); break; } lastPeriod = pos = whitespace; typeName.append(chars.subSequence(start, pos).toString()); start = pos = eatWhitespace(chars, pos+1); } else { if (whitespace > pos) { if (lastPeriod != -1) { typeName.append('.'); } typeName.append(chars.subSequence(start, pos).toString().trim()); break; } } } def = new TypeDef(typeName.toString()); if (pos == max) { pos++; } } def.pkgName = pkg.toString(); start = pos = eatWhitespace(chars, pos); if (pos < chars.length()) { pos = eatGeneric(chars, pos); if (pos != start) { def.generics = chars.subSequence(start, ++pos).toString(); } } pos = eatWhitespace(chars, pos); while (pos < max && chars.charAt(pos) == '[') { def.arrayDepth ++; while (chars.charAt(++pos)!=']') { ; } pos = eatWhitespace(chars, pos+1); } if (pos < chars.length() && chars.charAt(pos) == '.') { assert chars.charAt(pos+1) == '.'; assert chars.charAt(pos+2) == '.'; def.arrayDepth++; def.varargs = true; pos = eatWhitespace(chars, pos+3); } def.index = pos; return def; } JavaLexer(String definition); static int visitJavadoc(final JavadocVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotation(final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotationMembers(final AnnotationMemberVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitModifier(final ModifierVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitGeneric(final GenericVisitor<R> visitor, final R receiver,
final CharSequence chars, int pos); static int visitMethodSignature(final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static TypeDef extractType(final CharSequence chars, int pos); static SimpleStack<IsGeneric> extractGenerics(final CharSequence chars, final int pos); String getClassName(); int getPrivacy(); int getModifier(); String getSuperClass(); String[] getGenerics(); String[] getImports(); String[] getInterfaces(); boolean isPublic(); boolean isPrivate(); boolean isProtected(); boolean isStatic(); boolean isFinal(); boolean isAbstract(); boolean isNative(); boolean isClass(); boolean isAnnotation(); boolean isEnum(); boolean hasGenerics(); static Iterable<String> findImportsInGeneric(final String generic); static IsParameter lexParam(final CharSequence chars); static int visitClassFile(final ClassVisitor<Param> extractor,
final Param receiver, final CharSequence chars, int pos); }
|
@Test public void testMethodLexer() { final String methodGeneric = "<Complex, Generic extends Signature & More<Stuff>>"; final String modifiers = "public static final"; final String returnType = "Type"; final String returnGeneric = "<With<Generics>>"; final String methodName = "methodName"; final String paramGeneric = "<? extends Generic<int[]>>"; String params = "String[] i, java . lang . Class" +paramGeneric+ " cls"; String exceptions = "java.lang.RuntimeException, ClassCastException "; String method = modifiers + " "+methodGeneric +" "+ returnType+returnGeneric+"[][] " + methodName+ "(" + params+") throws "+exceptions; final int[] success = new int[8]; JavaLexer.visitMethodSignature(new MethodVisitor<Void>() { @Override public AnnotationMemberVisitor<Void> visitAnnotation(String annoName, String annoBody, Void receiver) { Assert.fail("No annotations"); return null; } @Override public void visitJavadoc(String javadoc, Void receiver) { Assert.fail("No javadoc"); } @Override public void visitModifier(int modifier, Void receiver) { switch(modifier) { case Modifier.PUBLIC: case Modifier.STATIC: case Modifier.FINAL: success[0] = success[0] | modifier; break; default: Assert.fail("Illegal modifier: "+Integer.toHexString(modifier)); } } @Override public void visitGeneric(String generic, Void receiver) { Assert.assertEquals(generic, methodGeneric); success[1] = 1; } @Override public void visitReturnType(TypeData returnedType, Void receiver) { Assert.assertEquals(returnedType.clsName, returnType); Assert.assertEquals(returnedType.generics, returnGeneric); Assert.assertEquals(returnedType.arrayDepth, 2); success[2] = 1; } @Override public void visitName(String name, Void receiver) { Assert.assertEquals(name, methodName); success[3] = 1; } @Override public ParameterVisitor<Void> visitParameter() { return new ParameterVisitor<Void>() { @Override public AnnotationMemberVisitor<Void> visitAnnotation(String annoName, String annoBody, Void receiver) { return null; } @Override public void visitModifier(int modifier, Void receiver) { } @Override public void visitType(TypeData type, String name, boolean varargs, Void receiver) { if ("i".equals(name)) { success[4] = 1; Assert.assertEquals("String", type.clsName); Assert.assertEquals(1, type.arrayDepth); } else if ("cls".equals(name)){ success[5] = 1; Assert.assertEquals("java.lang", type.pkgName); Assert.assertEquals("Class", type.clsName); Assert.assertEquals(0, type.arrayDepth); Assert.assertEquals(paramGeneric, type.generics); } else { Assert.fail("Unrecognized name: "+name+"; type: "+type); } } }; } @Override public void visitException(String type, Void receiver) { if ("java.lang.RuntimeException".equals(type)) { success[6] = 1; } else if ("ClassCastException".equals(type)) { success[7] = 1; } else { Assert.fail("Unrecognized exception type: "+type); } } }, null, method, 0); Assert.assertArrayEquals(success, new int[]{ Modifier.PUBLIC|Modifier.STATIC|Modifier.FINAL ,1,1,1, 1,1,1,1 }); }
|
public static <R> int visitMethodSignature (final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos) { pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } pos = visitAnnotation(visitor, receiver, chars, pos); pos = visitModifier(visitor, receiver, chars, pos); pos = visitGeneric(visitor, receiver, chars, pos); final TypeDef returnType = extractType(chars, pos); visitor.visitReturnType(returnType, receiver); int start = pos = eatWhitespace(chars, returnType.index); if (chars.charAt(pos) == '.' && chars.charAt(pos+1) == '.') { pos = eatWhitespace(chars, pos+3); returnType.arrayDepth++; } pos = eatJavaname(chars, pos); visitor.visitName(chars.subSequence(start, pos).toString(), receiver); pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == '(') { pos = eatWhitespace(chars, pos + 1); while (chars.charAt(pos) != ')') { int initial = pos; final ParameterVisitor<R> param = visitor.visitParameter(); pos = visitAnnotation(param, receiver, chars, pos); pos = visitModifier(param, receiver, chars, pos); final TypeDef def = extractType(chars, pos); start = pos = eatWhitespace(chars, def.index); boolean varargs = false; if (chars.charAt(pos) == '.') { assert chars.charAt(pos+1)=='.'; assert chars.charAt(pos+2)=='.'; def.arrayDepth ++; start = pos = eatWhitespace(chars, pos+3); pos = eatJavaname(chars, start); varargs = true; } else { pos = eatJavaname(chars, start); } param.visitType(def, chars.subSequence(start, pos).toString(), varargs, receiver); pos = eatWhitespace(chars, pos); if (chars.charAt(pos) == ',') { pos++; } if (initial == pos) { throw new IllegalArgumentException("Bad signature " + chars); } } } if (pos == chars.length()) { return pos; } pos = eatWhitespace(chars, pos+1); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == 't') { if (chars.subSequence(pos, pos+6).equals("throws")) { pos = eatWhitespace(chars, pos+7); while (pos < chars.length()) { if (chars.charAt(pos)=='{' || chars.charAt(pos) == ';') { return pos; } start = pos; pos = eatJavaname(chars, pos); visitor.visitException(chars.subSequence(start, pos).toString(), receiver); pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == ',') { pos = eatWhitespace(chars, pos+1); } } } } return eatWhitespace(chars, pos); }
|
JavaLexer { public static <R> int visitMethodSignature (final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos) { pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } pos = visitAnnotation(visitor, receiver, chars, pos); pos = visitModifier(visitor, receiver, chars, pos); pos = visitGeneric(visitor, receiver, chars, pos); final TypeDef returnType = extractType(chars, pos); visitor.visitReturnType(returnType, receiver); int start = pos = eatWhitespace(chars, returnType.index); if (chars.charAt(pos) == '.' && chars.charAt(pos+1) == '.') { pos = eatWhitespace(chars, pos+3); returnType.arrayDepth++; } pos = eatJavaname(chars, pos); visitor.visitName(chars.subSequence(start, pos).toString(), receiver); pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == '(') { pos = eatWhitespace(chars, pos + 1); while (chars.charAt(pos) != ')') { int initial = pos; final ParameterVisitor<R> param = visitor.visitParameter(); pos = visitAnnotation(param, receiver, chars, pos); pos = visitModifier(param, receiver, chars, pos); final TypeDef def = extractType(chars, pos); start = pos = eatWhitespace(chars, def.index); boolean varargs = false; if (chars.charAt(pos) == '.') { assert chars.charAt(pos+1)=='.'; assert chars.charAt(pos+2)=='.'; def.arrayDepth ++; start = pos = eatWhitespace(chars, pos+3); pos = eatJavaname(chars, start); varargs = true; } else { pos = eatJavaname(chars, start); } param.visitType(def, chars.subSequence(start, pos).toString(), varargs, receiver); pos = eatWhitespace(chars, pos); if (chars.charAt(pos) == ',') { pos++; } if (initial == pos) { throw new IllegalArgumentException("Bad signature " + chars); } } } if (pos == chars.length()) { return pos; } pos = eatWhitespace(chars, pos+1); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == 't') { if (chars.subSequence(pos, pos+6).equals("throws")) { pos = eatWhitespace(chars, pos+7); while (pos < chars.length()) { if (chars.charAt(pos)=='{' || chars.charAt(pos) == ';') { return pos; } start = pos; pos = eatJavaname(chars, pos); visitor.visitException(chars.subSequence(start, pos).toString(), receiver); pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == ',') { pos = eatWhitespace(chars, pos+1); } } } } return eatWhitespace(chars, pos); } }
|
JavaLexer { public static <R> int visitMethodSignature (final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos) { pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } pos = visitAnnotation(visitor, receiver, chars, pos); pos = visitModifier(visitor, receiver, chars, pos); pos = visitGeneric(visitor, receiver, chars, pos); final TypeDef returnType = extractType(chars, pos); visitor.visitReturnType(returnType, receiver); int start = pos = eatWhitespace(chars, returnType.index); if (chars.charAt(pos) == '.' && chars.charAt(pos+1) == '.') { pos = eatWhitespace(chars, pos+3); returnType.arrayDepth++; } pos = eatJavaname(chars, pos); visitor.visitName(chars.subSequence(start, pos).toString(), receiver); pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == '(') { pos = eatWhitespace(chars, pos + 1); while (chars.charAt(pos) != ')') { int initial = pos; final ParameterVisitor<R> param = visitor.visitParameter(); pos = visitAnnotation(param, receiver, chars, pos); pos = visitModifier(param, receiver, chars, pos); final TypeDef def = extractType(chars, pos); start = pos = eatWhitespace(chars, def.index); boolean varargs = false; if (chars.charAt(pos) == '.') { assert chars.charAt(pos+1)=='.'; assert chars.charAt(pos+2)=='.'; def.arrayDepth ++; start = pos = eatWhitespace(chars, pos+3); pos = eatJavaname(chars, start); varargs = true; } else { pos = eatJavaname(chars, start); } param.visitType(def, chars.subSequence(start, pos).toString(), varargs, receiver); pos = eatWhitespace(chars, pos); if (chars.charAt(pos) == ',') { pos++; } if (initial == pos) { throw new IllegalArgumentException("Bad signature " + chars); } } } if (pos == chars.length()) { return pos; } pos = eatWhitespace(chars, pos+1); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == 't') { if (chars.subSequence(pos, pos+6).equals("throws")) { pos = eatWhitespace(chars, pos+7); while (pos < chars.length()) { if (chars.charAt(pos)=='{' || chars.charAt(pos) == ';') { return pos; } start = pos; pos = eatJavaname(chars, pos); visitor.visitException(chars.subSequence(start, pos).toString(), receiver); pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == ',') { pos = eatWhitespace(chars, pos+1); } } } } return eatWhitespace(chars, pos); } JavaLexer(String definition); }
|
JavaLexer { public static <R> int visitMethodSignature (final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos) { pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } pos = visitAnnotation(visitor, receiver, chars, pos); pos = visitModifier(visitor, receiver, chars, pos); pos = visitGeneric(visitor, receiver, chars, pos); final TypeDef returnType = extractType(chars, pos); visitor.visitReturnType(returnType, receiver); int start = pos = eatWhitespace(chars, returnType.index); if (chars.charAt(pos) == '.' && chars.charAt(pos+1) == '.') { pos = eatWhitespace(chars, pos+3); returnType.arrayDepth++; } pos = eatJavaname(chars, pos); visitor.visitName(chars.subSequence(start, pos).toString(), receiver); pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == '(') { pos = eatWhitespace(chars, pos + 1); while (chars.charAt(pos) != ')') { int initial = pos; final ParameterVisitor<R> param = visitor.visitParameter(); pos = visitAnnotation(param, receiver, chars, pos); pos = visitModifier(param, receiver, chars, pos); final TypeDef def = extractType(chars, pos); start = pos = eatWhitespace(chars, def.index); boolean varargs = false; if (chars.charAt(pos) == '.') { assert chars.charAt(pos+1)=='.'; assert chars.charAt(pos+2)=='.'; def.arrayDepth ++; start = pos = eatWhitespace(chars, pos+3); pos = eatJavaname(chars, start); varargs = true; } else { pos = eatJavaname(chars, start); } param.visitType(def, chars.subSequence(start, pos).toString(), varargs, receiver); pos = eatWhitespace(chars, pos); if (chars.charAt(pos) == ',') { pos++; } if (initial == pos) { throw new IllegalArgumentException("Bad signature " + chars); } } } if (pos == chars.length()) { return pos; } pos = eatWhitespace(chars, pos+1); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == 't') { if (chars.subSequence(pos, pos+6).equals("throws")) { pos = eatWhitespace(chars, pos+7); while (pos < chars.length()) { if (chars.charAt(pos)=='{' || chars.charAt(pos) == ';') { return pos; } start = pos; pos = eatJavaname(chars, pos); visitor.visitException(chars.subSequence(start, pos).toString(), receiver); pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == ',') { pos = eatWhitespace(chars, pos+1); } } } } return eatWhitespace(chars, pos); } JavaLexer(String definition); static int visitJavadoc(final JavadocVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotation(final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotationMembers(final AnnotationMemberVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitModifier(final ModifierVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitGeneric(final GenericVisitor<R> visitor, final R receiver,
final CharSequence chars, int pos); static int visitMethodSignature(final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static TypeDef extractType(final CharSequence chars, int pos); static SimpleStack<IsGeneric> extractGenerics(final CharSequence chars, final int pos); String getClassName(); int getPrivacy(); int getModifier(); String getSuperClass(); String[] getGenerics(); String[] getImports(); String[] getInterfaces(); boolean isPublic(); boolean isPrivate(); boolean isProtected(); boolean isStatic(); boolean isFinal(); boolean isAbstract(); boolean isNative(); boolean isClass(); boolean isAnnotation(); boolean isEnum(); boolean hasGenerics(); static Iterable<String> findImportsInGeneric(final String generic); static IsParameter lexParam(final CharSequence chars); static int visitClassFile(final ClassVisitor<Param> extractor,
final Param receiver, final CharSequence chars, int pos); }
|
JavaLexer { public static <R> int visitMethodSignature (final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos) { pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } pos = visitAnnotation(visitor, receiver, chars, pos); pos = visitModifier(visitor, receiver, chars, pos); pos = visitGeneric(visitor, receiver, chars, pos); final TypeDef returnType = extractType(chars, pos); visitor.visitReturnType(returnType, receiver); int start = pos = eatWhitespace(chars, returnType.index); if (chars.charAt(pos) == '.' && chars.charAt(pos+1) == '.') { pos = eatWhitespace(chars, pos+3); returnType.arrayDepth++; } pos = eatJavaname(chars, pos); visitor.visitName(chars.subSequence(start, pos).toString(), receiver); pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == '(') { pos = eatWhitespace(chars, pos + 1); while (chars.charAt(pos) != ')') { int initial = pos; final ParameterVisitor<R> param = visitor.visitParameter(); pos = visitAnnotation(param, receiver, chars, pos); pos = visitModifier(param, receiver, chars, pos); final TypeDef def = extractType(chars, pos); start = pos = eatWhitespace(chars, def.index); boolean varargs = false; if (chars.charAt(pos) == '.') { assert chars.charAt(pos+1)=='.'; assert chars.charAt(pos+2)=='.'; def.arrayDepth ++; start = pos = eatWhitespace(chars, pos+3); pos = eatJavaname(chars, start); varargs = true; } else { pos = eatJavaname(chars, start); } param.visitType(def, chars.subSequence(start, pos).toString(), varargs, receiver); pos = eatWhitespace(chars, pos); if (chars.charAt(pos) == ',') { pos++; } if (initial == pos) { throw new IllegalArgumentException("Bad signature " + chars); } } } if (pos == chars.length()) { return pos; } pos = eatWhitespace(chars, pos+1); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == 't') { if (chars.subSequence(pos, pos+6).equals("throws")) { pos = eatWhitespace(chars, pos+7); while (pos < chars.length()) { if (chars.charAt(pos)=='{' || chars.charAt(pos) == ';') { return pos; } start = pos; pos = eatJavaname(chars, pos); visitor.visitException(chars.subSequence(start, pos).toString(), receiver); pos = eatWhitespace(chars, pos); if (pos == chars.length()) { return pos; } if (chars.charAt(pos) == ',') { pos = eatWhitespace(chars, pos+1); } } } } return eatWhitespace(chars, pos); } JavaLexer(String definition); static int visitJavadoc(final JavadocVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotation(final AnnotationVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitAnnotationMembers(final AnnotationMemberVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitModifier(final ModifierVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static int visitGeneric(final GenericVisitor<R> visitor, final R receiver,
final CharSequence chars, int pos); static int visitMethodSignature(final MethodVisitor<R> visitor, final R receiver, final CharSequence chars, int pos); static TypeDef extractType(final CharSequence chars, int pos); static SimpleStack<IsGeneric> extractGenerics(final CharSequence chars, final int pos); String getClassName(); int getPrivacy(); int getModifier(); String getSuperClass(); String[] getGenerics(); String[] getImports(); String[] getInterfaces(); boolean isPublic(); boolean isPrivate(); boolean isProtected(); boolean isStatic(); boolean isFinal(); boolean isAbstract(); boolean isNative(); boolean isClass(); boolean isAnnotation(); boolean isEnum(); boolean hasGenerics(); static Iterable<String> findImportsInGeneric(final String generic); static IsParameter lexParam(final CharSequence chars); static int visitClassFile(final ClassVisitor<Param> extractor,
final Param receiver, final CharSequence chars, int pos); }
|
@Test public void testDefaultLogging() throws Throwable { final String msg = "Success! " + hashCode(); borrowSout( ()-> LogInjector.DEFAULT.log(LogLevel.INFO, msg) , lines-> Assert.assertEquals("[INFO] " + msg, lines.first()) ); assertTrue("Failed", !failed); Log.defaultLogger().log(LogInjectorTest.class, "Default Logging Works!"); }
|
public Log defaultLogger() { return (level, debug) -> (level == LogLevel.ERROR ? SYS_ERR : SYS_OUT) .print(level, debug); }
|
LogInjector { public Log defaultLogger() { return (level, debug) -> (level == LogLevel.ERROR ? SYS_ERR : SYS_OUT) .print(level, debug); } }
|
LogInjector { public Log defaultLogger() { return (level, debug) -> (level == LogLevel.ERROR ? SYS_ERR : SYS_OUT) .print(level, debug); } }
|
LogInjector { public Log defaultLogger() { return (level, debug) -> (level == LogLevel.ERROR ? SYS_ERR : SYS_OUT) .print(level, debug); } Log defaultLogger(); }
|
LogInjector { public Log defaultLogger() { return (level, debug) -> (level == LogLevel.ERROR ? SYS_ERR : SYS_OUT) .print(level, debug); } Log defaultLogger(); }
|
@Test public void testAnnoNoArgs() { IsClass asClass = service.toClass(OuterTestClass.NoTargetAnno.class.getName()); IsAnnotation anno = asClass.getAnnotation(Target.class.getName()); IsAnnotationValue empty = anno.getValue(anno.getMethod("value")); Assert.assertTrue(empty.isArray()); Assert.assertEquals(0, Array.getLength(empty.getRawValue())); }
|
@Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); @Override IsClass toClass(String binaryName); @Override IsMethod toMethod(CtMethod type); @Override IsField toField(CtField type); @Override IsAnnotation toAnnotation(Annotation type); IsType[] toTypes(CtClass[] parameterTypes); static MappedIterable<Method> getMethodsInDeclaredOrder(Class<?> type); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); @Override IsClass toClass(String binaryName); @Override IsMethod toMethod(CtMethod type); @Override IsField toField(CtField type); @Override IsAnnotation toAnnotation(Annotation type); IsType[] toTypes(CtClass[] parameterTypes); static MappedIterable<Method> getMethodsInDeclaredOrder(Class<?> type); }
|
@Test public void testTestClass() { Class<?> cls = getTestClass(); IsClass asClass = service.toClass(cls.getName()); Assert.assertEquals(asClass.getPackage(), cls.getPackage().getName()); Assert.assertEquals(asClass.getEnclosedName(), X_Source.classToEnclosedSourceName(cls)); Assert.assertEquals(asClass.getModifier(), cls.getModifiers()); testAnnos(cls.getDeclaredAnnotations(), asClass); }
|
@Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); @Override IsClass toClass(String binaryName); @Override IsMethod toMethod(CtMethod type); @Override IsField toField(CtField type); @Override IsAnnotation toAnnotation(Annotation type); IsType[] toTypes(CtClass[] parameterTypes); static MappedIterable<Method> getMethodsInDeclaredOrder(Class<?> type); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); @Override IsClass toClass(String binaryName); @Override IsMethod toMethod(CtMethod type); @Override IsField toField(CtField type); @Override IsAnnotation toAnnotation(Annotation type); IsType[] toTypes(CtClass[] parameterTypes); static MappedIterable<Method> getMethodsInDeclaredOrder(Class<?> type); }
|
@Test public void testTestClass_Methods() { Class<?> cls = getTestClass(); IsClass asClass = service.toClass(cls.getName()); for (Method method : cls.getMethods()) { IsMethod imethod = asClass.getMethod(method.getName(), true, method.getParameterTypes()); String testCase = imethod.getQualifiedName() +" != "+method.getName(); Assert.assertNotNull(testCase, imethod); Assert.assertEquals(testCase, method.getName(), imethod.getName()); Assert.assertEquals(testCase, method.getModifiers(), imethod.getModifier()); Assert.assertEquals(testCase, imethod.getReturnType().getQualifiedName(), method.getReturnType().getCanonicalName()); Assert.assertTrue(testCase, BytecodeUtil.typesEqual(imethod.getParameters(), method.getParameterTypes())); Assert.assertTrue(testCase, BytecodeUtil.typesEqual(imethod.getExceptions(), method.getExceptionTypes())); testAnnos(method.getDeclaredAnnotations(), imethod); } }
|
@Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); @Override IsClass toClass(String binaryName); @Override IsMethod toMethod(CtMethod type); @Override IsField toField(CtField type); @Override IsAnnotation toAnnotation(Annotation type); IsType[] toTypes(CtClass[] parameterTypes); static MappedIterable<Method> getMethodsInDeclaredOrder(Class<?> type); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); @Override IsClass toClass(String binaryName); @Override IsMethod toMethod(CtMethod type); @Override IsField toField(CtField type); @Override IsAnnotation toAnnotation(Annotation type); IsType[] toTypes(CtClass[] parameterTypes); static MappedIterable<Method> getMethodsInDeclaredOrder(Class<?> type); }
|
@Test public void testTestClass_Fields() { Class<?> cls = getTestClass(); IsClass asClass = service.toClass(cls.getName()); for (Field field : cls.getFields()) { IsField ifield = asClass.getField(field.getName()); Assert.assertNotNull(field.getName(), ifield); Assert.assertEquals(field.getName(), ifield.getName()); Assert.assertEquals(field.getModifiers(), ifield.getModifier()); testAnnos(field.getDeclaredAnnotations(), ifield); } }
|
@Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); @Override IsClass toClass(String binaryName); @Override IsMethod toMethod(CtMethod type); @Override IsField toField(CtField type); @Override IsAnnotation toAnnotation(Annotation type); IsType[] toTypes(CtClass[] parameterTypes); static MappedIterable<Method> getMethodsInDeclaredOrder(Class<?> type); }
|
BytecodeAdapterService implements
SourceAdapterService<String, CtMethod, CtField, Annotation> { @Override public IsClass toClass(String binaryName) { int arrayCount = 0; while (binaryName.matches(".*" + X_Util.arrayRegex)) { arrayCount += 1; binaryName = binaryName.replaceFirst(X_Util.arrayRegex, ""); } IsClass cls = classes.get(binaryName); return cls.toArray(arrayCount); } BytecodeAdapterService(); BytecodeAdapterService(ClassPool pool); @Override IsClass toClass(String binaryName); @Override IsMethod toMethod(CtMethod type); @Override IsField toField(CtField type); @Override IsAnnotation toAnnotation(Annotation type); IsType[] toTypes(CtClass[] parameterTypes); static MappedIterable<Method> getMethodsInDeclaredOrder(Class<?> type); }
|
@Test public void testAllSlidesCanRender() throws IOException, ParseException { items.forAll(item->{ SlideRenderer renderer = new SlideRenderer(); final DomBuffer into = new DomBuffer() .setNewLine(true) .setTrimWhitespace(false); renderer.renderSlide(into, item.out2()); X_Log.info(X_Source.pathToLogLink(item.out1().getResourceName()), "\n", item.out2(), "\nRenders:", into, "\n\n" ); }); }
|
public void renderSlide(DomBuffer into, UiContainerExpr slide) { final DomBuffer out; if ("xapi-slide".equals(into.getTagName())) { out = into; } else { out = into.makeTag("xapi-slide"); } slide.getAttribute("id") .mapNullSafe(UiAttrExpr::getExpression) .mapNullSafe(ASTHelper::extractStringValue) .readIfPresent(out::setId); final ComposableXapiVisitor<DomBuffer> visitor = new ComposableXapiVisitor<>(); visitor .withUiContainerExpr((tag, buffer)->{ renderSlideChild(out, tag, visitor, slide); return false; }) .visit(slide.getBody(), out); }
|
SlideRenderer { public void renderSlide(DomBuffer into, UiContainerExpr slide) { final DomBuffer out; if ("xapi-slide".equals(into.getTagName())) { out = into; } else { out = into.makeTag("xapi-slide"); } slide.getAttribute("id") .mapNullSafe(UiAttrExpr::getExpression) .mapNullSafe(ASTHelper::extractStringValue) .readIfPresent(out::setId); final ComposableXapiVisitor<DomBuffer> visitor = new ComposableXapiVisitor<>(); visitor .withUiContainerExpr((tag, buffer)->{ renderSlideChild(out, tag, visitor, slide); return false; }) .visit(slide.getBody(), out); } }
|
SlideRenderer { public void renderSlide(DomBuffer into, UiContainerExpr slide) { final DomBuffer out; if ("xapi-slide".equals(into.getTagName())) { out = into; } else { out = into.makeTag("xapi-slide"); } slide.getAttribute("id") .mapNullSafe(UiAttrExpr::getExpression) .mapNullSafe(ASTHelper::extractStringValue) .readIfPresent(out::setId); final ComposableXapiVisitor<DomBuffer> visitor = new ComposableXapiVisitor<>(); visitor .withUiContainerExpr((tag, buffer)->{ renderSlideChild(out, tag, visitor, slide); return false; }) .visit(slide.getBody(), out); } }
|
SlideRenderer { public void renderSlide(DomBuffer into, UiContainerExpr slide) { final DomBuffer out; if ("xapi-slide".equals(into.getTagName())) { out = into; } else { out = into.makeTag("xapi-slide"); } slide.getAttribute("id") .mapNullSafe(UiAttrExpr::getExpression) .mapNullSafe(ASTHelper::extractStringValue) .readIfPresent(out::setId); final ComposableXapiVisitor<DomBuffer> visitor = new ComposableXapiVisitor<>(); visitor .withUiContainerExpr((tag, buffer)->{ renderSlideChild(out, tag, visitor, slide); return false; }) .visit(slide.getBody(), out); } void renderSlide(DomBuffer into, UiContainerExpr slide); }
|
SlideRenderer { public void renderSlide(DomBuffer into, UiContainerExpr slide) { final DomBuffer out; if ("xapi-slide".equals(into.getTagName())) { out = into; } else { out = into.makeTag("xapi-slide"); } slide.getAttribute("id") .mapNullSafe(UiAttrExpr::getExpression) .mapNullSafe(ASTHelper::extractStringValue) .readIfPresent(out::setId); final ComposableXapiVisitor<DomBuffer> visitor = new ComposableXapiVisitor<>(); visitor .withUiContainerExpr((tag, buffer)->{ renderSlideChild(out, tag, visitor, slide); return false; }) .visit(slide.getBody(), out); } void renderSlide(DomBuffer into, UiContainerExpr slide); }
|
@Test public void testInsertAtEdges() { int cnt = 0; RangePool<Integer> pool = new RangePool<>(); assertPoolStructure(pool, new Coord[]{coord(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)} ); pool.insert(coord(-2, 2), cnt++); assertPoolStructure(pool, new Coord[]{coord(Double.NEGATIVE_INFINITY, -2), coord(2, Double.POSITIVE_INFINITY)}, coord(-2, 2) ); pool.insert(coord(2, 4), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -2), coord(4, Double.POSITIVE_INFINITY) }, coord(-2, 2), coord(2, 4) ); pool.insert(coord(-4, -2), cnt++); assertPoolStructure(pool, new Coord[]{coord(Double.NEGATIVE_INFINITY, -4), coord(4, Double.POSITIVE_INFINITY)}, coord(-4, -2), coord(-2, 2), coord(2, 4) ); pool = new RangePool<>(); assertPoolStructure(pool, new Coord[]{coord(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)} ); pool.insert(coord(-2, 2), cnt++); assertPoolStructure(pool, new Coord[]{coord(Double.NEGATIVE_INFINITY, -2), coord(2, Double.POSITIVE_INFINITY)}, coord(-2, 2) ); pool.insert(coord(-4, -2), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -4), coord(2, Double.POSITIVE_INFINITY) }, coord(-4, -2), coord(-2, 2) ); pool.insert(coord(2, 4), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -4), coord(4, Double.POSITIVE_INFINITY) }, coord(-4, -2), coord(-2, 2), coord(2, 4) ); }
|
public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } RangePool(); }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } RangePool(); boolean insert(Coord coord, T value); Maybe<Coord> reserveSpace(Coord point, T value); boolean isValid(); MappedIterable<UnreservedNode<T>> forUnreservedAsc(); MappedIterable<UnreservedNode<T>> forUnreservedDesc(); MappedIterable<ReservedNode<T>> forReservedAsc(); MappedIterable<ReservedNode<T>> forReservedDesc(); }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } RangePool(); boolean insert(Coord coord, T value); Maybe<Coord> reserveSpace(Coord point, T value); boolean isValid(); MappedIterable<UnreservedNode<T>> forUnreservedAsc(); MappedIterable<UnreservedNode<T>> forUnreservedDesc(); MappedIterable<ReservedNode<T>> forReservedAsc(); MappedIterable<ReservedNode<T>> forReservedDesc(); }
|
@Test public void testInsertAtContainedEdges() { int cnt = 0; RangePool<Integer> pool = new RangePool<>(); assertPoolStructure(pool, new Coord[]{coord(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)} ); pool.insert(coord(8, 16), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, 8), coord(16, Double.POSITIVE_INFINITY) }, coord(8, 16) ); pool.insert(coord(-16, -8), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -16), coord(-8, 8), coord(16, Double.POSITIVE_INFINITY) }, coord(-16, -8), coord(8, 16) ); pool.insert(coord(-1, 1), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -16), coord(-8, -1), coord(1, 8), coord(16, Double.POSITIVE_INFINITY) }, coord(-16, -8), coord(-1, 1), coord(8, 16) ); pool.insert(coord(-2, -1), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -16), coord(-8, -2), coord(1, 8), coord(16, Double.POSITIVE_INFINITY) }, coord(-16, -8), coord(-2, -1), coord(-1, 1), coord(8, 16) ); pool.insert(coord(1, 2), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -16), coord(-8, -2), coord(2, 8), coord(16, Double.POSITIVE_INFINITY) }, coord(-16, -8), coord(-2, -1), coord(-1, 1), coord(1, 2), coord(8, 16) ); pool.insert(coord(-8, -2), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -16), coord(2, 8), coord(16, Double.POSITIVE_INFINITY) }, coord(-16, -8), coord(-8, -2), coord(-2, -1), coord(-1, 1), coord(1, 2), coord(8, 16) ); pool.insert(coord(2, 8), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -16), coord(16, Double.POSITIVE_INFINITY) }, coord(-16, -8), coord(-8, -2), coord(-2, -1), coord(-1, 1), coord(1, 2), coord(2, 8), coord(8, 16) ); }
|
public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } RangePool(); }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } RangePool(); boolean insert(Coord coord, T value); Maybe<Coord> reserveSpace(Coord point, T value); boolean isValid(); MappedIterable<UnreservedNode<T>> forUnreservedAsc(); MappedIterable<UnreservedNode<T>> forUnreservedDesc(); MappedIterable<ReservedNode<T>> forReservedAsc(); MappedIterable<ReservedNode<T>> forReservedDesc(); }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } RangePool(); boolean insert(Coord coord, T value); Maybe<Coord> reserveSpace(Coord point, T value); boolean isValid(); MappedIterable<UnreservedNode<T>> forUnreservedAsc(); MappedIterable<UnreservedNode<T>> forUnreservedDesc(); MappedIterable<ReservedNode<T>> forReservedAsc(); MappedIterable<ReservedNode<T>> forReservedDesc(); }
|
@Test public void testRangeSplit() { int cnt = 0; RangePool<Integer> pool = new RangePool<>(); assertPoolStructure(pool, new Coord[]{coord(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)} ); pool.insert(coord(8, 16), cnt++); assertPoolStructure(pool, new Coord[]{coord(Double.NEGATIVE_INFINITY, 8), coord(16, Double.POSITIVE_INFINITY)}, coord(8, 16) ); pool.insert(coord(-16, -8), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -16), coord(-8, 8), coord(16, Double.POSITIVE_INFINITY) }, coord(-16, -8), coord(8, 16) ); pool.insert(coord(-2, 2), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -16), coord(-8, -2), coord(2, 8), coord(16, Double.POSITIVE_INFINITY) }, coord(-16, -8), coord(-2, 2), coord(8, 16) ); pool = new RangePool<>(); assertPoolStructure(pool, new Coord[]{coord(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)} ); pool.insert(coord(-16, -8), cnt++); assertPoolStructure(pool, new Coord[]{coord(Double.NEGATIVE_INFINITY, -16), coord(-8, Double.POSITIVE_INFINITY)}, coord(-16, -8) ); pool.insert(coord(8, 16), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -16), coord(-8, 8), coord(16, Double.POSITIVE_INFINITY) }, coord(-16, -8), coord(8, 16) ); pool.insert(coord(-2, 2), cnt++); assertPoolStructure(pool, new Coord[]{ coord(Double.NEGATIVE_INFINITY, -16), coord(-8, -2), coord(2, 8), coord(16, Double.POSITIVE_INFINITY) }, coord(-16, -8), coord(-2, 2), coord(8, 16) ); }
|
public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } RangePool(); }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } RangePool(); boolean insert(Coord coord, T value); Maybe<Coord> reserveSpace(Coord point, T value); boolean isValid(); MappedIterable<UnreservedNode<T>> forUnreservedAsc(); MappedIterable<UnreservedNode<T>> forUnreservedDesc(); MappedIterable<ReservedNode<T>> forReservedAsc(); MappedIterable<ReservedNode<T>> forReservedDesc(); }
|
RangePool { public boolean insert(Coord coord, T value) { ReservedNode<T> newNode = new ReservedNode<>(coord, value); if (highest.getRange().contains(coord)) { if (highest.getRange().getX() == coord.getX()) { highest.attachBelow(newNode); } else { final UnreservedNode<T> newSpace = highest.split(newNode, RangeDirection.Higher); if (lowest == highest) { lowest = newSpace; } } return true; } else if (lowest.getRange().contains(coord)) { if (lowest.getRange().getY() == coord.getY()) { lowest.attachAbove(newNode); } else { final UnreservedNode<T> newSpace = lowest.split(newNode, RangeDirection.Lower); if (lowest == highest) { highest = newSpace; } } return true; } else { double toHighest = highest.getRange().getX() - coord.getY(); double toLowest = coord.getX() - lowest.getRange().getY(); final UnreservedNode<T> searchFrom; if (toHighest > toLowest) { searchFrom = lowest; } else { searchFrom = highest; } Maybe<UnreservedNode<T>> into = searchFrom.findUnreserved(coord); if (into.isPresent()) { final UnreservedNode<T> space = into.get(); final Coord unreserved = space.getRange(); if (unreserved.contains(coord)) { if (unreserved.equals(coord)) { space.replaceWith(newNode); } else if (unreserved.getY() == coord.getY()) { space.attachAbove(newNode); } else if (unreserved.getX() == coord.getX()) { space.attachBelow(newNode); } else { space.split(newNode, RangeDirection.Higher); } return true; } else { } } } return false; } RangePool(); boolean insert(Coord coord, T value); Maybe<Coord> reserveSpace(Coord point, T value); boolean isValid(); MappedIterable<UnreservedNode<T>> forUnreservedAsc(); MappedIterable<UnreservedNode<T>> forUnreservedDesc(); MappedIterable<ReservedNode<T>> forReservedAsc(); MappedIterable<ReservedNode<T>> forReservedDesc(); }
|
@Test public void testUserToStringWrapped() { UserInterface<User> ui = X_AutoUi.makeUi(MODEL, UserViewWrapped.class, ToStringUserInterface.class); Assert.assertEquals("email: email,\nname: name,\nid: id,\n", ui.toString()); }
|
@Override public String toString() { return b.toString(); }
|
ToStringUserInterface extends AbstractUserInterface implements Appendable { @Override public String toString() { return b.toString(); } }
|
ToStringUserInterface extends AbstractUserInterface implements Appendable { @Override public String toString() { return b.toString(); } }
|
ToStringUserInterface extends AbstractUserInterface implements Appendable { @Override public String toString() { return b.toString(); } @Override int hashCode(); @Override String toString(); @Override boolean equals(Object obj); @Override Appendable append(CharSequence csq); @Override Appendable append(CharSequence csq, int start, int end); @Override Appendable append(char c); }
|
ToStringUserInterface extends AbstractUserInterface implements Appendable { @Override public String toString() { return b.toString(); } @Override int hashCode(); @Override String toString(); @Override boolean equals(Object obj); @Override Appendable append(CharSequence csq); @Override Appendable append(CharSequence csq, int start, int end); @Override Appendable append(char c); }
|
@Test public void getBytes() throws Exception { Assert.assertEquals(mString, new String(mCacheUtils1.getBytes("bytes1"))); Assert.assertEquals(mString, new String(mCacheUtils1.getBytes("bytes1", null))); Assert.assertNull(mCacheUtils1.getBytes("bytes2", null)); Assert.assertEquals(mString, new String(mCacheUtils2.getBytes("bytes2"))); Assert.assertEquals(mString, new String(mCacheUtils2.getBytes("bytes2", null))); Assert.assertNull(mCacheUtils2.getBytes("bytes1", null)); }
|
public byte[] getBytes(@NonNull String key) { return getBytes(key, null); }
|
CacheUtils { public byte[] getBytes(@NonNull String key) { return getBytes(key, null); } }
|
CacheUtils { public byte[] getBytes(@NonNull String key) { return getBytes(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public byte[] getBytes(@NonNull String key) { return getBytes(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public byte[] getBytes(@NonNull String key) { return getBytes(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void getString() throws Exception { Assert.assertEquals(mString, mCacheUtils1.getString("string1")); Assert.assertEquals(mString, mCacheUtils1.getString("string1", null)); Assert.assertNull(mCacheUtils1.getString("string2", null)); Assert.assertEquals(mString, mCacheUtils2.getString("string2")); Assert.assertEquals(mString, mCacheUtils2.getString("string2", null)); Assert.assertNull(mCacheUtils2.getString("string1", null)); }
|
public String getString(@NonNull String key) { return getString(key, null); }
|
CacheUtils { public String getString(@NonNull String key) { return getString(key, null); } }
|
CacheUtils { public String getString(@NonNull String key) { return getString(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public String getString(@NonNull String key) { return getString(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public String getString(@NonNull String key) { return getString(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void getJSONObject() throws Exception { Assert.assertEquals(mJSONObject.toString(), mCacheUtils1.getJSONObject("jsonObject1").toString()); Assert.assertEquals(mJSONObject.toString(), mCacheUtils1.getJSONObject("jsonObject1", null).toString()); Assert.assertNull(mCacheUtils1.getJSONObject("jsonObject2", null)); Assert.assertEquals(mJSONObject.toString(), mCacheUtils2.getJSONObject("jsonObject2").toString()); Assert.assertEquals(mJSONObject.toString(), mCacheUtils2.getJSONObject("jsonObject2", null).toString()); Assert.assertNull(mCacheUtils2.getJSONObject("jsonObject1", null)); }
|
public JSONObject getJSONObject(@NonNull String key) { return getJSONObject(key, null); }
|
CacheUtils { public JSONObject getJSONObject(@NonNull String key) { return getJSONObject(key, null); } }
|
CacheUtils { public JSONObject getJSONObject(@NonNull String key) { return getJSONObject(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public JSONObject getJSONObject(@NonNull String key) { return getJSONObject(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public JSONObject getJSONObject(@NonNull String key) { return getJSONObject(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void getJSONArray() throws Exception { Assert.assertEquals(mJSONArray.toString(), mCacheUtils1.getJSONArray("jsonArray1").toString()); Assert.assertEquals(mJSONArray.toString(), mCacheUtils1.getJSONArray("jsonArray1", null).toString()); Assert.assertNull(mCacheUtils1.getJSONArray("jsonArray2", null)); Assert.assertEquals(mJSONArray.toString(), mCacheUtils2.getJSONArray("jsonArray2").toString()); Assert.assertEquals(mJSONArray.toString(), mCacheUtils2.getJSONArray("jsonArray2", null).toString()); Assert.assertNull(mCacheUtils2.getJSONArray("jsonArray1", null)); }
|
public JSONArray getJSONArray(@NonNull String key) { return getJSONArray(key, null); }
|
CacheUtils { public JSONArray getJSONArray(@NonNull String key) { return getJSONArray(key, null); } }
|
CacheUtils { public JSONArray getJSONArray(@NonNull String key) { return getJSONArray(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public JSONArray getJSONArray(@NonNull String key) { return getJSONArray(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public JSONArray getJSONArray(@NonNull String key) { return getJSONArray(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void getBitmap() throws Exception { Assert.assertTrue(mCacheUtils1.getString("bitmap1").equals("Bitmap (100 x 100) compressed as PNG with quality 100")); Assert.assertTrue(mCacheUtils1.getString("bitmap1", null).equals("Bitmap (100 x 100) compressed as PNG with quality 100")); Assert.assertNull(mCacheUtils1.getString("bitmap2", null)); Assert.assertTrue(mCacheUtils2.getString("bitmap2").equals("Bitmap (100 x 100) compressed as PNG with quality 100")); Assert.assertTrue(mCacheUtils2.getString("bitmap2", null).equals("Bitmap (100 x 100) compressed as PNG with quality 100")); Assert.assertNull(mCacheUtils2.getString("bitmap1", null)); }
|
public Bitmap getBitmap(@NonNull String key) { return getBitmap(key, null); }
|
CacheUtils { public Bitmap getBitmap(@NonNull String key) { return getBitmap(key, null); } }
|
CacheUtils { public Bitmap getBitmap(@NonNull String key) { return getBitmap(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public Bitmap getBitmap(@NonNull String key) { return getBitmap(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public Bitmap getBitmap(@NonNull String key) { return getBitmap(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void getDrawable() throws Exception { Assert.assertTrue(mCacheUtils1.getString("drawable1").equals("Bitmap (100 x 100) compressed as PNG with quality 100")); Assert.assertTrue(mCacheUtils1.getString("drawable1", null).equals("Bitmap (100 x 100) compressed as PNG with quality 100")); Assert.assertNull(mCacheUtils1.getString("drawable2", null)); Assert.assertTrue(mCacheUtils2.getString("drawable2").equals("Bitmap (100 x 100) compressed as PNG with quality 100")); Assert.assertTrue(mCacheUtils2.getString("drawable2", null).equals("Bitmap (100 x 100) compressed as PNG with quality 100")); Assert.assertNull(mCacheUtils2.getString("drawable1", null)); }
|
public Drawable getDrawable(@NonNull String key) { return getDrawable(key, null); }
|
CacheUtils { public Drawable getDrawable(@NonNull String key) { return getDrawable(key, null); } }
|
CacheUtils { public Drawable getDrawable(@NonNull String key) { return getDrawable(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public Drawable getDrawable(@NonNull String key) { return getDrawable(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public Drawable getDrawable(@NonNull String key) { return getDrawable(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void getParcel() throws Exception { Assert.assertTrue(mCacheUtils1.getParcelable("parcelable1", ParcelableTest.CREATOR).equals(mParcelableTest)); Assert.assertTrue(mCacheUtils1.getParcelable("parcelable1", ParcelableTest.CREATOR, null).equals(mParcelableTest)); Assert.assertNull(mCacheUtils1.getParcelable("parcelable2", ParcelableTest.CREATOR, null)); Assert.assertTrue(mCacheUtils2.getParcelable("parcelable2", ParcelableTest.CREATOR).equals(mParcelableTest)); Assert.assertTrue(mCacheUtils2.getParcelable("parcelable2", ParcelableTest.CREATOR, null).equals(mParcelableTest)); Assert.assertNull(mCacheUtils2.getParcelable("parcelable1", ParcelableTest.CREATOR, null)); }
|
public <T> T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator) { return getParcelable(key, creator, null); }
|
CacheUtils { public <T> T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator) { return getParcelable(key, creator, null); } }
|
CacheUtils { public <T> T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator) { return getParcelable(key, creator, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public <T> T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator) { return getParcelable(key, creator, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public <T> T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator) { return getParcelable(key, creator, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void getSerializable() throws Exception { Assert.assertTrue(mCacheUtils1.getSerializable("serializable1").equals(mSerializableTest)); Assert.assertTrue(mCacheUtils1.getSerializable("serializable1", null).equals(mSerializableTest)); Assert.assertNull(mCacheUtils1.getSerializable("parcelable2", null)); Assert.assertTrue(mCacheUtils2.getSerializable("serializable2").equals(mSerializableTest)); Assert.assertTrue(mCacheUtils2.getSerializable("serializable2", null).equals(mSerializableTest)); Assert.assertNull(mCacheUtils2.getSerializable("parcelable1", null)); }
|
public Object getSerializable(@NonNull String key) { return getSerializable(key, null); }
|
CacheUtils { public Object getSerializable(@NonNull String key) { return getSerializable(key, null); } }
|
CacheUtils { public Object getSerializable(@NonNull String key) { return getSerializable(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public Object getSerializable(@NonNull String key) { return getSerializable(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public Object getSerializable(@NonNull String key) { return getSerializable(key, null); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void getCacheSize() throws Exception { Assert.assertEquals(FileUtils.getDirLength(file1), mCacheUtils1.getCacheSize()); Assert.assertEquals(FileUtils.getDirLength(file2), mCacheUtils2.getCacheSize()); }
|
public long getCacheSize() { return mCacheManager.getCacheSize(); }
|
CacheUtils { public long getCacheSize() { return mCacheManager.getCacheSize(); } }
|
CacheUtils { public long getCacheSize() { return mCacheManager.getCacheSize(); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public long getCacheSize() { return mCacheManager.getCacheSize(); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public long getCacheSize() { return mCacheManager.getCacheSize(); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void getCacheCount() throws Exception { Assert.assertEquals(8, mCacheUtils1.getCacheCount()); Assert.assertEquals(8, mCacheUtils2.getCacheCount()); }
|
public int getCacheCount() { return mCacheManager.getCacheCount(); }
|
CacheUtils { public int getCacheCount() { return mCacheManager.getCacheCount(); } }
|
CacheUtils { public int getCacheCount() { return mCacheManager.getCacheCount(); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public int getCacheCount() { return mCacheManager.getCacheCount(); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public int getCacheCount() { return mCacheManager.getCacheCount(); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void remove() throws Exception { Assert.assertNotNull(mCacheUtils1.getString("string1")); mCacheUtils1.remove("string1"); Assert.assertNull(mCacheUtils1.getString("string1")); Assert.assertNotNull(mCacheUtils2.getString("string2")); mCacheUtils2.remove("string2"); Assert.assertNull(mCacheUtils2.getString("string2")); }
|
public boolean remove(@NonNull String key) { return mCacheManager.removeByKey(key); }
|
CacheUtils { public boolean remove(@NonNull String key) { return mCacheManager.removeByKey(key); } }
|
CacheUtils { public boolean remove(@NonNull String key) { return mCacheManager.removeByKey(key); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public boolean remove(@NonNull String key) { return mCacheManager.removeByKey(key); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public boolean remove(@NonNull String key) { return mCacheManager.removeByKey(key); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void clear() throws Exception { Assert.assertNotNull(mCacheUtils1.getBytes("bytes1")); Assert.assertNotNull(mCacheUtils1.getString("string1")); Assert.assertNotNull(mCacheUtils1.getJSONObject("jsonObject1")); Assert.assertNotNull(mCacheUtils1.getJSONArray("jsonArray1")); Assert.assertNotNull(mCacheUtils1.getString("bitmap1")); Assert.assertNotNull(mCacheUtils1.getString("drawable1")); Assert.assertNotNull(mCacheUtils1.getParcelable("parcelable1", ParcelableTest.CREATOR)); Assert.assertNotNull(mCacheUtils1.getSerializable("serializable1")); mCacheUtils1.clear(); Assert.assertNull(mCacheUtils1.getBytes("bytes1")); Assert.assertNull(mCacheUtils1.getString("string1")); Assert.assertNull(mCacheUtils1.getJSONObject("jsonObject1")); Assert.assertNull(mCacheUtils1.getJSONArray("jsonArray1")); Assert.assertNull(mCacheUtils1.getString("bitmap1")); Assert.assertNull(mCacheUtils1.getString("drawable1")); Assert.assertNull(mCacheUtils1.getParcelable("parcelable1", ParcelableTest.CREATOR)); Assert.assertNull(mCacheUtils1.getSerializable("serializable1")); Assert.assertNotNull(mCacheUtils2.getBytes("bytes2")); Assert.assertNotNull(mCacheUtils2.getString("string2")); Assert.assertNotNull(mCacheUtils2.getJSONObject("jsonObject2")); Assert.assertNotNull(mCacheUtils2.getJSONArray("jsonArray2")); Assert.assertNotNull(mCacheUtils2.getString("bitmap2")); Assert.assertNotNull(mCacheUtils2.getString("drawable2")); Assert.assertNotNull(mCacheUtils2.getParcelable("parcelable2", ParcelableTest.CREATOR)); Assert.assertNotNull(mCacheUtils2.getSerializable("serializable2")); mCacheUtils2.clear(); Assert.assertNull(mCacheUtils2.getBytes("bytes2")); Assert.assertNull(mCacheUtils2.getString("string2")); Assert.assertNull(mCacheUtils2.getJSONObject("jsonObject2")); Assert.assertNull(mCacheUtils2.getJSONArray("jsonArray2")); Assert.assertNull(mCacheUtils2.getString("bitmap2")); Assert.assertNull(mCacheUtils2.getString("drawable2")); Assert.assertNull(mCacheUtils2.getParcelable("parcelable2", ParcelableTest.CREATOR)); Assert.assertNull(mCacheUtils2.getSerializable("serializable2")); }
|
public boolean clear() { return mCacheManager.clear(); }
|
CacheUtils { public boolean clear() { return mCacheManager.clear(); } }
|
CacheUtils { public boolean clear() { return mCacheManager.clear(); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); }
|
CacheUtils { public boolean clear() { return mCacheManager.clear(); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); }
|
CacheUtils { public boolean clear() { return mCacheManager.clear(); } private CacheUtils(@NonNull File cacheDir, long maxSize, int maxCount); static CacheUtils getInstance(); static CacheUtils getInstance(String cacheName); static CacheUtils getInstance(long maxSize, int maxCount); static CacheUtils getInstance(String cacheName, long maxSize, int maxCount); static CacheUtils getInstance(@NonNull File cacheDir); static CacheUtils getInstance(@NonNull File cacheDir, long maxSize, int maxCount); void put(@NonNull String key, @NonNull byte[] value); void put(@NonNull String key, @NonNull byte[] value, int saveTime); byte[] getBytes(@NonNull String key); byte[] getBytes(@NonNull String key, byte[] defaultValue); void put(@NonNull String key, @NonNull String value); void put(@NonNull String key, @NonNull String value, int saveTime); String getString(@NonNull String key); String getString(@NonNull String key, String defaultValue); void put(@NonNull String key, @NonNull JSONObject value); void put(@NonNull String key, @NonNull JSONObject value, int saveTime); JSONObject getJSONObject(@NonNull String key); JSONObject getJSONObject(@NonNull String key, JSONObject defaultValue); void put(@NonNull String key, @NonNull JSONArray value); void put(@NonNull String key, @NonNull JSONArray value, int saveTime); JSONArray getJSONArray(@NonNull String key); JSONArray getJSONArray(@NonNull String key, JSONArray defaultValue); void put(@NonNull String key, @NonNull Bitmap value); void put(@NonNull String key, @NonNull Bitmap value, int saveTime); Bitmap getBitmap(@NonNull String key); Bitmap getBitmap(@NonNull String key, Bitmap defaultValue); void put(@NonNull String key, @NonNull Drawable value); void put(@NonNull String key, @NonNull Drawable value, int saveTime); Drawable getDrawable(@NonNull String key); Drawable getDrawable(@NonNull String key, Drawable defaultValue); void put(@NonNull String key, @NonNull Parcelable value); void put(@NonNull String key, @NonNull Parcelable value, int saveTime); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator); T getParcelable(@NonNull String key, @NonNull Parcelable.Creator<T> creator, T defaultValue); void put(@NonNull String key, @NonNull Serializable value); void put(@NonNull String key, @NonNull Serializable value, int saveTime); Object getSerializable(@NonNull String key); Object getSerializable(@NonNull String key, Object defaultValue); long getCacheSize(); int getCacheCount(); boolean remove(@NonNull String key); boolean clear(); static final int SEC; static final int MIN; static final int HOUR; static final int DAY; }
|
@Test public void getString() throws Exception { Assert.assertEquals("stringVal1", spUtils1.getString("stringKey1")); Assert.assertEquals("stringVal", spUtils1.getString("stringKey", "stringVal")); Assert.assertEquals("", spUtils1.getString("stringKey")); Assert.assertEquals("stringVal2", spUtils2.getString("stringKey2")); Assert.assertEquals("stringVal", spUtils2.getString("stringKey", "stringVal")); Assert.assertEquals("", spUtils2.getString("stringKey")); }
|
public String getString(@NonNull String key) { return getString(key, ""); }
|
SPUtils { public String getString(@NonNull String key) { return getString(key, ""); } }
|
SPUtils { public String getString(@NonNull String key) { return getString(key, ""); } private SPUtils(String spName); }
|
SPUtils { public String getString(@NonNull String key) { return getString(key, ""); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
SPUtils { public String getString(@NonNull String key) { return getString(key, ""); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
@Test public void getInt() throws Exception { Assert.assertEquals(1, spUtils1.getInt("intKey1")); Assert.assertEquals(2048, spUtils1.getInt("intKey", 2048)); Assert.assertEquals(-1, spUtils1.getInt("intKey")); Assert.assertEquals(2, spUtils2.getInt("intKey2")); Assert.assertEquals(2048, spUtils2.getInt("intKey", 2048)); Assert.assertEquals(-1, spUtils2.getInt("intKey")); }
|
public int getInt(@NonNull String key) { return getInt(key, -1); }
|
SPUtils { public int getInt(@NonNull String key) { return getInt(key, -1); } }
|
SPUtils { public int getInt(@NonNull String key) { return getInt(key, -1); } private SPUtils(String spName); }
|
SPUtils { public int getInt(@NonNull String key) { return getInt(key, -1); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
SPUtils { public int getInt(@NonNull String key) { return getInt(key, -1); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
@Test public void getLong() throws Exception { Assert.assertEquals(1L, spUtils1.getLong("longKey1")); Assert.assertEquals(2048L, spUtils1.getLong("longKey", 2048)); Assert.assertEquals(-1L, spUtils1.getLong("longKey")); Assert.assertEquals(2L, spUtils2.getLong("longKey2")); Assert.assertEquals(2048L, spUtils2.getLong("longKey", 2048)); Assert.assertEquals(-1L, spUtils2.getLong("longKey")); }
|
public long getLong(@NonNull String key) { return getLong(key, -1L); }
|
SPUtils { public long getLong(@NonNull String key) { return getLong(key, -1L); } }
|
SPUtils { public long getLong(@NonNull String key) { return getLong(key, -1L); } private SPUtils(String spName); }
|
SPUtils { public long getLong(@NonNull String key) { return getLong(key, -1L); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
SPUtils { public long getLong(@NonNull String key) { return getLong(key, -1L); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
@Test public void getFloat() throws Exception { Assert.assertEquals(1f, spUtils1.getFloat("floatKey1"), 0f); Assert.assertEquals(2048f, spUtils1.getFloat("floatKey", 2048f), 0f); Assert.assertEquals(-1f, spUtils1.getFloat("floatKey"), 0f); Assert.assertEquals(2f, spUtils2.getFloat("floatKey2"), 0f); Assert.assertEquals(2048f, spUtils2.getFloat("floatKey", 2048f), 0f); Assert.assertEquals(-1f, spUtils2.getFloat("floatKey"), 0f); }
|
public float getFloat(@NonNull String key) { return getFloat(key, -1f); }
|
SPUtils { public float getFloat(@NonNull String key) { return getFloat(key, -1f); } }
|
SPUtils { public float getFloat(@NonNull String key) { return getFloat(key, -1f); } private SPUtils(String spName); }
|
SPUtils { public float getFloat(@NonNull String key) { return getFloat(key, -1f); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
SPUtils { public float getFloat(@NonNull String key) { return getFloat(key, -1f); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
@Test public void getBoolean() throws Exception { Assert.assertTrue(spUtils1.getBoolean("booleanKey1")); Assert.assertTrue(spUtils1.getBoolean("booleanKey", true)); Assert.assertFalse(spUtils1.getBoolean("booleanKey")); Assert.assertTrue(spUtils2.getBoolean("booleanKey2")); Assert.assertTrue(spUtils2.getBoolean("booleanKey", true)); Assert.assertFalse(spUtils2.getBoolean("booleanKey")); }
|
public boolean getBoolean(@NonNull String key) { return getBoolean(key, false); }
|
SPUtils { public boolean getBoolean(@NonNull String key) { return getBoolean(key, false); } }
|
SPUtils { public boolean getBoolean(@NonNull String key) { return getBoolean(key, false); } private SPUtils(String spName); }
|
SPUtils { public boolean getBoolean(@NonNull String key) { return getBoolean(key, false); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
SPUtils { public boolean getBoolean(@NonNull String key) { return getBoolean(key, false); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
@Test public void getAll() throws Exception { Map<String, ?> map; System.out.println("sp1 {"); map = spUtils1.getAll(); for (Map.Entry<String, ?> entry : map.entrySet()) { System.out.println(" " + entry.getKey() + ": " + entry.getValue()); } System.out.println("}"); System.out.println("sp2 {"); map = spUtils2.getAll(); for (Map.Entry<String, ?> entry : map.entrySet()) { System.out.println(" " + entry.getKey() + ": " + entry.getValue()); } System.out.println("}"); }
|
public Map<String, ?> getAll() { return sp.getAll(); }
|
SPUtils { public Map<String, ?> getAll() { return sp.getAll(); } }
|
SPUtils { public Map<String, ?> getAll() { return sp.getAll(); } private SPUtils(String spName); }
|
SPUtils { public Map<String, ?> getAll() { return sp.getAll(); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
SPUtils { public Map<String, ?> getAll() { return sp.getAll(); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
@Test public void testRemove() throws Exception { Assert.assertEquals("stringVal1", spUtils1.getString("stringKey1")); spUtils1.remove("stringKey1"); Assert.assertEquals("", spUtils1.getString("stringKey1")); Assert.assertEquals("stringVal2", spUtils2.getString("stringKey2")); spUtils2.remove("stringKey2"); Assert.assertEquals("", spUtils2.getString("stringKey2")); }
|
public void remove(@NonNull String key) { sp.edit().remove(key).apply(); }
|
SPUtils { public void remove(@NonNull String key) { sp.edit().remove(key).apply(); } }
|
SPUtils { public void remove(@NonNull String key) { sp.edit().remove(key).apply(); } private SPUtils(String spName); }
|
SPUtils { public void remove(@NonNull String key) { sp.edit().remove(key).apply(); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
SPUtils { public void remove(@NonNull String key) { sp.edit().remove(key).apply(); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
@Test public void testContains() throws Exception { Assert.assertTrue(spUtils1.contains("stringKey1")); Assert.assertFalse(spUtils1.contains("stringKey")); Assert.assertTrue(spUtils2.contains("stringKey2")); Assert.assertFalse(spUtils2.contains("stringKey")); }
|
public boolean contains(@NonNull String key) { return sp.contains(key); }
|
SPUtils { public boolean contains(@NonNull String key) { return sp.contains(key); } }
|
SPUtils { public boolean contains(@NonNull String key) { return sp.contains(key); } private SPUtils(String spName); }
|
SPUtils { public boolean contains(@NonNull String key) { return sp.contains(key); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
SPUtils { public boolean contains(@NonNull String key) { return sp.contains(key); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
@Test public void clear() throws Exception { spUtils1.clear(); Assert.assertEquals("", spUtils1.getString("stringKey1")); Assert.assertEquals(-1, spUtils1.getInt("intKey1")); Assert.assertEquals(-1L, spUtils1.getLong("longKey1")); Assert.assertEquals(-1f, spUtils1.getFloat("floatKey1"), 0f); Assert.assertFalse(spUtils1.getBoolean("booleanKey1")); spUtils2.clear(); Assert.assertEquals("", spUtils2.getString("stringKey2")); Assert.assertEquals(-1, spUtils2.getInt("intKey2")); Assert.assertEquals(-1L, spUtils2.getLong("longKey1")); Assert.assertEquals(-1f, spUtils2.getFloat("floatKey1"), 0f); Assert.assertFalse(spUtils2.getBoolean("booleanKey1")); }
|
public void clear() { sp.edit().clear().apply(); }
|
SPUtils { public void clear() { sp.edit().clear().apply(); } }
|
SPUtils { public void clear() { sp.edit().clear().apply(); } private SPUtils(String spName); }
|
SPUtils { public void clear() { sp.edit().clear().apply(); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
SPUtils { public void clear() { sp.edit().clear().apply(); } private SPUtils(String spName); static SPUtils getInstance(); static SPUtils getInstance(String spName); void put(@NonNull String key, @NonNull String value); String getString(@NonNull String key); String getString(@NonNull String key, @NonNull String defaultValue); void put(@NonNull String key, int value); int getInt(@NonNull String key); int getInt(@NonNull String key, int defaultValue); void put(@NonNull String key, long value); long getLong(@NonNull String key); long getLong(@NonNull String key, long defaultValue); void put(@NonNull String key, float value); float getFloat(@NonNull String key); float getFloat(@NonNull String key, float defaultValue); void put(@NonNull String key, boolean value); boolean getBoolean(@NonNull String key); boolean getBoolean(@NonNull String key, boolean defaultValue); void put(@NonNull String key, @NonNull Set<String> values); Set<String> getStringSet(@NonNull String key); Set<String> getStringSet(@NonNull String key, @NonNull Set<String> defaultValue); Map<String, ?> getAll(); boolean contains(@NonNull String key); void remove(@NonNull String key); void clear(); }
|
@Test public void proxySettingsObtainedInOrder() { Properties properties = givenDefaultProperties(); environmentVariables.set("HTTP_PROXY", "http: ProxyConfig proxyConfig = new ProxyConfig(new DefaultPropertyLoader(properties)); assertThat(proxyConfig.getProxyHost(), is("proxyhost3")); System.setProperty("http.proxyHost", "proxyhost2"); proxyConfig = new ProxyConfig(new DefaultPropertyLoader(properties)); assertThat(proxyConfig.getProxyHost(), is("proxyhost2")); given(properties.getProperty("proxy.host")).willReturn("proxyhost1"); proxyConfig = new ProxyConfig(new DefaultPropertyLoader(properties)); assertThat(proxyConfig.getProxyHost(), is("proxyhost1")); }
|
public String getProxyHost() { return proxyHost; }
|
ProxyConfig { public String getProxyHost() { return proxyHost; } }
|
ProxyConfig { public String getProxyHost() { return proxyHost; } ProxyConfig(PropertyLoader propertyLoader); }
|
ProxyConfig { public String getProxyHost() { return proxyHost; } ProxyConfig(PropertyLoader propertyLoader); boolean isProxyRequired(); String getProxyType(); String getProxyHost(); int getProxyPort(); String getProxyAddress(); String getProxyUsername(); String getProxyPassword(); String getNonProxyHosts(); }
|
ProxyConfig { public String getProxyHost() { return proxyHost; } ProxyConfig(PropertyLoader propertyLoader); boolean isProxyRequired(); String getProxyType(); String getProxyHost(); int getProxyPort(); String getProxyAddress(); String getProxyUsername(); String getProxyPassword(); String getNonProxyHosts(); }
|
@Test public void closesMultipleDriversForSingleBrowserProvider() throws IOException { BrowserProvider mockProvider = mock(BrowserProvider.class); WebDriver mockDriver = mock(WebDriver.class); when(mockProvider.createDriver()).thenReturn(mockDriver); Browser browser1 = test1.getBrowser("A", mockProvider); browser1.getDriver(); Browser browser2 = test1.getBrowser("B", mockProvider); browser2.getDriver(); test1.closeSuiteResources(); verify(mockProvider, times(1)).close(); verify(mockDriver, times(2)).quit(); }
|
@Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } static void setScreenshotTakerClass(Class<? extends ScreenshotTaker> screenshotTaker); @Override Browser getBrowser(); Browser getBrowser(String key); Browser getBrowser(String key, BrowserProvider browserProvider); void switchBrowser(String key); void switchBrowser(String key, BrowserProvider browserProvider); @AfterSuite void resetThreadBrowsers(); }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } static void setScreenshotTakerClass(Class<? extends ScreenshotTaker> screenshotTaker); @Override Browser getBrowser(); Browser getBrowser(String key); Browser getBrowser(String key, BrowserProvider browserProvider); void switchBrowser(String key); void switchBrowser(String key, BrowserProvider browserProvider); @AfterSuite void resetThreadBrowsers(); }
|
@Test public void closesMultipleDriversAndBrowserProviders() throws IOException { BrowserProvider mockProvider1 = mock(BrowserProvider.class); WebDriver mockDriver1 = mock(WebDriver.class); when(mockProvider1.createDriver()).thenReturn(mockDriver1); BrowserProvider mockProvider2 = mock(BrowserProvider.class); WebDriver mockDriver2 = mock(WebDriver.class); when(mockProvider2.createDriver()).thenReturn(mockDriver2); Browser browser1 = test1.getBrowser("E", mockProvider1); browser1.getDriver(); Browser browser2 = test1.getBrowser("F", mockProvider1); browser2.getDriver(); Browser browser3 = test1.getBrowser("G", mockProvider2); browser3.getDriver(); test1.closeSuiteResources(); verify(mockProvider1, times(1)).close(); verify(mockDriver1, times(2)).quit(); verify(mockProvider2, times(1)).close(); verify(mockDriver2, times(1)).quit(); }
|
@Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } static void setScreenshotTakerClass(Class<? extends ScreenshotTaker> screenshotTaker); @Override Browser getBrowser(); Browser getBrowser(String key); Browser getBrowser(String key, BrowserProvider browserProvider); void switchBrowser(String key); void switchBrowser(String key, BrowserProvider browserProvider); @AfterSuite void resetThreadBrowsers(); }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } static void setScreenshotTakerClass(Class<? extends ScreenshotTaker> screenshotTaker); @Override Browser getBrowser(); Browser getBrowser(String key); Browser getBrowser(String key, BrowserProvider browserProvider); void switchBrowser(String key); void switchBrowser(String key, BrowserProvider browserProvider); @AfterSuite void resetThreadBrowsers(); }
|
@Test public void runningTestsAsSeparateSuites_browsersAreNotReused() { BrowserProvider mockProvider = mock(BrowserProvider.class); ConcordionBrowserFixture test = this.test1; Browser browser1 = test.getBrowser("X", mockProvider); afterSuite(test); ConcordionBrowserFixture test2 = new ConcordionBrowserFixture() {}; Browser browser2 = test2.getBrowser("X", mockProvider); afterSuite(test2); assertThat(browser1, is(not(browser2))); }
|
@Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } static void setScreenshotTakerClass(Class<? extends ScreenshotTaker> screenshotTaker); @Override Browser getBrowser(); Browser getBrowser(String key); Browser getBrowser(String key, BrowserProvider browserProvider); void switchBrowser(String key); void switchBrowser(String key, BrowserProvider browserProvider); @AfterSuite void resetThreadBrowsers(); }
|
ConcordionBrowserFixture extends ConcordionFixture implements BrowserBasedTest { @Override public Browser getBrowser() { return getBrowser(threadBrowserId.get()); } static void setScreenshotTakerClass(Class<? extends ScreenshotTaker> screenshotTaker); @Override Browser getBrowser(); Browser getBrowser(String key); Browser getBrowser(String key, BrowserProvider browserProvider); void switchBrowser(String key); void switchBrowser(String key, BrowserProvider browserProvider); @AfterSuite void resetThreadBrowsers(); }
|
@Test public void canCreateInstanceOfPageObjectUsingBBTOnly() { PageHelper tpo = setUpMocks(); TestPageObject testPageObject = tpo.newInstance(TestPageObject.class); assertNotNull("Should not be null when constructing instance of " + TestPageObject.class.getName(), testPageObject); }
|
public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); void triggerCheckPage(WebElement triggerElement, String tag); void checkWindow(String tag); void checkRegion(WebElement region, String tag); boolean isElementPresent(WebElement element); boolean isElementVisible(WebElement element); static boolean isElementPresent(WebDriver driver, By by); static boolean isElementVisible(WebDriver driver, By by); void capturePage(WebElement element); void capturePage(WebElement element, String description); void capturePage(ScreenshotTaker screenshotTaker, String description); void capturePage(WebElement element, String description, CardResult result); P capturePageAndClick(WebElement element, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, String description, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, int timeoutSeconds, String description, Class<P> expectedPage, Object... params); void waitForElementToClickable(WebElement webElement, int timeOutInSeconds); P newInstance(Class<P> expectedPage, Object... params); WebElement getFirstVisibleElement(List<WebElement> webElements); String getCurrentFrameNameOrId(); static String getCurrentFrameNameOrId(WebDriver driver); static WebElement getCurrentFrame(WebDriver driver); void switchToMainDocument(); static void switchToMainDocument(WebDriver driver); void acceptAlertIfPresent(); static void acceptAlertIfPresent(WebDriver driver); static void waitUntil(WebDriver driver, ExpectedCondition<?> condition, int timeOutInSeconds); }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); void triggerCheckPage(WebElement triggerElement, String tag); void checkWindow(String tag); void checkRegion(WebElement region, String tag); boolean isElementPresent(WebElement element); boolean isElementVisible(WebElement element); static boolean isElementPresent(WebDriver driver, By by); static boolean isElementVisible(WebDriver driver, By by); void capturePage(WebElement element); void capturePage(WebElement element, String description); void capturePage(ScreenshotTaker screenshotTaker, String description); void capturePage(WebElement element, String description, CardResult result); P capturePageAndClick(WebElement element, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, String description, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, int timeoutSeconds, String description, Class<P> expectedPage, Object... params); void waitForElementToClickable(WebElement webElement, int timeOutInSeconds); P newInstance(Class<P> expectedPage, Object... params); WebElement getFirstVisibleElement(List<WebElement> webElements); String getCurrentFrameNameOrId(); static String getCurrentFrameNameOrId(WebDriver driver); static WebElement getCurrentFrame(WebDriver driver); void switchToMainDocument(); static void switchToMainDocument(WebDriver driver); void acceptAlertIfPresent(); static void acceptAlertIfPresent(WebDriver driver); static void waitUntil(WebDriver driver, ExpectedCondition<?> condition, int timeOutInSeconds); }
|
@Test public void canCreateInstanceOfPageObjectUsingBBTPlusMultipleParams() { PageHelper tpo = setUpMocks(); TestPageObject testPageObject = tpo.newInstance(TestPageObject.class, "HelloWorld", 1); assertNotNull("Should not be null when constructing instance of " + TestPageObject.class.getName() + " and optional parameters", testPageObject); }
|
public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); void triggerCheckPage(WebElement triggerElement, String tag); void checkWindow(String tag); void checkRegion(WebElement region, String tag); boolean isElementPresent(WebElement element); boolean isElementVisible(WebElement element); static boolean isElementPresent(WebDriver driver, By by); static boolean isElementVisible(WebDriver driver, By by); void capturePage(WebElement element); void capturePage(WebElement element, String description); void capturePage(ScreenshotTaker screenshotTaker, String description); void capturePage(WebElement element, String description, CardResult result); P capturePageAndClick(WebElement element, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, String description, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, int timeoutSeconds, String description, Class<P> expectedPage, Object... params); void waitForElementToClickable(WebElement webElement, int timeOutInSeconds); P newInstance(Class<P> expectedPage, Object... params); WebElement getFirstVisibleElement(List<WebElement> webElements); String getCurrentFrameNameOrId(); static String getCurrentFrameNameOrId(WebDriver driver); static WebElement getCurrentFrame(WebDriver driver); void switchToMainDocument(); static void switchToMainDocument(WebDriver driver); void acceptAlertIfPresent(); static void acceptAlertIfPresent(WebDriver driver); static void waitUntil(WebDriver driver, ExpectedCondition<?> condition, int timeOutInSeconds); }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); void triggerCheckPage(WebElement triggerElement, String tag); void checkWindow(String tag); void checkRegion(WebElement region, String tag); boolean isElementPresent(WebElement element); boolean isElementVisible(WebElement element); static boolean isElementPresent(WebDriver driver, By by); static boolean isElementVisible(WebDriver driver, By by); void capturePage(WebElement element); void capturePage(WebElement element, String description); void capturePage(ScreenshotTaker screenshotTaker, String description); void capturePage(WebElement element, String description, CardResult result); P capturePageAndClick(WebElement element, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, String description, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, int timeoutSeconds, String description, Class<P> expectedPage, Object... params); void waitForElementToClickable(WebElement webElement, int timeOutInSeconds); P newInstance(Class<P> expectedPage, Object... params); WebElement getFirstVisibleElement(List<WebElement> webElements); String getCurrentFrameNameOrId(); static String getCurrentFrameNameOrId(WebDriver driver); static WebElement getCurrentFrame(WebDriver driver); void switchToMainDocument(); static void switchToMainDocument(WebDriver driver); void acceptAlertIfPresent(); static void acceptAlertIfPresent(WebDriver driver); static void waitUntil(WebDriver driver, ExpectedCondition<?> condition, int timeOutInSeconds); }
|
@Test public void shouldFailAsNoParamsConstructorForPageObject() { PageHelper tpo = setUpMocks(); thrown.expect(RuntimeException.class); thrown.expectCause(allOf( instanceOf(NoSuchMethodException.class), hasProperty("message", is("org.concordion.cubano.driver.web.TestPageObjectNoParams.<init>(org.concordion.cubano.driver.BrowserBasedTest, [Ljava.lang.Object;)")))); tpo.newInstance(TestPageObjectNoParams.class, "ShouldFailAsNoParamsConstructor"); }
|
public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); void triggerCheckPage(WebElement triggerElement, String tag); void checkWindow(String tag); void checkRegion(WebElement region, String tag); boolean isElementPresent(WebElement element); boolean isElementVisible(WebElement element); static boolean isElementPresent(WebDriver driver, By by); static boolean isElementVisible(WebDriver driver, By by); void capturePage(WebElement element); void capturePage(WebElement element, String description); void capturePage(ScreenshotTaker screenshotTaker, String description); void capturePage(WebElement element, String description, CardResult result); P capturePageAndClick(WebElement element, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, String description, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, int timeoutSeconds, String description, Class<P> expectedPage, Object... params); void waitForElementToClickable(WebElement webElement, int timeOutInSeconds); P newInstance(Class<P> expectedPage, Object... params); WebElement getFirstVisibleElement(List<WebElement> webElements); String getCurrentFrameNameOrId(); static String getCurrentFrameNameOrId(WebDriver driver); static WebElement getCurrentFrame(WebDriver driver); void switchToMainDocument(); static void switchToMainDocument(WebDriver driver); void acceptAlertIfPresent(); static void acceptAlertIfPresent(WebDriver driver); static void waitUntil(WebDriver driver, ExpectedCondition<?> condition, int timeOutInSeconds); }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); void triggerCheckPage(WebElement triggerElement, String tag); void checkWindow(String tag); void checkRegion(WebElement region, String tag); boolean isElementPresent(WebElement element); boolean isElementVisible(WebElement element); static boolean isElementPresent(WebDriver driver, By by); static boolean isElementVisible(WebDriver driver, By by); void capturePage(WebElement element); void capturePage(WebElement element, String description); void capturePage(ScreenshotTaker screenshotTaker, String description); void capturePage(WebElement element, String description, CardResult result); P capturePageAndClick(WebElement element, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, String description, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, int timeoutSeconds, String description, Class<P> expectedPage, Object... params); void waitForElementToClickable(WebElement webElement, int timeOutInSeconds); P newInstance(Class<P> expectedPage, Object... params); WebElement getFirstVisibleElement(List<WebElement> webElements); String getCurrentFrameNameOrId(); static String getCurrentFrameNameOrId(WebDriver driver); static WebElement getCurrentFrame(WebDriver driver); void switchToMainDocument(); static void switchToMainDocument(WebDriver driver); void acceptAlertIfPresent(); static void acceptAlertIfPresent(WebDriver driver); static void waitUntil(WebDriver driver, ExpectedCondition<?> condition, int timeOutInSeconds); }
|
@Test public void canCreateInstanceOfPageObjectWhichOnlyHasBBTConstructor() { PageHelper tpo = setUpMocks(); TestPageObjectNoParams testPageObjectNoParams = tpo.newInstance(TestPageObjectNoParams.class); assertNotNull("Should not be null when constructing instance of " + TestPageObjectNoParams.class.getName() + " and class has Browser Based Test Constructor Only", testPageObjectNoParams); }
|
public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); void triggerCheckPage(WebElement triggerElement, String tag); void checkWindow(String tag); void checkRegion(WebElement region, String tag); boolean isElementPresent(WebElement element); boolean isElementVisible(WebElement element); static boolean isElementPresent(WebDriver driver, By by); static boolean isElementVisible(WebDriver driver, By by); void capturePage(WebElement element); void capturePage(WebElement element, String description); void capturePage(ScreenshotTaker screenshotTaker, String description); void capturePage(WebElement element, String description, CardResult result); P capturePageAndClick(WebElement element, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, String description, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, int timeoutSeconds, String description, Class<P> expectedPage, Object... params); void waitForElementToClickable(WebElement webElement, int timeOutInSeconds); P newInstance(Class<P> expectedPage, Object... params); WebElement getFirstVisibleElement(List<WebElement> webElements); String getCurrentFrameNameOrId(); static String getCurrentFrameNameOrId(WebDriver driver); static WebElement getCurrentFrame(WebDriver driver); void switchToMainDocument(); static void switchToMainDocument(WebDriver driver); void acceptAlertIfPresent(); static void acceptAlertIfPresent(WebDriver driver); static void waitUntil(WebDriver driver, ExpectedCondition<?> condition, int timeOutInSeconds); }
|
PageHelper { public <P extends BasePageObject<P>> P newInstance(Class<P> expectedPage, Object... params) { try { if (params.length > 0) { Class<?>[] constructorArguments = new Class<?>[2]; constructorArguments[0] = BrowserBasedTest.class; constructorArguments[1] = Object[].class; return expectedPage.getDeclaredConstructor(constructorArguments).newInstance(getTest(), params); } else { return expectedPage.getDeclaredConstructor(BrowserBasedTest.class).newInstance(getTest()); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { if (e.getMessage() == null && e.getCause() != null) { throw new RuntimeException(e.getCause()); } else { throw new RuntimeException(e); } } } PageHelper(BasePageObject<?> pageObject); PageHelper(BasePageObject<?> pageObject, Class<?> logLocation); void triggerCheckPage(WebElement triggerElement, String tag); void checkWindow(String tag); void checkRegion(WebElement region, String tag); boolean isElementPresent(WebElement element); boolean isElementVisible(WebElement element); static boolean isElementPresent(WebDriver driver, By by); static boolean isElementVisible(WebDriver driver, By by); void capturePage(WebElement element); void capturePage(WebElement element, String description); void capturePage(ScreenshotTaker screenshotTaker, String description); void capturePage(WebElement element, String description, CardResult result); P capturePageAndClick(WebElement element, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, String description, Class<P> expectedPage, Object... params); P capturePageAndClick(WebElement element, int timeoutSeconds, String description, Class<P> expectedPage, Object... params); void waitForElementToClickable(WebElement webElement, int timeOutInSeconds); P newInstance(Class<P> expectedPage, Object... params); WebElement getFirstVisibleElement(List<WebElement> webElements); String getCurrentFrameNameOrId(); static String getCurrentFrameNameOrId(WebDriver driver); static WebElement getCurrentFrame(WebDriver driver); void switchToMainDocument(); static void switchToMainDocument(WebDriver driver); void acceptAlertIfPresent(); static void acceptAlertIfPresent(WebDriver driver); static void waitUntil(WebDriver driver, ExpectedCondition<?> condition, int timeOutInSeconds); }
|
@Test public void propertyKeyOriginalCaseIsAvailalbe() { Properties properties = new CaselessProperties(); properties.put("a.SETTING", "value"); @SuppressWarnings("unchecked") Enumeration<String> en = (Enumeration<String>) properties.propertyNames(); String propName = en.nextElement(); assertThat(propName, is("a.SETTING")); }
|
@Override public synchronized Object put(Object key, Object value) { lookup.put(((String) key), (String) key); return super.put(key, value); }
|
CaselessProperties extends Properties { @Override public synchronized Object put(Object key, Object value) { lookup.put(((String) key), (String) key); return super.put(key, value); } }
|
CaselessProperties extends Properties { @Override public synchronized Object put(Object key, Object value) { lookup.put(((String) key), (String) key); return super.put(key, value); } }
|
CaselessProperties extends Properties { @Override public synchronized Object put(Object key, Object value) { lookup.put(((String) key), (String) key); return super.put(key, value); } @Override synchronized Object put(Object key, Object value); @Override String getProperty(String key); @Override String getProperty(String key, String defaultValue); }
|
CaselessProperties extends Properties { @Override public synchronized Object put(Object key, Object value) { lookup.put(((String) key), (String) key); return super.put(key, value); } @Override synchronized Object put(Object key, Object value); @Override String getProperty(String key); @Override String getProperty(String key, String defaultValue); }
|
@Test public void environmentPropertiesOverrideDefaultProperties() { Properties properties = givenDefaultProperties(); given(properties.getProperty("a.setting")).willReturn("false"); given(properties.getProperty("SIT.a.setting")).willReturn("true"); DefaultPropertyLoader loader = new DefaultPropertyLoader(properties); assertThat(loader.getProperty("a.setting"), is("false")); given(properties.getProperty(eq("environment"), any())).willReturn("SIT"); loader = new DefaultPropertyLoader(properties); assertThat(loader.getProperty("a.setting"), is("true")); }
|
@Override public String getProperty(String key) { String value = retrieveProperty(key); if (value.isEmpty()) { throw new IllegalArgumentException(String.format("Unable to find property %s", key)); } return value; }
|
DefaultPropertyLoader implements PropertyLoader { @Override public String getProperty(String key) { String value = retrieveProperty(key); if (value.isEmpty()) { throw new IllegalArgumentException(String.format("Unable to find property %s", key)); } return value; } }
|
DefaultPropertyLoader implements PropertyLoader { @Override public String getProperty(String key) { String value = retrieveProperty(key); if (value.isEmpty()) { throw new IllegalArgumentException(String.format("Unable to find property %s", key)); } return value; } DefaultPropertyLoader(Properties properties); }
|
DefaultPropertyLoader implements PropertyLoader { @Override public String getProperty(String key) { String value = retrieveProperty(key); if (value.isEmpty()) { throw new IllegalArgumentException(String.format("Unable to find property %s", key)); } return value; } DefaultPropertyLoader(Properties properties); String getEnvironment(); @Override String getProperty(String key); @Override String getProperty(String key, String defaultValue); @Override boolean getPropertyAsBoolean(String key, String defaultValue); @Override int getPropertyAsInteger(String key, String defaultValue); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix, boolean trimPrefix); }
|
DefaultPropertyLoader implements PropertyLoader { @Override public String getProperty(String key) { String value = retrieveProperty(key); if (value.isEmpty()) { throw new IllegalArgumentException(String.format("Unable to find property %s", key)); } return value; } DefaultPropertyLoader(Properties properties); String getEnvironment(); @Override String getProperty(String key); @Override String getProperty(String key, String defaultValue); @Override boolean getPropertyAsBoolean(String key, String defaultValue); @Override int getPropertyAsInteger(String key, String defaultValue); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix, boolean trimPrefix); }
|
@Test public void systemPropertyWillOverrideEnvironment() throws Exception { Properties properties = givenDefaultProperties(); System.setProperty("environment", "SIT"); DefaultPropertyLoader loader = new DefaultPropertyLoader(properties); assertThat(loader.getEnvironment(), is("SIT")); }
|
public String getEnvironment() { return environment; }
|
DefaultPropertyLoader implements PropertyLoader { public String getEnvironment() { return environment; } }
|
DefaultPropertyLoader implements PropertyLoader { public String getEnvironment() { return environment; } DefaultPropertyLoader(Properties properties); }
|
DefaultPropertyLoader implements PropertyLoader { public String getEnvironment() { return environment; } DefaultPropertyLoader(Properties properties); String getEnvironment(); @Override String getProperty(String key); @Override String getProperty(String key, String defaultValue); @Override boolean getPropertyAsBoolean(String key, String defaultValue); @Override int getPropertyAsInteger(String key, String defaultValue); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix, boolean trimPrefix); }
|
DefaultPropertyLoader implements PropertyLoader { public String getEnvironment() { return environment; } DefaultPropertyLoader(Properties properties); String getEnvironment(); @Override String getProperty(String key); @Override String getProperty(String key, String defaultValue); @Override boolean getPropertyAsBoolean(String key, String defaultValue); @Override int getPropertyAsInteger(String key, String defaultValue); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix, boolean trimPrefix); }
|
@Test public void canSearchForPopertiesWithPrefixMatchingCase() throws IOException { Properties properties = givenDefaultSearchProperties(); DefaultPropertyLoader loader = new DefaultPropertyLoader(properties); Map<String, String> found = loader.getPropertiesStartingWith("a.setting."); assertThat(found.values().size(), is(1)); assertThat(found.keySet().iterator().next(), is("a.setting.2")); }
|
@Override public Map<String, String> getPropertiesStartingWith(String keyPrefix) { return getPropertiesStartingWith(keyPrefix, false); }
|
DefaultPropertyLoader implements PropertyLoader { @Override public Map<String, String> getPropertiesStartingWith(String keyPrefix) { return getPropertiesStartingWith(keyPrefix, false); } }
|
DefaultPropertyLoader implements PropertyLoader { @Override public Map<String, String> getPropertiesStartingWith(String keyPrefix) { return getPropertiesStartingWith(keyPrefix, false); } DefaultPropertyLoader(Properties properties); }
|
DefaultPropertyLoader implements PropertyLoader { @Override public Map<String, String> getPropertiesStartingWith(String keyPrefix) { return getPropertiesStartingWith(keyPrefix, false); } DefaultPropertyLoader(Properties properties); String getEnvironment(); @Override String getProperty(String key); @Override String getProperty(String key, String defaultValue); @Override boolean getPropertyAsBoolean(String key, String defaultValue); @Override int getPropertyAsInteger(String key, String defaultValue); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix, boolean trimPrefix); }
|
DefaultPropertyLoader implements PropertyLoader { @Override public Map<String, String> getPropertiesStartingWith(String keyPrefix) { return getPropertiesStartingWith(keyPrefix, false); } DefaultPropertyLoader(Properties properties); String getEnvironment(); @Override String getProperty(String key); @Override String getProperty(String key, String defaultValue); @Override boolean getPropertyAsBoolean(String key, String defaultValue); @Override int getPropertyAsInteger(String key, String defaultValue); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix); @Override Map<String, String> getPropertiesStartingWith(String keyPrefix, boolean trimPrefix); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.