/*
(non-Javadoc)
@see org.springframework.hateoas.EntityLinks#linkFor(java.lang.Class, java.lang.Object[])
353778
@Override
	public LinkBuilder linkFor(Class<?> type, Object... parameters) {
		return getPluginFor(type).linkFor(type, parameters);
	}
1052445
@Override
	public Optional<Link> findLinkWithRel(LinkRelation relation, String representation) {

		Assert.notNull(relation, "LinkRelation must not be null!");
		Assert.notNull(representation, "Representation must not be null!");

		return relation.isSameAs(IanaLinkRelations.SELF) //
				? findSelfLink(representation) //
				: super.findLinkWithRel(relation, representation);
	}
825289
@Override
	public LinkRelation getCollectionResourceRelFor(Class<?> type) {
		return LinkRelation.of(StringUtils.uncapitalize(type.getSimpleName()) + "List");
	}
1345818
public void linkOneToMany(Object obj, CollectionDescriptor cod, boolean insert)
    {
        Object referencedObjects = cod.getPersistentField().get(obj);
        storeAndLinkOneToMany(true, obj, cod,referencedObjects, insert);
    }
509572
public static function set_links( Base $entity, $link, Container $new = null )
    {

        $repository = $entity->r();
        if( !$repository->hasLink( $link, $detail ) ) {
            throw new EntityLinkException("Bad link `{$link}`");
        }

        if( is_null( $new ) ) {
            $new = new Container();
        }

        // check container is of the correct type
        $class = $new->classGet();
        $classUnqualified = get_unqualified_class( $class );
        if( $class and !in_array( $classUnqualified, $detail->foreignEntities ) ) {
            $foreignEntities = implode( ', ', $detail->foreignEntities );
            throw new EntityLinkException(
                "Passed container is of type `{$classUnqualified}` and we need one of type(s) {$foreignEntities}"
            );
        }

        // Build array key'd, $existing, like so
        // array(
        //     spl_obj_hash( 'link' ) => spl_obj_hash( 'entity' )
        // )

        $existingLinks = $repository->linksGet( $entity, $link, $classUnqualified, null, false );

        $existing = array();
        foreach( $existingLinks as $splHashLink => $link ) {
            $existing[$splHashLink] = spl_object_hash( $link[$detail->refForeign[0]] );
        }

        $newKeys = array_keys( $new->collection );

        $newKeys = array();
        $ordering = array(); $n = 0;
        foreach( $new as $splHashEntity => $_ ) {
            $newKeys[] = $splHashEntity;
            $ordering[$splHashEntity] = $n++;
        }

        // operations
        $toRemove = array_diff( $existing, $newKeys );
        $toAdd = array_diff( $newKeys, $existing );
        $unchanged = array_intersect( $existing, $newKeys );

        //
        $numModified = 0;

        // remove
        while( list($splHashLink,) = each( $toRemove ) ) {
            $existingLinks[$splHashLink][$detail->refSource[1]] = null;
            $existingLinks[$splHashLink][$detail->refForeign[0]] = null;
            $numModified++;
        }

        // add
        $linkRepo = Repository::init( $link );
        foreach( $toAdd as $key ) {

            $link = $linkRepo->make();
            $link[$detail->refSource[1]] = $entity;
            $link[$detail->refForeign[0]] = $new[$key];

            if( isset( $detail->sortColumn ) ) {
                $link[$detail->sortColumn] = $ordering[$key];
            }

            $numModified++;

        }

        if( isset( $detail->sortColumn ) ) {
            foreach( $unchanged as $linkKey => $entityKey ) {
                $numModified += $existingLinks[$linkKey]->set( $detail->sortColumn, $ordering[$entityKey] ) ? 1 : 0;
            }
        }

        return $numModified;

    }
1189994
@Override
	public ControllerLinkBuilder linkTo(Class<?> controller, Method method, Object... parameters) {
		return ControllerLinkBuilder.linkTo(controller, method, parameters);
	}
877906
public Href with(final Object key, final Object value) {
        final SortedMap<String, List<String>> map = new TreeMap<>(this.params);
        if (!map.containsKey(key.toString())) {
            map.put(key.toString(), new LinkedList<>());
        }
        map.get(key.toString()).add(value.toString());
        return new Href(this.uri, map, this.fragment);
    }
609533
private Content getClassLinks(LinkInfoImpl.Kind context, Collection<?> list) {
        Content dd = new HtmlTree(HtmlTag.DD);
        boolean isFirst = true;
        for (Object type : list) {
            if (!isFirst) {
                Content separator = new StringContent(", ");
                dd.addContent(separator);
            } else {
                isFirst = false;
            }
            // TODO: should we simply split this method up to avoid instanceof ?
            if (type instanceof TypeElement) {
                Content link = getLink(
                        new LinkInfoImpl(configuration, context, (TypeElement)(type)));
                dd.addContent(HtmlTree.CODE(link));
            } else {
                Content link = getLink(
                        new LinkInfoImpl(configuration, context, ((TypeMirror)type)));
                dd.addContent(HtmlTree.CODE(link));
            }
        }
        return dd;
    }
843329
@Override
	public Link linkToItemResource(Class<?> type, Object id) {
		return getPluginFor(type).linkToItemResource(type, id);
	}
452026
@Override
  public final String getFor(final Class<?> pClass, final String pThingName) {
    if ("entityEdit".equals(pThingName) && pClass == Cart.class) {
      return null;
    } else if (pClass == CustOrder.class) {
      if ("entitySave".equals(pThingName)) {
        return PrCuOrSv.class.getSimpleName();
      } else if ("entityEdit".equals(pThingName)
        || "entityPrint".equals(pThingName)) {
        return PrcEntityRetrieve.class.getSimpleName();
      }
      return null;
    } else if ("entityEdit".equals(pThingName)
      || "entityConfirmDelete".equals(pThingName)) {
      return getForRetrieveForEditDelete(pClass);
    } else if ("entityCopy".equals(pThingName)) {
      return getForCopy(pClass);
    } else if ("entityPrint".equals(pThingName)) {
      return getForPrint(pClass);
    } else if ("entitySave".equals(pThingName)) {
      return getForSave(pClass);
    } else if ("entityFDelete".equals(pThingName)) {
      return getForFDelete(pClass);
    } else if ("entityEFDelete".equals(pThingName)) {
      return getForEFDelete(pClass);
    } else if ("entityFSave".equals(pThingName)) {
      return getForFSave(pClass);
    } else if ("entityEFSave".equals(pThingName)) {
      return getForEFSave(pClass);
    } else if ("entityFolDelete".equals(pThingName)) {
      return getForFolDelete(pClass);
    } else if ("entityFolSave".equals(pThingName)) {
      return getForFolSave(pClass);
    } else if ("entityDelete".equals(pThingName)) {
      return getForDelete(pClass);
    } else if ("entityCreate".equals(pThingName)) {
      return getForCreate(pClass);
    }
    return null;
  }
883157
public boolean isLinked(ParaObject obj, String type2, String id2) {
		if (obj == null || obj.getId() == null || type2 == null || id2 == null) {
			return false;
		}
		String url = Utils.formatMessage("{0}/links/{1}/{2}", obj.getObjectURI(), type2, id2);
		Boolean result = getEntity(invokeGet(url, null), Boolean.class);
		return result != null && result;
	}
1076740
@Override
  public final String getFor(final Class<?> pClass, final String pThingName) {
    if ("list".equals(pThingName)) {
      return "waPrcEntitiesPage";
    }
    return null;
  }
109683
@Override
	public <L extends LinksInformation> L as(Class<L> linksClass) {
		try {
			ObjectReader reader = mapper.readerFor(linksClass);
			return reader.readValue(data);
		} catch (IOException e) {
			throw new IllegalStateException(e);
		}
	}
615972
@Override
    public Link linkSetProperty(Invocation invocation, String propertyName) throws Exception {
        return new JSUndefinedPropertySetLink( invocation.builder() );
    }
368701
@Override
	public WebMvcLinkBuilder linkTo(Method method, Object... parameters) {
		return WebMvcLinkBuilder.linkTo(method, parameters);
	}
844869
public boolean isLinked(ParaObject obj, ParaObject toObj) {
		if (obj == null || obj.getId() == null || toObj == null || toObj.getId() == null) {
			return false;
		}
		return isLinked(obj, toObj.getType(), toObj.getId());
	}
504924
@Override
	public LinkRelation getItemResourceRelFor(Class<?> type) {

		LookupContext context = LookupContext.forItemResourceRelLookup(type);

		return providers.getRequiredPluginFor(context).getItemResourceRelFor(type);
	}