<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.apache.directory.server.dhcp.service.store;

import com.google.common.base.Preconditions;
import java.net.InetAddress;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.anarres.dhcp.common.address.InterfaceAddress;
import org.apache.directory.server.dhcp.DhcpException;
import org.apache.directory.server.dhcp.messages.DhcpMessage;
import org.apache.directory.server.dhcp.messages.HardwareAddress;
import org.apache.directory.server.dhcp.messages.MessageType;
import org.apache.directory.server.dhcp.service.manager.AbstractLeaseManager;

/**
 *
 * @author shevek
 */
public class FixedStoreLeaseManager extends AbstractLeaseManager {

    private final ConcurrentMap<HardwareAddress, Lease> leases = new ConcurrentHashMap<HardwareAddress, Lease>();

    @Nonnull
    public ConcurrentMap<HardwareAddress, Lease> getLeases() {
        return leases;
    }

    @CheckForNull
    public Lease getLease(@Nonnull HardwareAddress hardwareAddress) {
        Preconditions.checkNotNull(hardwareAddress, "HardwareAddress was null.");
        return leases.get(hardwareAddress);
    }

    @Nonnull
    public Lease addLease(@Nonnull HardwareAddress hardwareAddress, @Nonnull Lease lease) {
        leases.put(hardwareAddress, lease);
        return lease;
    }

    @Nonnull
    public Lease addLease(@Nonnull HardwareAddress hardwareAddress, @Nonnull InetAddress clientAddress) {
        Lease lease = new Lease();
        lease.setClientAddress(clientAddress);
        return addLease(hardwareAddress, lease);
    }

    @Override
    public DhcpMessage leaseOffer(InterfaceAddress localAddress,
            DhcpMessage request, InetAddress networkAddress,
            InetAddress clientRequestedAddress, long clientRequestedExpirySecs) throws DhcpException {<commit_msg>Allow creation of a Lease with an InterfaceAddress.<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.apache.directory.server.dhcp.service.store;

import com.google.common.base.Preconditions;
import java.net.InetAddress;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.anarres.dhcp.common.address.InterfaceAddress;
import org.apache.directory.server.dhcp.DhcpException;
import org.apache.directory.server.dhcp.messages.DhcpMessage;
import org.apache.directory.server.dhcp.messages.HardwareAddress;
import org.apache.directory.server.dhcp.messages.MessageType;
import org.apache.directory.server.dhcp.options.OptionsField;
import org.apache.directory.server.dhcp.options.perinterface.BroadcastAddress;
import org.apache.directory.server.dhcp.options.vendor.SubnetMask;
import org.apache.directory.server.dhcp.service.manager.AbstractLeaseManager;

/**
 *
 * @author shevek
 */
public class FixedStoreLeaseManager extends AbstractLeaseManager {

    private final ConcurrentMap<HardwareAddress, Lease> leases = new ConcurrentHashMap<HardwareAddress, Lease>();

    @Nonnull
    public ConcurrentMap<HardwareAddress, Lease> getLeases() {
        return leases;
    }

    @CheckForNull
    public Lease getLease(@Nonnull HardwareAddress hardwareAddress) {
        Preconditions.checkNotNull(hardwareAddress, "HardwareAddress was null.");
        return leases.get(hardwareAddress);
    }

    @Nonnull
    public Lease addLease(@Nonnull HardwareAddress hardwareAddress, @Nonnull Lease lease) {
        leases.put(hardwareAddress, lease);
        return lease;
    }

    @Nonnull
    public Lease addLease(@Nonnull HardwareAddress hardwareAddress, @Nonnull InetAddress clientAddress) {
        Lease lease = new Lease();
        lease.setClientAddress(clientAddress);
        return addLease(hardwareAddress, lease);
    }

    @Nonnull
    public Lease addLease(@Nonnull HardwareAddress hardwareAddress, @Nonnull InterfaceAddress interfaceAddress) {
        Lease lease = addLease(hardwareAddress, interfaceAddress.getAddress());
        OptionsField options = lease.getOptions();
        options.setAddressOption(SubnetMask.class, interfaceAddress.getNetmaskAddress());
        options.setAddressOption(BroadcastAddress.class, interfaceAddress.getBroadcastAddress());
        return lease;
    }

    @Override
    public DhcpMessage leaseOffer(InterfaceAddress localAddress,
            DhcpMessage request, InetAddress networkAddress,
            InetAddress clientRequestedAddress, long clientRequestedExpirySecs) throws DhcpException {
{'fraction_non_alphanumeric': 0.08328255128986391, 'fraction_numerical': 0.0, 'mean_word_length': 4.545045045045045, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5401510', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1334, 'n_words': 299}