@Override int weigh(Map<String, Entry<?>> value) { int weight = 0; weight += pathPattern.length(); weight += options.size(); for (Entry<?> e : value.values()) { weight += e.path().length(); if (e.hasContent()) { weight += e.contentAsText().length(); } } return weight; }
@Override int weigh(Map<String, Entry<?>> value) { int weight = 0; weight += pathPattern.length(); weight += options.size(); for (Entry<?> e : value.values()) { weight += e.path().length(); if (e.hasContent()) { weight += e.contentAsText().length(); } } return weight; }
@Override int weigh(Map<String, Entry<?>> value) { int weight = 0; weight += pathPattern.length(); weight += options.size(); for (Entry<?> e : value.values()) { weight += e.path().length(); if (e.hasContent()) { weight += e.contentAsText().length(); } } return weight; }
@Override int weigh(Entry<?> value) { int weight = 0; weight += query.path().length(); for (String e : query.expressions()) { weight += e.length(); } if (value != null && value.hasContent()) { weight += value.contentAsText().length(); } return weight; }
@Override int weigh(Entry<?> value) { int weight = 0; weight += query.path().length(); for (String e : query.expressions()) { weight += e.length(); } if (value != null && value.hasContent()) { weight += value.contentAsText().length(); } return weight; }
@Override int weigh(Entry<?> value) { int weight = 0; weight += query.path().length(); for (String e : query.expressions()) { weight += e.length(); } if (value != null && value.hasContent()) { weight += value.contentAsText().length(); } return weight; }
public static <T> EntryDto<T> convert(Repository repository, Entry<T> entry) { requireNonNull(entry, "entry"); if (entry.hasContent()) { return convert(repository, entry.path(), entry.type(), entry.content()); } return convert(repository, entry.path(), entry.type()); }
public static <T> EntryDto<T> convert(Repository repository, Entry<T> entry) { requireNonNull(entry, "entry"); if (entry.hasContent()) { return convert(repository, entry.path(), entry.type(), entry.content()); } return convert(repository, entry.path(), entry.type()); }
public static <T> EntryDto<T> convert(Repository repository, Entry<T> entry) { requireNonNull(entry, "entry"); if (entry.hasContent()) { return convert(repository, entry.path(), entry.type(), entry.content()); } return convert(repository, entry.path(), entry.type()); }
@Test public void testGetFilesWithDirectory() throws Exception { final String testRootWithoutSlash = TEST_ROOT.substring(0, TEST_ROOT.length() - 1); final Map<String, Entry<?>> files = rule.client().getFiles( rule.project(), rule.repo1(), Revision.HEAD, testRootWithoutSlash + ", " + TEST_ROOT + '*').join(); assertThat(files).hasSize(NUM_FILES + 1); final Entry<?> dir = files.get(testRootWithoutSlash); assertThat(dir.type()).isEqualTo(EntryType.DIRECTORY); assertThat(dir.path()).isEqualTo(testRootWithoutSlash); assertThat(dir.hasContent()).isFalse(); assertThatThrownBy(dir::content).isInstanceOf(IllegalStateException.class); files.values().forEach(f -> { if (f.type() != EntryType.DIRECTORY) { assertThatJson(f.content()).isEqualTo("{}"); } }); }
@Test public void ofDirectory() throws Exception { final Entry<Void> e = Entry.ofDirectory(new Revision(1), "/"); assertThat(e.revision()).isEqualTo(new Revision(1)); assertThat(e.hasContent()).isFalse(); e.ifHasContent(unused -> fail()); assertThatThrownBy(e::content).isInstanceOf(IllegalStateException.class); assertThatThrownBy(e::contentAsJson).isInstanceOf(IllegalStateException.class); assertThatThrownBy(e::contentAsText).isInstanceOf(IllegalStateException.class); assertThatThrownBy(e::contentAsPrettyText).isInstanceOf(IllegalStateException.class); assertThatThrownBy(() -> e.contentAsJson(JsonNode.class)).isInstanceOf(IllegalStateException.class); // directory vs. directory final Entry<Void> e2 = Entry.ofDirectory(new Revision(1), "/"); assertThat(e).isEqualTo(e2); assertThat(e.hashCode()).isEqualTo(e2.hashCode()); assertThat(e).isNotEqualTo(Entry.ofDirectory(new Revision(2), "/")); assertThat(e).isNotEqualTo(Entry.ofDirectory(new Revision(1), "/foo")); // directory vs. text file final Entry<String> e3 = Entry.ofText(new Revision(1), "/a.txt", "foo"); assertThat(e).isNotEqualTo(e3); assertThat(e.hashCode()).isNotEqualTo(e3.hashCode()); // directory vs. JSON file final Entry<JsonNode> e4 = Entry.ofJson(new Revision(1), "/a.json", "{ \"foo\": \"bar\" }"); assertThat(e).isNotEqualTo(e4); assertThat(e.hashCode()).isNotEqualTo(e4.hashCode()); }
final Entry<String> e = Entry.ofText(new Revision(1), "/a.txt", "foo"); assertThat(e.revision()).isEqualTo(new Revision(1)); assertThat(e.hasContent()).isTrue(); e.ifHasContent(content -> assertThat(content).isEqualTo("foo")); assertThat(e.content()).isEqualTo("foo");
@Test public void ofJson() throws Exception { final Entry<JsonNode> e = Entry.ofJson(new Revision(1), "/a.json", "{ \"foo\": \"bar\" }"); assertThat(e.revision()).isEqualTo(new Revision(1)); assertThat(e.hasContent()).isTrue(); e.ifHasContent(content -> assertThatJson(content).isEqualTo("{ \"foo\": \"bar\" }")); assertThatJson(e.content()).isEqualTo("{ \"foo\": \"bar\" }"); assertThat(e.contentAsText()).isEqualTo("{\"foo\":\"bar\"}"); assertThat(e.contentAsPrettyText()).isEqualTo("{\n \"foo\": \"bar\"\n}"); assertThat(e.content()).isSameAs(e.contentAsJson()); assertThat(e.content()).isEqualTo(e.contentAsJson(JsonNode.class)); // JSON file vs. JSON file final Entry<JsonNode> e2 = Entry.ofJson(new Revision(1), "/a.json", "{ \"foo\": \"bar\" }"); assertThat(e).isEqualTo(e2); assertThat(e.hashCode()).isEqualTo(e2.hashCode()); assertThat(e).isNotEqualTo(Entry.ofJson(new Revision(2), "/a.json", "{ \"foo\": \"bar\" }")); assertThat(e).isNotEqualTo(Entry.ofJson(new Revision(1), "/b.json", "{ \"foo\": \"bar\" }")); assertThat(e).isNotEqualTo(Entry.ofJson(new Revision(1), "/a.json", "null")); // JSON file vs. text file final Entry<String> e3 = Entry.ofText(new Revision(1), "/a.json", "{\"foo\":\"bar\"}"); assertThat(e).isNotEqualTo(e3); assertThat(e.hashCode()).isNotEqualTo(e3.hashCode()); // JSON file vs. directory final Entry<Void> e4 = Entry.ofDirectory(new Revision(1), "/foo"); assertThat(e).isNotEqualTo(e4); assertThat(e.hashCode()).isNotEqualTo(e4.hashCode()); }