@Test(expectedExceptions = IOException.class) public void testDeleteUnexistingRhyme() throws IOException { store.delete("Unexisting"); }
public void delete(final String sentence) throws IOException { String word = WordUtils.getLastWord(sentence); if (word.isEmpty()) { return; } String rhyme = normalizeString(wordParser.phoneticRhymePart(word)); StressType type = wordParser.stressType(word); connect(); try { String sentenceKey = getUniqueIdKey(sentencens, normalizeString(sentence)); if (redis.exists(sentenceKey) == 0) { throw new IOException("The element to remove does not exist."); } String indexKey = getUniqueIdKey(indexns, buildUniqueToken(rhyme, type)); String sentenceId = redis.get(sentenceKey); sentenceId = sentencens.build(sentenceId).toString(); if (redis.exists(indexKey) == 1) { String indexId = redis.get(indexKey); indexId = indexns.build(indexId).toString(); if (redis.exists(indexId) == 1) { redis.srem(indexId, sentenceId); } if (redis.smembers(indexId).isEmpty()) { redis.del(indexId, indexKey); } } redis.del(sentenceId, sentenceKey); LOGGER.info("Deleted rhyme: {}", sentence); } finally { disconnect(); } }
RedisStore { public void delete(final String sentence) throws IOException { String word = WordUtils.getLastWord(sentence); if (word.isEmpty()) { return; } String rhyme = normalizeString(wordParser.phoneticRhymePart(word)); StressType type = wordParser.stressType(word); connect(); try { String sentenceKey = getUniqueIdKey(sentencens, normalizeString(sentence)); if (redis.exists(sentenceKey) == 0) { throw new IOException("The element to remove does not exist."); } String indexKey = getUniqueIdKey(indexns, buildUniqueToken(rhyme, type)); String sentenceId = redis.get(sentenceKey); sentenceId = sentencens.build(sentenceId).toString(); if (redis.exists(indexKey) == 1) { String indexId = redis.get(indexKey); indexId = indexns.build(indexId).toString(); if (redis.exists(indexId) == 1) { redis.srem(indexId, sentenceId); } if (redis.smembers(indexId).isEmpty()) { redis.del(indexId, indexKey); } } redis.del(sentenceId, sentenceKey); LOGGER.info("Deleted rhyme: {}", sentence); } finally { disconnect(); } } }
RedisStore { public void delete(final String sentence) throws IOException { String word = WordUtils.getLastWord(sentence); if (word.isEmpty()) { return; } String rhyme = normalizeString(wordParser.phoneticRhymePart(word)); StressType type = wordParser.stressType(word); connect(); try { String sentenceKey = getUniqueIdKey(sentencens, normalizeString(sentence)); if (redis.exists(sentenceKey) == 0) { throw new IOException("The element to remove does not exist."); } String indexKey = getUniqueIdKey(indexns, buildUniqueToken(rhyme, type)); String sentenceId = redis.get(sentenceKey); sentenceId = sentencens.build(sentenceId).toString(); if (redis.exists(indexKey) == 1) { String indexId = redis.get(indexKey); indexId = indexns.build(indexId).toString(); if (redis.exists(indexId) == 1) { redis.srem(indexId, sentenceId); } if (redis.smembers(indexId).isEmpty()) { redis.del(indexId, indexKey); } } redis.del(sentenceId, sentenceKey); LOGGER.info("Deleted rhyme: {}", sentence); } finally { disconnect(); } } @Inject  RedisStore(@Named("sentence") final Keymaker sentencens,
        @Named("index") final Keymaker indexns, final WordParser wordParser, final Jedis redis,
        final @Named(REDIS_PASSWORD) Optional<String> redisPassword, final Charset encoding); }
RedisStore { public void delete(final String sentence) throws IOException { String word = WordUtils.getLastWord(sentence); if (word.isEmpty()) { return; } String rhyme = normalizeString(wordParser.phoneticRhymePart(word)); StressType type = wordParser.stressType(word); connect(); try { String sentenceKey = getUniqueIdKey(sentencens, normalizeString(sentence)); if (redis.exists(sentenceKey) == 0) { throw new IOException("The element to remove does not exist."); } String indexKey = getUniqueIdKey(indexns, buildUniqueToken(rhyme, type)); String sentenceId = redis.get(sentenceKey); sentenceId = sentencens.build(sentenceId).toString(); if (redis.exists(indexKey) == 1) { String indexId = redis.get(indexKey); indexId = indexns.build(indexId).toString(); if (redis.exists(indexId) == 1) { redis.srem(indexId, sentenceId); } if (redis.smembers(indexId).isEmpty()) { redis.del(indexId, indexKey); } } redis.del(sentenceId, sentenceKey); LOGGER.info("Deleted rhyme: {}", sentence); } finally { disconnect(); } } @Inject  RedisStore(@Named("sentence") final Keymaker sentencens,
        @Named("index") final Keymaker indexns, final WordParser wordParser, final Jedis redis,
        final @Named(REDIS_PASSWORD) Optional<String> redisPassword, final Charset encoding); void add(final String sentence); void delete(final String sentence); Set<String> findAll(); String getRhyme(final String sentence); }
RedisStore { public void delete(final String sentence) throws IOException { String word = WordUtils.getLastWord(sentence); if (word.isEmpty()) { return; } String rhyme = normalizeString(wordParser.phoneticRhymePart(word)); StressType type = wordParser.stressType(word); connect(); try { String sentenceKey = getUniqueIdKey(sentencens, normalizeString(sentence)); if (redis.exists(sentenceKey) == 0) { throw new IOException("The element to remove does not exist."); } String indexKey = getUniqueIdKey(indexns, buildUniqueToken(rhyme, type)); String sentenceId = redis.get(sentenceKey); sentenceId = sentencens.build(sentenceId).toString(); if (redis.exists(indexKey) == 1) { String indexId = redis.get(indexKey); indexId = indexns.build(indexId).toString(); if (redis.exists(indexId) == 1) { redis.srem(indexId, sentenceId); } if (redis.smembers(indexId).isEmpty()) { redis.del(indexId, indexKey); } } redis.del(sentenceId, sentenceKey); LOGGER.info("Deleted rhyme: {}", sentence); } finally { disconnect(); } } @Inject  RedisStore(@Named("sentence") final Keymaker sentencens,
        @Named("index") final Keymaker indexns, final WordParser wordParser, final Jedis redis,
        final @Named(REDIS_PASSWORD) Optional<String> redisPassword, final Charset encoding); void add(final String sentence); void delete(final String sentence); Set<String> findAll(); String getRhyme(final String sentence);  }