Skip to content

Commit

Permalink
try release icefrog
Browse files Browse the repository at this point in the history
  • Loading branch information
HbnKing committed Dec 27, 2023
1 parent 9e07d2b commit 4434459
Show file tree
Hide file tree
Showing 29 changed files with 2,173 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.bson.types.CodeWithScope;


@Deprecated
public class CodeWithScopeCodec implements Codec<CodeWithScope> {
private final Codec<Document> documentCodec;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.bson.codecs.Codec;
import org.bson.codecs.DecoderContext;
import org.bson.codecs.EncoderContext;

import java.util.Date;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.StringWriter;


@Deprecated
public class JsonObjectCodec implements Codec<JsonObject> {
private final JsonWriterSettings writerSettings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.bson.json.JsonObject;


@Deprecated
public final class JsonObjectCodecProvider implements CodecProvider {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.bson.types.MaxKey;


@Deprecated
public class MaxKeyCodec implements Codec<MaxKey> {
@Override
public void encode(final BsonWriter writer, final MaxKey value, final EncoderContext encoderContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.bson.types.MinKey;


@Deprecated
public class MinKeyCodec implements Codec<MinKey> {
@Override
public void encode(final BsonWriter writer, final MinKey value, final EncoderContext encoderContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
package com.whaleal.mars.codecs.pojo;


import com.whaleal.icefrog.core.util.StrUtil;
import com.whaleal.mars.util.StrUtil;
import com.whaleal.mars.codecs.Convention;
import com.whaleal.mars.codecs.pojo.annotations.Entity;
import com.whaleal.mars.util.Assert;
import org.bson.codecs.pojo.IdGenerator;

import java.lang.annotation.Annotation;
import java.util.*;

import static com.whaleal.icefrog.core.lang.Precondition.notNull;
import static java.lang.String.format;
import static java.util.Collections.*;

Expand Down Expand Up @@ -71,7 +71,8 @@ public class EntityModelBuilder<T> {


public EntityModelBuilder(final Class<T> type) {
MarsBuilderHelper.configureClassModelBuilder(this, notNull("type", type));
Assert.notNull(type);
MarsBuilderHelper.configureClassModelBuilder(this, type);
initCollectionName();
}

Expand All @@ -98,7 +99,8 @@ public IdGenerator<?> getIdGenerator() {


public EntityModelBuilder<T> instanceCreatorFactory(final InstanceCreatorFactory<T> instanceCreatorFactory) {
this.instanceCreatorFactory = notNull("instanceCreatorFactory", instanceCreatorFactory);
Assert.notNull(instanceCreatorFactory);
this.instanceCreatorFactory = instanceCreatorFactory ;
return this;
}

Expand All @@ -114,7 +116,8 @@ public InstanceCreatorFactory<T> getInstanceCreatorFactory() {
* @return
*/
public EntityModelBuilder<T> type(final Class<T> type) {
this.type = notNull("type", type);
Assert.notNull(type);
this.type = type ;
return this;
}

Expand All @@ -125,7 +128,8 @@ public Class<T> getType() {


public EntityModelBuilder<T> conventions(final List<Convention> conventions) {
this.conventions = notNull("conventions", conventions);
Assert.notNull(conventions);
this.conventions =conventions;
return this;
}

Expand All @@ -136,7 +140,8 @@ public List<Convention> getConventions() {


public EntityModelBuilder<T> annotations(final List<Annotation> annotations) {
this.annotations = notNull("annotations", annotations);
Assert.notNull(annotations);
this.annotations = annotations;
return this;
}

Expand Down Expand Up @@ -187,12 +192,13 @@ public String getIdPropertyName() {


public boolean removeProperty(final String propertyName) {
return propertyModelBuilders.remove(getProperty(notNull("propertyName", propertyName)));
Assert.notNull(propertyName);
return propertyModelBuilders.remove(getProperty( propertyName));
}


public PropertyModelBuilder<?> getProperty(final String propertyName) {
notNull("propertyName", propertyName);
Assert.notNull(propertyName);
for (PropertyModelBuilder<?> propertyModelBuilder : propertyModelBuilders) {
if (propertyModelBuilder.getName().equals(propertyName)) {
return propertyModelBuilder;
Expand Down Expand Up @@ -229,7 +235,8 @@ EntityModelBuilder<T> propertyNameToTypeParameterMap(final Map<String, TypeParam
EntityModelBuilder<T> addProperty(final PropertyModelBuilder<?> propertyModelBuilder) {

if(propertyModelBuilder.isReadable() || propertyModelBuilder.isWritable()){
propertyModelBuilders.add(notNull("propertyModelBuilder", propertyModelBuilder));
Assert.notNull(propertyModelBuilder);
propertyModelBuilders.add(propertyModelBuilder);
}

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import com.whaleal.icefrog.core.lang.Pair;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -45,22 +46,22 @@ static <V> TypeData<V> specializeTypeData(final TypeData<V> typeData, final List
return typeData;
}

Map<Integer, Pair<Integer, TypeParameterMap> > propertyToClassParamIndexMap = typeParameterMap.getPropertyToClassParamIndexMap();
Pair<Integer, TypeParameterMap> classTypeParamRepresentsWholeField = propertyToClassParamIndexMap.get(-1);
Map<Integer, AbstractMap.SimpleEntry<Integer, TypeParameterMap> > propertyToClassParamIndexMap = typeParameterMap.getPropertyToClassParamIndexMap();
AbstractMap.SimpleEntry<Integer, TypeParameterMap> classTypeParamRepresentsWholeField = propertyToClassParamIndexMap.get(-1);
if (classTypeParamRepresentsWholeField != null) {

if(classTypeParamRepresentsWholeField.left() ==null){
if(classTypeParamRepresentsWholeField.getKey() ==null){
throw new IllegalStateException("Invalid state, the whole class cannot be represented by a subtype.");
}

return (TypeData<V>) typeParameters.get(classTypeParamRepresentsWholeField.left());
return (TypeData<V>) typeParameters.get(classTypeParamRepresentsWholeField.getKey());
} else {
return getTypeData(typeData, typeParameters, propertyToClassParamIndexMap);
}
}

private static <V> TypeData<V> getTypeData(final TypeData<V> typeData, final List<TypeData<?>> specializedTypeParameters,
final Map<Integer, Pair<Integer, TypeParameterMap> > propertyToClassParamIndexMap) {
final Map<Integer, AbstractMap.SimpleEntry<Integer, TypeParameterMap> > propertyToClassParamIndexMap) {
List<TypeData<?>> subTypeParameters = new ArrayList<>(typeData.getTypeParameters());
for (int i = 0; i < typeData.getTypeParameters().size(); i++) {
subTypeParameters.set(i, getTypeData(subTypeParameters.get(i), specializedTypeParameters, propertyToClassParamIndexMap, i));
Expand All @@ -69,25 +70,25 @@ private static <V> TypeData<V> getTypeData(final TypeData<V> typeData, final Lis
}

private static TypeData<?> getTypeData(final TypeData<?> typeData, final List<TypeData<?>> specializedTypeParameters,
final Map<Integer, Pair<Integer, TypeParameterMap> > propertyToClassParamIndexMap,
final Map<Integer, AbstractMap.SimpleEntry<Integer, TypeParameterMap> > propertyToClassParamIndexMap,
final int index) {
if (!propertyToClassParamIndexMap.containsKey(index)) {
return typeData;
}

Pair< Integer, TypeParameterMap > integerTypeParameterMapPair = propertyToClassParamIndexMap.get(index);
AbstractMap.SimpleEntry< Integer, TypeParameterMap > integerTypeParameterMapPair = propertyToClassParamIndexMap.get(index);

Function<Integer,TypeData<?>> function = new Function<Integer, TypeData<?>>() {
@Override
public TypeData<?> apply( Integer num ) {
if (typeData.getTypeParameters().isEmpty()) {
// Represents the whole typeData
return specializedTypeParameters.get(integerTypeParameterMapPair.left());
return specializedTypeParameters.get(integerTypeParameterMapPair.getKey());
} else {
// Represents a single nested type parameter within this typeData
TypeData.Builder<?> builder = TypeData.builder(typeData.getType());
List<TypeData<?>> typeParameters = new ArrayList<>(typeData.getTypeParameters());
typeParameters.set(index, specializedTypeParameters.get(integerTypeParameterMapPair.left()));
typeParameters.set(index, specializedTypeParameters.get(integerTypeParameterMapPair.getKey()));
builder.addTypeParameters(typeParameters);
return builder.build();
}
Expand All @@ -103,7 +104,7 @@ public TypeData<?> apply( TypeParameterMap r ) {
}
};

return integerTypeParameterMapPair.left() !=null ? function.apply(integerTypeParameterMapPair.left()):function1.apply(integerTypeParameterMapPair.right());
return integerTypeParameterMapPair.getKey() !=null ? function.apply(integerTypeParameterMapPair.getKey()):function1.apply(integerTypeParameterMapPair.getValue());
}

private MarsSpecializationHelper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.lang.annotation.Annotation;
import java.util.List;

import static com.whaleal.icefrog.core.lang.Precondition.notNull;
import static com.whaleal.mars.util.Assert.notNull;
import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
Expand Down Expand Up @@ -110,7 +110,7 @@ Codec<T> getCodec() {


public PropertyModelBuilder<T> propertySerialization(final PropertySerialization<T> propertySerialization) {
this.propertySerialization = notNull("propertySerialization", propertySerialization);
this.propertySerialization = notNull(propertySerialization);
return this;
}

Expand All @@ -126,7 +126,7 @@ public List<Annotation> getReadAnnotations() {


public PropertyModelBuilder<T> readAnnotations(final List<Annotation> annotations) {
this.readAnnotations = unmodifiableList(notNull("annotations", annotations));
this.readAnnotations = unmodifiableList(notNull( annotations));
return this;
}

Expand Down Expand Up @@ -209,7 +209,7 @@ public String toString() {
}

PropertyModelBuilder<T> propertyName(final String propertyName) {
this.name = notNull("propertyName", propertyName);
this.name = notNull( propertyName);
return this;
}

Expand All @@ -218,7 +218,7 @@ TypeData<T> getTypeData() {
}

PropertyModelBuilder<T> typeData(final TypeData<T> typeData) {
this.typeData = notNull("typeData", typeData);
this.typeData = notNull( typeData);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.lang.reflect.*;
import java.util.*;

import static com.whaleal.icefrog.core.lang.Precondition.notNull;
import static com.whaleal.mars.util.Assert.notNull;
import static java.lang.String.format;


Expand All @@ -45,7 +45,7 @@ public final class TypeData< T > implements TypeWithTypeParameters< T > {


public static < T > Builder< T > builder( final Class< T > type ) {
return new Builder< T >(notNull("type", type));
return new Builder< T >(notNull( type));
}

public static TypeData< ? > newInstance( final Method method ) {
Expand Down Expand Up @@ -114,13 +114,13 @@ private Builder( final Class< T > type ) {


public < S > Builder< T > addTypeParameter( final TypeData< S > typeParameter ) {
typeParameters.add(notNull("typeParameter", typeParameter));
typeParameters.add(notNull( typeParameter));
return this;
}


public Builder< T > addTypeParameters( final List< TypeData< ? > > typeParameters ) {
notNull("typeParameters", typeParameters);
notNull(typeParameters);
for (TypeData< ? > typeParameter : typeParameters) {
addTypeParameter(typeParameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@
package com.whaleal.mars.codecs.pojo;


import com.whaleal.icefrog.core.lang.Pair;
import com.whaleal.mars.util.Assert;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;

import static com.whaleal.icefrog.core.lang.Precondition.notNull;
import static java.util.Collections.unmodifiableMap;


final class TypeParameterMap {
private final Map<Integer, Pair<Integer, TypeParameterMap> > propertyToClassParamIndexMap;
private final Map<Integer, AbstractMap.SimpleEntry<Integer, TypeParameterMap> > propertyToClassParamIndexMap;


static Builder builder() {
return new Builder();
}


Map<Integer, Pair<Integer, TypeParameterMap> > getPropertyToClassParamIndexMap() {
Map<Integer, AbstractMap.SimpleEntry<Integer, TypeParameterMap> > getPropertyToClassParamIndexMap() {
return propertyToClassParamIndexMap;
}

Expand All @@ -58,26 +58,30 @@ boolean hasTypeParameters() {


static final class Builder {
private final Map<Integer, Pair<Integer, TypeParameterMap> > propertyToClassParamIndexMap = new HashMap<>();
private final Map<Integer, AbstractMap.SimpleEntry<Integer, TypeParameterMap> > propertyToClassParamIndexMap = new HashMap<>();

private Builder() {
}


Builder addIndex(final int classTypeParameterIndex) {
propertyToClassParamIndexMap.put(-1, new Pair<>(notNull("value", classTypeParameterIndex), null));

Assert.notNull(classTypeParameterIndex);
propertyToClassParamIndexMap.put(-1, new AbstractMap.SimpleEntry<>(classTypeParameterIndex, null));
return this;
}


Builder addIndex(final int propertyTypeParameterIndex, final int classTypeParameterIndex) {
propertyToClassParamIndexMap.put(propertyTypeParameterIndex, new Pair<>(notNull("value", classTypeParameterIndex), null));
Assert.notNull(classTypeParameterIndex);
propertyToClassParamIndexMap.put(propertyTypeParameterIndex, new AbstractMap.SimpleEntry<>( classTypeParameterIndex, null));
return this;
}


Builder addIndex(final int propertyTypeParameterIndex, final TypeParameterMap typeParameterMap) {
propertyToClassParamIndexMap.put(propertyTypeParameterIndex, new Pair<>(null, notNull("value", typeParameterMap)));
Assert.notNull(typeParameterMap);
propertyToClassParamIndexMap.put(propertyTypeParameterIndex, new AbstractMap.SimpleEntry<>(null, typeParameterMap));
return this;
}

Expand Down Expand Up @@ -120,7 +124,7 @@ public int hashCode() {
return getPropertyToClassParamIndexMap().hashCode();
}

private TypeParameterMap(final Map<Integer, Pair<Integer, TypeParameterMap> > propertyToClassParamIndexMap) {
private TypeParameterMap(final Map<Integer, AbstractMap.SimpleEntry<Integer, TypeParameterMap> > propertyToClassParamIndexMap) {
this.propertyToClassParamIndexMap = unmodifiableMap(propertyToClassParamIndexMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
package com.whaleal.mars.core.aggregation;


import com.whaleal.icefrog.core.lang.Precondition;

import com.whaleal.mars.core.aggregation.expressions.Expressions;
import com.whaleal.mars.core.aggregation.expressions.impls.Expression;
import com.whaleal.mars.core.aggregation.stages.*;
import com.whaleal.mars.core.query.filters.Filter;
import com.whaleal.mars.session.option.AggregationOptions;
import com.whaleal.mars.util.Assert;
import org.bson.Document;

import java.util.ArrayList;
Expand Down Expand Up @@ -63,12 +64,12 @@ private AggregationPipeline(Class<T> outputType ,List<Stage> stages ){
}

public static <T> AggregationPipeline<T> create(Class<T> outputType,List<Stage> stages){
Precondition.checkNotNull(outputType,"outputType can't be null in AggregationPipeline") ;
Assert.checkNotNull(outputType,"outputType can't be null in AggregationPipeline") ;
return new AggregationPipeline<T>(outputType,stages);
}

public static <T> AggregationPipeline<T> create(Class<T> outputType){
Precondition.checkNotNull(outputType,"outputType can't be null in AggregationPipeline") ;
Assert.checkNotNull(outputType,"outputType can't be null in AggregationPipeline") ;
return new AggregationPipeline<T>(outputType);
}

Expand Down
Loading

0 comments on commit 4434459

Please sign in to comment.