All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.immutables.fixture.encoding.defs.TableEncoding Maven / Gradle / Ivy

There is a newer version: 2.10.1
Show newest version
/*
   Copyright 2016 Immutables Authors and Contributors

   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.immutables.fixture.encoding.defs;

import org.immutables.encode.Encoding.StandardNaming;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Table;
import java.io.Serializable;
import org.immutables.encode.Encoding;

@Encoding
class TableEncoding {
  public static final Void SMART_NULL = null;
  private static final String SILLY_CONSTANT = "{T}";

  @Encoding.Impl
  private final ImmutableTable value = ImmutableTable.of();
  private final int tableSize = value.size();

  @Encoding.Expose
  Table accessor() {
    return value;
  }

  int getTableSize() {
    return tableSize;
  }

  @Override
  public String toString() {
    String actuallyInvolvedToString = value.toString() + SILLY_CONSTANT;
    return actuallyInvolvedToString;
  }

  @Override
  public int hashCode() {
    return value.hashCode() + 1;
  }

  boolean equals(TableEncoding other) {
    return value.equals(other.value);
  }

  static  T helper(T param) throws java.lang.Exception, java.lang.Error {
    return param;
  }

  @Encoding.Of
  static  ImmutableTable init(Table table) {
    return ImmutableTable.copyOf(table);
  }

  @Encoding.Copy
  @Encoding.Naming("with*Put")
  public ImmutableTable withPut(R row, C column, V value) {
    return ImmutableTable.builder()
        .put(row, column, value)
        .build();
  }

  @Encoding.Naming("*CellSet")
  public ImmutableSet> cellSet() {
    return value.cellSet();
  }

  @Encoding.Builder
  static class Builder {
    private static final Object DILLY_CONSTANT = "{D}";
    private final ImmutableTable.Builder builder = ImmutableTable.builder();

    @Encoding.Naming(standard = StandardNaming.PUT)
    @Encoding.Init
    void put(R row, C column, V value) {
      builder.put(row, column, value);
    }

    @Encoding.Naming(standard = StandardNaming.PUT_ALL)
    @Encoding.Init
    @Encoding.Copy
    void putAll(Table table) {
      builder.putAll(table);
      DILLY_CONSTANT.toString();// just reference constant
    }

    @Encoding.Build
    ImmutableTable build() {
      return builder.build();
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy