MATSIM
LazyAllocationAttributes.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * Attributes.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.utils.objectattributes.attributable;
23 
24 import java.util.*;
25 import java.util.function.Consumer;
26 import java.util.function.Supplier;
27 
31 public final class LazyAllocationAttributes implements Attributes {
32 
33  private final Consumer<Attributes> consumer;
34  private final Supplier<Attributes> supplier;
35 
36  public LazyAllocationAttributes(final Consumer<Attributes> consumer, final Supplier<Attributes> supplier) {
37  this.consumer = consumer;
38  this.supplier = supplier;
39  }
40 
41  @Override
42  public Object putAttribute(String attribute, Object value) {
43  Attributes attributes = this.supplier.get();
44  if (Objects.isNull(attributes)) {
45  attributes = new AttributesImpl();
46  this.consumer.accept(attributes);
47  }
48  attributes.putAttribute(attribute, value);
49  return null;
50  }
51 
52  @Override
53  public Object getAttribute(String attribute) {
54  return null;
55  }
56 
57  @Override
58  public Object removeAttribute(String attribute) {
59  return null;
60  }
61 
62  @Override
63  public void clear() {
64  }
65 
66  @Override
67  public Map<String, Object> getAsMap() {
68  return Collections.emptyMap();
69  }
70 
71  @Override
72  public int size() {
73  return 0;
74  }
75 
76  @Override
77  public boolean isEmpty() {
78  return true;
79  }
80 }
Object putAttribute(final String attribute, final Object value)
LazyAllocationAttributes(final Consumer< Attributes > consumer, final Supplier< Attributes > supplier)