Tabnine Logo
ScenarioIO
Code IndexAdd Tabnine to your IDE (free)

How to use
ScenarioIO
in
com.github.rinde.rinsim.scenario

Best Java code snippets using com.github.rinde.rinsim.scenario.ScenarioIO (Showing top 20 results out of 315)

origin: rinde/RinSim

@SuppressWarnings("null")
@Override
public Scenario get() {
 if (localCache == null) {
  localCache = (Scenario) ScenarioIO.read(
   serializedScenario, scenarioClass);
 }
 return localCache;
}
origin: rinde/RinSim

static String toJson(FabriRechtScenario scenario) {
 return ScenarioIO.write(scenario);
}
origin: com.github.rinde/rinsim-scenario

@Override
public Predicate<?> doDeserialize(JsonElement json, Type typeOfT,
  JsonDeserializationContext context) {
 checkArgument(json.isJsonPrimitive());
 try {
  final Predicate<?> obj =
   (Predicate<?>) deserializeObject(json.getAsString());
  return obj;
 } catch (final IOException e) {
  throw new IllegalArgumentException(e);
 } catch (final ClassNotFoundException e) {
  throw new IllegalArgumentException(e);
 }
}
origin: rinde/RinSim

/**
 * Tests whether the specified scenario can be correctly written to disk, it
 * compares the equality of the specified object with a parsed object and it
 * compares the equality of the serialized string.
 * @param input The scenario to test with IO.
 */
public static void assertScenarioIO(Scenario input) {
 final String serialized = ScenarioIO.write(input);
 final Scenario parsed = ScenarioIO.read(serialized);
 final String serializedAgain = ScenarioIO.write(parsed);
 System.out.println(serialized);
 assertThat(input).isEqualTo(parsed);
 assertThat(serialized).isEqualTo(serializedAgain);
}
origin: rinde/RinSim

/**
 * Tests {@link ScenarioIO#readerAdapter(com.google.common.base.Function)}.
 * @throws IOException When IO fails.
 */
@Test
public void testReaderAdapter() throws IOException {
 final Scenario s = Scenario.builder()
  .addModel(TimeModel.builder().withTickLength(7L))
  .build();
 final Path tmpDir = Files.createTempDirectory("rinsim-scenario-io-test");
 final Path file = Paths.get(tmpDir.toString(), "test.scen");
 ScenarioIO.write(s, file);
 final Scenario out = ScenarioIO.reader().apply(file);
 final Scenario convertedOut =
  verifyNotNull(ScenarioIO.readerAdapter(ScenarioConverters.toRealtime())
   .apply(file));
 assertThat(s).isEqualTo(out);
 assertThat(s).isNotEqualTo(convertedOut);
 assertThat(convertedOut.getModelBuilders())
  .contains(TimeModel.builder()
   .withRealTime()
   .withStartInClockMode(ClockMode.SIMULATED)
   .withTickLength(7L));
 Files.delete(file);
 Files.delete(tmpDir);
}
origin: com.github.rinde/rinsim-scenario

/**
 * Allows to adapt the default reader ({@link #reader()}) by converting all
 * read scenarios. {@link ScenarioConverters} contains functions that can be
 * used for this.
 * @param converter A converter that transforms a scenario.
 * @return A new reader function.
 */
public static Function<Path, Scenario> readerAdapter(
  Function<Scenario, Scenario> converter) {
 return Functions.compose(converter, reader());
}
origin: com.github.rinde/rinsim-scenario

private static Gson initialize() {
 final GsonBuilder builder = new GsonBuilder();
 builder
  .registerTypeAdapter(ProblemClass.class, adapt(ProblemClassIO.INSTANCE))
  .registerTypeHierarchyAdapter(TimeWindowPolicy.class,
   adapt(TimeWindowHierarchyIO.INSTANCE))
  .registerTypeAdapter(Scenario.class, adapt(ScenarioObjIO.INSTANCE))
  .registerTypeAdapter(ParcelDTO.class, adapt(ParcelIO.INSTANCE))
  .registerTypeAdapter(VehicleDTO.class, adapt(VehicleIO.INSTANCE))
  .registerTypeAdapter(Point.class, new PointIO())
  .registerTypeAdapter(TimeWindow.class, new TimeWindowIO())
  .registerTypeAdapter(Unit.class, adapt(UnitIO.INSTANCE))
  .registerTypeAdapter(Supplier.class, adapt(SupplierIO.INSTANCE))
  .registerTypeHierarchyAdapter(Graph.class, adapt(GraphIO.INSTANCE))
  .registerTypeAdapter(Measure.class, adapt(MeasureIO.INSTANCE))
  .registerTypeHierarchyAdapter(Enum.class, adapt(EnumIO.INSTANCE))
  .registerTypeAdapter(StopCondition.class,
   adapt(StopConditionIO.INSTANCE))
  .registerTypeAdapter(Class.class, adapt(ClassIO.INSTANCE))
  .registerTypeAdapter(ImmutableList.class,
   adapt(ImmutableListIO.INSTANCE))
  .registerTypeAdapter(ImmutableSet.class, adapt(ImmutableSetIO.INSTANCE))
  .registerTypeAdapter(ModelBuilder.class,
   adapt(ModelBuilderIO.INSTANCE));
 return builder.create();
}
origin: rinde/RinSim

 .build();
final String serialized = ScenarioIO.write(s);
assertThat(serialized).isEqualTo(ser);
final Scenario deserialized = ScenarioIO.read(serialized);
assertThat(s).isEqualTo(deserialized);
origin: rinde/RinSim

/**
 * Allows to adapt the default reader ({@link #reader()}) by converting all
 * read scenarios. {@link ScenarioConverters} contains functions that can be
 * used for this.
 * @param converter A converter that transforms a scenario.
 * @return A new reader function.
 */
public static Function<Path, Scenario> readerAdapter(
  Function<Scenario, Scenario> converter) {
 return Functions.compose(converter, reader());
}
origin: rinde/RinSim

private static Gson initialize() {
 final GsonBuilder builder = new GsonBuilder();
 builder
  .registerTypeAdapter(ProblemClass.class, adapt(ProblemClassIO.INSTANCE))
  .registerTypeHierarchyAdapter(TimeWindowPolicy.class,
   adapt(TimeWindowHierarchyIO.INSTANCE))
  .registerTypeAdapter(Scenario.class, adapt(ScenarioObjIO.INSTANCE))
  .registerTypeAdapter(ParcelDTO.class, adapt(ParcelIO.INSTANCE))
  .registerTypeAdapter(VehicleDTO.class, adapt(VehicleIO.INSTANCE))
  .registerTypeAdapter(Point.class, new PointIO())
  .registerTypeAdapter(TimeWindow.class, new TimeWindowIO())
  .registerTypeAdapter(Unit.class, adapt(UnitIO.INSTANCE))
  .registerTypeAdapter(Supplier.class, adapt(SupplierIO.INSTANCE))
  .registerTypeHierarchyAdapter(Graph.class, adapt(GraphIO.INSTANCE))
  .registerTypeAdapter(Measure.class, adapt(MeasureIO.INSTANCE))
  .registerTypeHierarchyAdapter(Enum.class, adapt(EnumIO.INSTANCE))
  .registerTypeAdapter(StopCondition.class,
   adapt(StopConditionIO.INSTANCE))
  .registerTypeAdapter(Class.class, adapt(ClassIO.INSTANCE))
  .registerTypeAdapter(ImmutableList.class,
   adapt(ImmutableListIO.INSTANCE))
  .registerTypeAdapter(ImmutableSet.class, adapt(ImmutableSetIO.INSTANCE))
  .registerTypeAdapter(ModelBuilder.class,
   adapt(ModelBuilderIO.INSTANCE));
 return builder.create();
}
origin: rinde/RinSim

/**
 * Convert the specified JSON string to a {@link FabriRechtScenario}.
 * @param json The JSON string to parse.
 * @return A new instance of [@link {@link FabriRechtScenario}.
 */
public static FabriRechtScenario fromJson(String json) {
 return ScenarioIO.read(json, AutoValue_FabriRechtScenario.class);
}
origin: rinde/RinSim

final Scenario originalScenario = ScenarioIO.read(SERIALIZED_SCENARIO);
assertEquals("Change in scenario format detected.", originalScenario,
 scenario);
final String output = ScenarioIO.write(scenario);
final Scenario converted = ScenarioIO.read(output);
origin: rinde/RinSim

/**
 * Write the scenario to disk in JSON format.
 * @param scenario The scenario to write.
 * @param writer The writer to use.
 * @throws IOException When writing fails.
 */
public static void toJson(FabriRechtScenario scenario, Writer writer)
  throws IOException {
 final String s = ScenarioIO.write(scenario);
 writer.append(s);
 writer.close();
}
origin: rinde/RinSim

Builder() {
 configurationsSet = newLinkedHashSet();
 scenariosBuilder = ImmutableSet.builder();
 scenarioProviderBuilder = Optional.absent();
 fileReader = ScenarioIO.reader();
 resultListeners = newArrayList();
 showGui = false;
 repetitions = 1;
 seedRepetitions = 1;
 masterSeed = 0L;
 numThreads = Runtime.getRuntime().availableProcessors();
 numBatches = 1;
 compositeTaskSize = 1;
 computerType = Computers.LOCAL;
 postProc = PostProcessors.defaultPostProcessor();
 experimentOrdering = DEFAULT_EXPERIMENT_ORDERING;
}
origin: rinde/RinSim

@Override
public Predicate<?> doDeserialize(JsonElement json, Type typeOfT,
  JsonDeserializationContext context) {
 checkArgument(json.isJsonPrimitive());
 try {
  final Predicate<?> obj =
   (Predicate<?>) deserializeObject(json.getAsString());
  return obj;
 } catch (final IOException e) {
  throw new IllegalArgumentException(e);
 } catch (final ClassNotFoundException e) {
  throw new IllegalArgumentException(e);
 }
}
origin: com.github.rinde/rinsim-scenario

/**
 * Reads a {@link Scenario} from disk.
 * @param file The file to read from.
 * @return A {@link Scenario} instance.
 * @throws IOException When reading fails.
 */
public static Scenario read(Path file) throws IOException {
 return read(file, AutoValue_Scenario.class);
}
origin: rinde/RinSim

/**
 * Writes the specified {@link Scenario} to disk in the JSON format.
 * @param s The scenario.
 * @param to The file to write to.
 * @throws IOException In case anything went wrong during writing the
 *           scenario.
 */
public static void write(Scenario s, Path to) throws IOException {
 Files.write(to, Splitter.on(System.lineSeparator()).split(write(s)),
  Charsets.UTF_8);
}
origin: com.github.rinde/rinsim-experiment

Builder() {
 configurationsSet = newLinkedHashSet();
 scenariosBuilder = ImmutableSet.builder();
 scenarioProviderBuilder = Optional.absent();
 fileReader = ScenarioIO.reader();
 resultListeners = newArrayList();
 showGui = false;
 repetitions = 1;
 seedRepetitions = 1;
 masterSeed = 0L;
 numThreads = Runtime.getRuntime().availableProcessors();
 numBatches = 1;
 compositeTaskSize = 1;
 computerType = Computers.LOCAL;
 postProc = PostProcessors.defaultPostProcessor();
 experimentOrdering = DEFAULT_EXPERIMENT_ORDERING;
}
origin: com.github.rinde/rinsim-experiment

@SuppressWarnings("null")
@Override
public Scenario get() {
 if (localCache == null) {
  localCache = (Scenario) ScenarioIO.read(
   serializedScenario, scenarioClass);
 }
 return localCache;
}
origin: com.github.rinde/rinsim-scenario

/**
 * Writes the specified {@link Scenario} to disk in the JSON format.
 * @param s The scenario.
 * @param to The file to write to.
 * @throws IOException In case anything went wrong during writing the
 *           scenario.
 */
public static void write(Scenario s, Path to) throws IOException {
 Files.write(to, Splitter.on(System.lineSeparator()).split(write(s)),
  Charsets.UTF_8);
}
com.github.rinde.rinsim.scenarioScenarioIO

Javadoc

Provides utilities for reading and writing scenario files.

Most used methods

  • read
    Reads a scenario from disk.
  • write
    Writes the specified Scenario to disk in the JSON format.
  • reader
    Creates a Function that converts Paths into the specified subclass of Scenario.
  • adapt
  • deserializeObject
  • readerAdapter
    Allows to adapt the default reader ( #reader()) by converting all read scenarios. ScenarioConverters
  • serializeObject

Popular in Java

  • Reactive rest calls using spring rest template
  • notifyDataSetChanged (ArrayAdapter)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • setScale (BigDecimal)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Best plugins for Eclipse
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