
br.com.objectos.xls.pojo.plugin.SheetMethodWidth Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2015 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.xls.pojo.plugin;
import br.com.objectos.code.AnnotationInfo;
import br.com.objectos.pojo.plugin.Property;
import br.com.objectos.xls.Unit;
import br.com.objectos.xls.pojo.Width;
import com.squareup.javapoet.MethodSpec;
/**
* @author [email protected] (Marcio Endo)
*/
abstract class SheetMethodWidth {
private static final SheetMethodWidth SKIP = new Skip();
private SheetMethodWidth() {
}
public static SheetMethodWidth of(Property property) {
return property.annotationInfo(Width.class)
.map(Present::of)
.orElse(SKIP);
}
public abstract void write(MethodSpec.Builder write);
private static class Present extends SheetMethodWidth {
private final int value;
private final Unit unit;
private Present(int value, Unit unit) {
this.value = value;
this.unit = unit;
}
public static SheetMethodWidth of(AnnotationInfo annotationInfo) {
int value = annotationInfo.intValue("value", 0);
Unit unit = annotationInfo.enumValue(Unit.class, "unit", Unit.CHAR);
return new Present(value, unit);
}
@Override
public void write(MethodSpec.Builder write) {
write.addCode(" .size($L, $T.$L)", value, Unit.class, unit);
}
}
private static class Skip extends SheetMethodWidth {
@Override
public void write(MethodSpec.Builder write) {
write.addCode(" .skip()");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy