<commit_before>/*
 * Copyright 2014 Open Networking Laboratory
 *
 * 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 org.onlab.onos.net.intent.constraint;

import com.google.common.base.MoreObjects;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.intent.Constraint;
import org.onlab.onos.net.resource.LinkResourceService;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Objects;

/**
 * Constraint that evaluates the latency through a path.
 */
public class LatencyConstraint implements Constraint {

    // TODO: formalize the key for latency all over the codes.
    private static final String LATENCY_KEY = "latency";

    private final Duration latency;

    /**
     * Creates a new constraint to keep under specified latency through a path.
     * @param latency latency to be kept
     */
    public LatencyConstraint(Duration latency) {
        this.latency = latency;
    }

    public Duration getLatency() {
        return latency;
    }

    @Override
    public double cost(Link link, LinkResourceService resourceService) {
        String value = link.annotations().value(LATENCY_KEY);

        double latencyInMicroSec;
        try {
            latencyInMicroSec = Double.parseDouble(value);
        } catch (NumberFormatException e) {
            latencyInMicroSec = 1.0;<commit_msg>Modify getter name to match the project naming convention<commit_after>/*
 * Copyright 2014 Open Networking Laboratory
 *
 * 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 org.onlab.onos.net.intent.constraint;

import com.google.common.base.MoreObjects;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.intent.Constraint;
import org.onlab.onos.net.resource.LinkResourceService;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Objects;

/**
 * Constraint that evaluates the latency through a path.
 */
public class LatencyConstraint implements Constraint {

    // TODO: formalize the key for latency all over the codes.
    private static final String LATENCY_KEY = "latency";

    private final Duration latency;

    /**
     * Creates a new constraint to keep under specified latency through a path.
     * @param latency latency to be kept
     */
    public LatencyConstraint(Duration latency) {
        this.latency = latency;
    }

    public Duration latency() {
        return latency;
    }

    @Override
    public double cost(Link link, LinkResourceService resourceService) {
        String value = link.annotations().value(LATENCY_KEY);

        double latencyInMicroSec;
        try {
            latencyInMicroSec = Double.parseDouble(value);
        } catch (NumberFormatException e) {
            latencyInMicroSec = 1.0;
{'fraction_non_alphanumeric': 0.07947712418300654, 'fraction_numerical': 0.00522875816993464, 'mean_word_length': 3.3427922814982973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7253367', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1003, 'n_words': 373}