Tabnine Logo
ReferenceLibrary.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
org.batfish.referencelibrary.ReferenceLibrary
constructor

Best Java code snippets using org.batfish.referencelibrary.ReferenceLibrary.<init> (Showing top 10 results out of 315)

origin: batfish/batfish

/**
 * Reads the {@link ReferenceLibrary} object from {@code dataPath}. If the path does not exist,
 * initializes a new object.
 *
 * @throws IOException If file exists but its contents could not be cast to {@link
 *     ReferenceLibrary}
 */
public static ReferenceLibrary read(Path dataPath) throws IOException {
 if (Files.exists(dataPath)) {
  return BatfishObjectMapper.mapper()
    .readValue(CommonUtil.readFile(dataPath), ReferenceLibrary.class);
 }
 return new ReferenceLibrary(null);
}
origin: batfish/batfish

/**
 * Adds the reference books in {@code newBooks} to the ReferenceLibrary at {@code path}. Books
 * with the same name are overwritten
 */
public static void mergeReferenceBooks(
  @Nonnull Path path, @Nonnull SortedSet<ReferenceBook> newBooks) throws IOException {
 ReferenceLibrary originalLibrary = read(path);
 List<ReferenceBook> booksToKeep =
   originalLibrary._books.stream()
     .filter(
       originalBook ->
         !newBooks.stream()
           .anyMatch(newBook -> newBook.getName().equals(originalBook.getName())))
     .collect(Collectors.toList());
 booksToKeep.addAll(newBooks);
 ReferenceLibrary newLibrary = new ReferenceLibrary(booksToKeep);
 write(newLibrary, path);
}
origin: batfish/batfish

 /** Test that we get back the reference library */
 @Test
 public void getReferenceLibrary() {
  String network = "someNetwork";
  Main.getWorkMgr().initNetwork(network, null);

  // we only check that the right type of object is returned at the expected URL target
  // we rely on ReferenceLibraryBean to have created the object with the right content
  Response response = getReferenceLibraryTarget(network).get();
  assertThat(response.getStatus(), equalTo(OK.getStatusCode()));
  assertThat(
    response.readEntity(ReferenceLibraryBean.class),
    equalTo(new ReferenceLibraryBean(new ReferenceLibrary(ImmutableList.of()))));
 }
}
origin: batfish/batfish

/** Test if empty library is bean'd properly */
@Test
public void constructorEmpty() throws IOException {
 ReferenceLibrary library = new ReferenceLibrary(ImmutableList.of());
 assertThat(new ReferenceLibraryBean(library).books, equalTo(ImmutableSortedSet.of()));
}
origin: batfish/batfish

@Test
public void testGetAddressBooks() {
 String book1 = "book1";
 String book2 = "book2";
 ReferenceBook refBook1 = ReferenceBook.builder(book1).build();
 ReferenceBook refBook2 = ReferenceBook.builder(book2).build();
 ReferenceLibrary referenceLibrary = new ReferenceLibrary(ImmutableList.of(refBook1, refBook2));
 assertThat(getAddressBooks(referenceLibrary), equalTo(ImmutableSet.of(book1, book2)));
}
origin: batfish/batfish

 @Test
 public void getAddressBook() throws JsonProcessingException {
  String container = "someContainer";
  Main.getWorkMgr().initNetwork(container, null);

  // write a library to the right place
  ReferenceLibrary.write(
    new ReferenceLibrary(ImmutableList.of(ReferenceBook.builder("book1").build())),
    Main.getWorkMgr().getReferenceLibraryPath(container));

  // we only check that the right type of object is returned at the expected URL target
  // we rely on ReferenceBookBean to have created the object with the right content
  Response response = getAddressBookTarget(container, "book1").get();
  assertThat(response.getStatus(), equalTo(OK.getStatusCode()));
  assertThat(
    response.readEntity(ReferenceBook.class), equalTo(ReferenceBook.builder("book1").build()));

  // should get 404 for non-existent dimension
  Response response2 = getAddressBookTarget(container, "book2").get();
  assertThat(response2.getStatus(), equalTo(NOT_FOUND.getStatusCode()));
 }
}
origin: batfish/batfish

@Test
public void delAddressBook() throws IOException {
 String container = "someContainer";
 Main.getWorkMgr().initNetwork(container, null);
 // write a library to the right place
 ReferenceLibrary.write(
   new ReferenceLibrary(ImmutableList.of(ReferenceBook.builder("book1").build())),
   Main.getWorkMgr().getReferenceLibraryPath(container));
 Response response = getAddressBookTarget(container, "book1").delete();
 // response should be OK and book1 should have disappeared
 assertThat(response.getStatus(), equalTo(OK.getStatusCode()));
 assertThat(
   Main.getWorkMgr().getReferenceLibrary(container).getReferenceBook("book1").isPresent(),
   equalTo(false));
 // deleting again should fail
 Response response2 = getAddressBookTarget(container, "book1").delete();
 assertThat(response2.getStatus(), equalTo(NOT_FOUND.getStatusCode()));
}
origin: batfish/batfish

@Test
public void testGetAddressGroups() {
 String group1 = "group1";
 String group2 = "group2";
 AddressGroup addressGroup1 = new AddressGroup(null, group1);
 AddressGroup addressGroup2 = new AddressGroup(null, group2);
 ReferenceBook refBook1 =
   ReferenceBook.builder("book1")
     .setAddressGroups(ImmutableList.of(addressGroup1, addressGroup2))
     .build();
 ReferenceBook refBook2 =
   ReferenceBook.builder("book2").setAddressGroups(ImmutableList.of(addressGroup1)).build();
 ReferenceBook refBook3 = ReferenceBook.builder("book3").build();
 ReferenceLibrary referenceLibrary =
   new ReferenceLibrary(ImmutableList.of(refBook1, refBook2, refBook3));
 assertThat(getAddressGroups(referenceLibrary), equalTo(ImmutableSet.of(group1, group2)));
}
origin: batfish/batfish

 /** Test if a non-empty library is bean'd properly */
 @Test
 public void constructorNonEmpty() throws IOException {
  ReferenceLibrary library =
    new ReferenceLibrary(
      ImmutableList.of(
        ReferenceBook.builder("book1").build(), ReferenceBook.builder("book2").build()));

  assertThat(
    new ReferenceLibraryBean(library).books,
    equalTo(
      ImmutableSet.of(
        new ReferenceBookBean(ReferenceBook.builder("book1").build()),
        new ReferenceBookBean(ReferenceBook.builder("book2").build()))));
 }
}
origin: batfish/batfish

Path tempPath = CommonUtil.createTempFile("referencelibrary", "tmp");
ReferenceLibrary library =
  new ReferenceLibrary(
    ImmutableList.of(
      ReferenceBook.builder("book1").build(), ReferenceBook.builder("book2").build()));
org.batfish.referencelibraryReferenceLibrary<init>

Javadoc

The argument to this constructor is a List (not a SortedSet) to prevent Jackson from silently removing duplicate entries.

Popular methods of ReferenceLibrary

  • read
    Reads the ReferenceLibrary object from dataPath. If the path does not exist, initializes a new objec
  • write
  • getReferenceBook
    From the ReferenceLibrary at dataPath, get the ReferenceBook with name bookName.
  • getReferenceBooks
  • checkDuplicates
    Does the provided collection have duplicates?
  • mergeReferenceBooks
    Adds the reference books in newBooks to the ReferenceLibrary at path. Books with the same name are o
  • checkValidName
    Is this is valid library object name?
  • delAddressBook
    Deletes the book

Popular in Java

  • Reading from database using SQL prepared statement
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getExternalFilesDir (Context)
  • getSystemService (Context)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • JTextField (javax.swing)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now