/* * Copyright 2017 TWO SIGMA OPEN SOURCE, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.twosigma.jupyter; import java.util.Map; import java.util.Optional; import static com.google.common.base.Preconditions.checkNotNull; import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals; import static org.apache.commons.lang3.builder.HashCodeBuilder.reflectionHashCode; import static org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString; public class KernelParameters { public static final String KERNEL_PARAMETERS = "beakerx_kernel_parameters"; private Map<String, Object> params; public KernelParameters(Map<String, Object> params) { this.params = checkNotNull(params); } public Map<String, Object> getParams() { return params; } public <T> Optional<T> getParam(String key, Class<T> clazz) { if (params.containsKey(key)) { return Optional.of(clazz.cast(params.get(key))); } return Optional.empty(); } @Override public boolean equals(Object o) { return reflectionEquals(this, o); } @Override public int hashCode() { return reflectionHashCode(this); } @Override public String toString() { return reflectionToString(this); } }